//! returns: 0
// Load-reserved, store-conditional and the read-modify-write forms on one hart.
.text;
@entry
    addi %sp %sp -16;
    li %t0 5;
    sd %t0 0(%sp);
// A reservation held on the address lets the store-conditional succeed.
    lr.d.aqrl %t1 (%sp);
    bne %t1 %t0 @fail;
    li %t0 9;
    sc.d.aqrl %t3 %t0 (%sp);
    bnez %t3 @fail;
    ld %t4 0(%sp);
    bne %t4 %t0 @fail;
// The success cleared the reservation, so a second store-conditional fails and stores nothing.
    li %t5 77;
    sc.d.aqrl %t3 %t5 (%sp);
    beqz %t3 @fail;
    ld %t4 0(%sp);
    bne %t4 %t0 @fail;
// A reservation on another address does not cover this one.
    addi %t6 %sp 8;
    lr.d %t1 (%t6);
    sc.d %t3 %t5 (%sp);
    beqz %t3 @fail;
    ld %t4 0(%sp);
    bne %t4 %t0 @fail;
// A read-modify-write returns the old value and stores the result.
    amoadd.d %t1 %t0 (%sp);
    bne %t1 %t0 @fail;
    ld %t4 0(%sp);
    li %t5 18;
    bne %t4 %t5 @fail;
// The word forms sign-extend what they load.
    li %t0 -2;
    sw %t0 8(%sp);
    lr.w %t1 (%t6);
    bne %t1 %t0 @fail;
    li %t0 0;
    j @exit;
@fail
    li %t0 1;
@exit
    mv %a0 %t0;
    li %a7 1024;
    ecall;
