// File: /workspace/github_c_makefile_star2_O3/wjmelements[P]evm/tst/evm.c
// Function: test_revertStorage
void test_revertStorage() {
    evmInit();

    address_t from = AddressFromHex42("0x4a6f6B9fF1fc974096f9063a45Fd12bD5B928AD1");
    uint64_t gas = 67656;
    val_t value;
    value[0] = 0;
    value[1] = 0;
    value[2] = 0xffeeeedd;

    evmMockBalance(from, value);

#define PROGRAM_REVERTSSTORE \
        CALLER, ADDRESS, XOR, PUSH1, 15, JUMPI, \
        PUSH1, 32, CALLDATALOAD, PUSH0, CALLDATALOAD, SSTORE, \
        PUSH0, PUSH0, REVERT, \
        JUMPDEST, \
        CALLDATASIZE, PUSH0, PUSH0, CALLDATACOPY, \
        PUSH0, PUSH0, MSIZE, PUSH0, PUSH0, ADDRESS, GAS, CALL, MSIZE, MSTORE, \
        SELFBALANCE, MSIZE, MSTORE, \
        PUSH0, PUSH0, MSIZE, PUSH0, CALLVALUE, ADDRESS, GAS, CALL, MSIZE, MSTORE, \
        SELFBALANCE, MSIZE, MSTORE, \
        PUSH0, PUSH0, MSIZE, PUSH0, SELFBALANCE, ADDRESS, GAS, CALL, MSIZE, MSTORE, \
        SELFBALANCE, MSIZE, MSTORE, \
        PUSH0, CALLDATALOAD, SLOAD, MSIZE, MSTORE, \
        MSIZE, PUSH0, RETURN
    // 333018600f576020355f35555f5ffd5b365f5f375f5f595f5f305af159524759525f5f595f34305af159524759525f5f595f47305af159524759525f35545952595ff3
    op_t revertTest[] = {
        PROGRAM_REVERTSSTORE
    };
    // 60438060093d393df3333018600f576020355f35555f5ffd5b365f5f375f5f595f5f305af159524759525f5f595f34305af159524759525f5f595f47305af159524759525f35545952595ff3
    op_t createRevertTest[] = {
        PUSH1, 67, DUP1, PUSH1, 0x09, RETURNDATASIZE, CODECOPY, RETURNDATASIZE, RETURN,
        PROGRAM_REVERTSSTORE
    };
#undef PROGRAM_REVERTSSTORE
    data_t input;
    input.content = createRevertTest;
    input.size = sizeof(createRevertTest);
    result_t createResult = txCreate(from, gas, value, input);
    assert(UPPER(UPPER(createResult.status)) == 0);
    assert(LOWER(UPPER(createResult.status)) == 0x80d9b122);
    assert(UPPER(LOWER(createResult.status)) == 0xdc3a16fdc41f96cf);
    assert(LOWER(LOWER(createResult.status)) == 0x010ffe7e38d227c3);
    assert(createResult.returnData.size == sizeof(revertTest));
    assert(memcmp(createResult.returnData.content, revertTest, sizeof(revertTest)) == 0);
    assert(createResult.gasRemaining == 0);

    value[1] = 0x22;
    value[2] = 0;
    evmMockBalance(from, value);

    input.size = 64;
    input.content = calloc(1, 64);
    input.content[63] = 0x01;

    gas = 103640;
    address_t to = AddressFromUint256(&createResult.status);

    result_t sstoreRevertResult = txCall(from, gas, to, value, input, NULL);
    assert(UPPER(UPPER(sstoreRevertResult.status)) == 0);
    assert(LOWER(UPPER(sstoreRevertResult.status)) == 0);
    assert(UPPER(LOWER(sstoreRevertResult.status)) == 0);
    assert(LOWER(LOWER(sstoreRevertResult.status)) == 1);
    assert(sstoreRevertResult.returnData.size == 288);
    assert(memcmp(input.content, sstoreRevertResult.returnData.content, input.size) == 0);
    for (int j = 0; j < 3; j++) {
        int i, k = j * 64;
        for (i = 64 + k; i < 123 + k; i++) {
            assert(sstoreRevertResult.returnData.content[i] == 0);
        }
        assert(sstoreRevertResult.returnData.content[i++] == 0x22);
        assert(sstoreRevertResult.returnData.content[i++] == 0xff);
        assert(sstoreRevertResult.returnData.content[i++] == 0xee);
        assert(sstoreRevertResult.returnData.content[i++] == 0xee);
        assert(sstoreRevertResult.returnData.content[i++] == 0xdd);
    }
    for (int i = 256; i < 288; i++) {
        assert(sstoreRevertResult.returnData.content[i] == 0);
    }
    assert(sstoreRevertResult.gasRemaining == 0);

    evmFinalize();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
xorl %eax, %eax
callq 0xca4d
movq $-0x2, %r14
leaq 0x38(%rsp), %r15
leaq 0xc1d5(%rip), %r12      # 0x14070
movq 0x16156(%rip), %r13     # 0x1dff8
leaq 0xf234(%rip), %rbx      # 0x170dd
movzbl 0x4(%r14,%r12), %ecx
leal -0x30(%rcx), %ebp
cmpb $0xa, %bpl
jb 0x7ed0
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x7ec4
addb $-0x57, %cl
jmp 0x7ece
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7f0e
addb $-0x37, %cl
movl %ecx, %ebp
movzbl 0x5(%r14,%r12), %ecx
leal -0x30(%rcx), %eax
cmpb $0xa, %al
jb 0x7ef5
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x7ee9
addb $-0x57, %cl
jmp 0x7ef3
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7f23
addb $-0x37, %cl
movl %ecx, %eax
shlb $0x4, %bpl
addb %al, %bpl
movb %bpl, (%r15)
addq $0x2, %r14
incq %r15
cmpq $0x26, %r14
jb 0x7ea9
jmp 0x7f37
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %bpl
jmp 0x7ed0
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %al
jmp 0x7ef5
leaq 0x64(%rsp), %rbx
movq $0x0, (%rbx)
movl $0xffeeeedd, 0x8(%rbx)  # imm = 0xFFEEEEDD
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xcd4a
leaq 0x105f6(%rip), %rsi     # 0x18560
leaq 0xf0(%rsp), %r8
movl $0x9, %ecx
movq %r8, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0xf35f5952, 0x48(%r8)  # imm = 0xF35F5952
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x70(%rsp), %r14
movl $0x10848, %esi          # imm = 0x10848
movl $0x4c, %ecx
movq %r14, %rdi
movq %rbx, %rdx
callq 0xd683
cmpq $0x0, 0x10(%r14)
jne 0x82cf
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, 0x88(%rsp)
jne 0x82ee
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, 0x90(%rsp)
jne 0x830d
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, 0x98(%rsp)
jne 0x832c
cmpq $0x43, 0x70(%rsp)
jne 0x834b
movq 0x78(%rsp), %rdi
leaq 0x104fa(%rip), %rsi     # 0x18510
movl $0x43, %edx
callq 0x30d0
testl %eax, %eax
jne 0x836a
cmpq $0x0, 0xa0(%rsp)
jne 0x8389
leaq 0x64(%rsp), %rbx
movq $0x22, 0x4(%rbx)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xcd4a
movl $0x1, %edi
movl $0x40, %esi
callq 0x3090
movq %rax, %r14
movb $0x1, 0x3f(%rax)
movl 0x88(%rsp), %eax
bswapl %eax
movl %eax, 0x50(%rsp)
movq 0x90(%rsp), %rax
bswapq %rax
movq %rax, 0x54(%rsp)
movq 0x98(%rsp), %rax
bswapq %rax
movq %rax, 0x5c(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x28(%rsp)
movups 0x50(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb0(%rsp), %r15
movl $0x194d8, %esi          # imm = 0x194D8
movl $0x40, %ecx
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %r8
xorl %r9d, %r9d
callq 0xd126
cmpq $0x0, 0x10(%r15)
jne 0x83a8
cmpq $0x0, 0xc8(%rsp)
jne 0x83c7
cmpq $0x0, 0xd0(%rsp)
jne 0x83e6
cmpq $0x1, 0xd8(%rsp)
jne 0x8405
cmpq $0x120, 0xb0(%rsp) # imm = 0x120
jne 0x8424
movq 0xb8(%rsp), %rbx
movl $0x40, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x30d0
testl %eax, %eax
jne 0x8443
leaq 0x40(%rbx), %rax
xorl %ecx, %ecx
movl $0x40, %edx
movl %edx, %esi
orq $0x3b, %rsi
xorl %edi, %edi
cmpb $0x0, (%rax,%rdi)
jne 0x81f6
incq %rdi
cmpl $0x3b, %edi
jne 0x8163
cmpb $0x22, (%rbx,%rsi)
jne 0x8291
cmpb $-0x1, 0x1(%rbx,%rsi)
jne 0x8272
cmpb $-0x12, 0x2(%rbx,%rsi)
jne 0x8253
cmpb $-0x12, 0x3(%rbx,%rsi)
jne 0x8234
cmpb $-0x23, 0x4(%rbx,%rsi)
jne 0x8215
incl %ecx
addl $0x40, %edx
addq $0x40, %rax
cmpl $0x3, %ecx
jne 0x815b
xorl %eax, %eax
cmpb $0x0, 0x100(%rbx,%rax)
jne 0x82b0
incq %rax
cmpq $0x20, %rax
jne 0x81b7
cmpq $0x0, 0xe0(%rsp)
jne 0x8462
xorl %eax, %eax
callq 0xcd49
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd1a4(%rip), %rdi      # 0x153a1
leaq 0xbeb8(%rip), %rsi      # 0x140bc
leaq 0xcfd0(%rip), %rcx      # 0x151db
movl $0x511, %edx            # imm = 0x511
callq 0x3040
leaq 0xd24c(%rip), %rdi      # 0x15468
leaq 0xbe99(%rip), %rsi      # 0x140bc
leaq 0xcfb1(%rip), %rcx      # 0x151db
movl $0x517, %edx            # imm = 0x517
callq 0x3040
leaq 0xd1fa(%rip), %rdi      # 0x15435
leaq 0xbe7a(%rip), %rsi      # 0x140bc
leaq 0xcf92(%rip), %rcx      # 0x151db
movl $0x516, %edx            # imm = 0x516
callq 0x3040
leaq 0xd1db(%rip), %rdi      # 0x15435
leaq 0xbe5b(%rip), %rsi      # 0x140bc
leaq 0xcf73(%rip), %rcx      # 0x151db
movl $0x515, %edx            # imm = 0x515
callq 0x3040
leaq 0xd189(%rip), %rdi      # 0x15402
leaq 0xbe3c(%rip), %rsi      # 0x140bc
leaq 0xcf54(%rip), %rcx      # 0x151db
movl $0x514, %edx            # imm = 0x514
callq 0x3040
leaq 0xd137(%rip), %rdi      # 0x153cf
leaq 0xbe1d(%rip), %rsi      # 0x140bc
leaq 0xcf35(%rip), %rcx      # 0x151db
movl $0x513, %edx            # imm = 0x513
callq 0x3040
leaq 0xd0ea(%rip), %rdi      # 0x153a1
leaq 0xbdfe(%rip), %rsi      # 0x140bc
leaq 0xcf16(%rip), %rcx      # 0x151db
movl $0x51a, %edx            # imm = 0x51A
callq 0x3040
leaq 0xc66d(%rip), %rdi      # 0x14943
leaq 0xbddf(%rip), %rsi      # 0x140bc
leaq 0xcef7(%rip), %rcx      # 0x151db
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x3040
leaq 0xc68d(%rip), %rdi      # 0x14982
leaq 0xbdc0(%rip), %rsi      # 0x140bc
leaq 0xced8(%rip), %rcx      # 0x151db
movl $0x4f5, %edx            # imm = 0x4F5
callq 0x3040
leaq 0xc69e(%rip), %rdi      # 0x149b2
leaq 0xbda1(%rip), %rsi      # 0x140bc
leaq 0xceb9(%rip), %rcx      # 0x151db
movl $0x4f6, %edx            # imm = 0x4F6
callq 0x3040
leaq 0xc6b7(%rip), %rdi      # 0x149ea
leaq 0xbd82(%rip), %rsi      # 0x140bc
leaq 0xce9a(%rip), %rcx      # 0x151db
movl $0x4f7, %edx            # imm = 0x4F7
callq 0x3040
leaq 0xcea3(%rip), %rdi      # 0x151f5
leaq 0xbd63(%rip), %rsi      # 0x140bc
leaq 0xce7b(%rip), %rcx      # 0x151db
movl $0x4f8, %edx            # imm = 0x4F8
callq 0x3040
leaq 0xceb7(%rip), %rdi      # 0x15228
leaq 0xbd44(%rip), %rsi      # 0x140bc
leaq 0xce5c(%rip), %rcx      # 0x151db
movl $0x4f9, %edx            # imm = 0x4F9
callq 0x3040
leaq 0xc700(%rip), %rdi      # 0x14a90
leaq 0xbd25(%rip), %rsi      # 0x140bc
leaq 0xce3d(%rip), %rcx      # 0x151db
movl $0x4fa, %edx            # imm = 0x4FA
callq 0x3040
leaq 0xcec6(%rip), %rdi      # 0x15275
leaq 0xbd06(%rip), %rsi      # 0x140bc
leaq 0xce1e(%rip), %rcx      # 0x151db
movl $0x508, %edx            # imm = 0x508
callq 0x3040
leaq 0xced4(%rip), %rdi      # 0x152a2
leaq 0xbce7(%rip), %rsi      # 0x140bc
leaq 0xcdff(%rip), %rcx      # 0x151db
movl $0x509, %edx            # imm = 0x509
callq 0x3040
leaq 0xcee2(%rip), %rdi      # 0x152cf
leaq 0xbcc8(%rip), %rsi      # 0x140bc
leaq 0xcde0(%rip), %rcx      # 0x151db
movl $0x50a, %edx            # imm = 0x50A
callq 0x3040
leaq 0xcef0(%rip), %rdi      # 0x152fc
leaq 0xbca9(%rip), %rsi      # 0x140bc
leaq 0xcdc1(%rip), %rcx      # 0x151db
movl $0x50b, %edx            # imm = 0x50B
callq 0x3040
leaq 0xcefe(%rip), %rdi      # 0x15329
leaq 0xbc8a(%rip), %rsi      # 0x140bc
leaq 0xcda2(%rip), %rcx      # 0x151db
movl $0x50c, %edx            # imm = 0x50C
callq 0x3040
leaq 0xcf09(%rip), %rdi      # 0x15353
leaq 0xbc6b(%rip), %rsi      # 0x140bc
leaq 0xcd83(%rip), %rcx      # 0x151db
movl $0x50d, %edx            # imm = 0x50D
callq 0x3040
leaq 0xd032(%rip), %rdi      # 0x1549b
leaq 0xbc4c(%rip), %rsi      # 0x140bc
leaq 0xcd64(%rip), %rcx      # 0x151db
movl $0x51c, %edx            # imm = 0x51C
callq 0x3040