// File: /workspace/github_c_makefile_star2_O1/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 0xca7b
movq $-0x2, %r14
leaq 0x38(%rsp), %r15
leaq 0xc1d8(%rip), %r12      # 0x14050
movq 0x16179(%rip), %r13     # 0x1dff8
leaq 0xf237(%rip), %rbx      # 0x170bd
movzbl 0x4(%r14,%r12), %ecx
leal -0x30(%rcx), %ebp
cmpb $0xa, %bpl
jb 0x7ead
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x7ea1
addb $-0x57, %cl
jmp 0x7eab
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7eeb
addb $-0x37, %cl
movl %ecx, %ebp
movzbl 0x5(%r14,%r12), %ecx
leal -0x30(%rcx), %eax
cmpb $0xa, %al
jb 0x7ed2
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x7ec6
addb $-0x57, %cl
jmp 0x7ed0
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7f00
addb $-0x37, %cl
movl %ecx, %eax
shlb $0x4, %bpl
addb %al, %bpl
movb %bpl, (%r15)
addq $0x2, %r14
incq %r15
cmpq $0x26, %r14
jb 0x7e86
jmp 0x7f14
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %bpl
jmp 0x7ead
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %al
jmp 0x7ed2
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 0xcf2a
leaq 0x105f9(%rip), %rsi     # 0x18540
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 0xd845
cmpq $0x0, 0x10(%r14)
jne 0x82ac
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, 0x88(%rsp)
jne 0x82cb
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, 0x90(%rsp)
jne 0x82ea
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, 0x98(%rsp)
jne 0x8309
cmpq $0x43, 0x70(%rsp)
jne 0x8328
movq 0x78(%rsp), %rdi
leaq 0x104fd(%rip), %rsi     # 0x184f0
movl $0x43, %edx
callq 0x30d0
testl %eax, %eax
jne 0x8347
cmpq $0x0, 0xa0(%rsp)
jne 0x8366
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 0xcf2a
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 0xd30c
cmpq $0x0, 0x10(%r15)
jne 0x8385
cmpq $0x0, 0xc8(%rsp)
jne 0x83a4
cmpq $0x0, 0xd0(%rsp)
jne 0x83c3
cmpq $0x1, 0xd8(%rsp)
jne 0x83e2
cmpq $0x120, 0xb0(%rsp) # imm = 0x120
jne 0x8401
movq 0xb8(%rsp), %rbx
movl $0x40, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x30d0
testl %eax, %eax
jne 0x8420
leaq 0x40(%rbx), %rax
xorl %ecx, %ecx
movl $0x40, %edx
movl %edx, %esi
orq $0x3b, %rsi
xorl %edi, %edi
cmpb $0x0, (%rax,%rdi)
jne 0x81d3
incq %rdi
cmpl $0x3b, %edi
jne 0x8140
cmpb $0x22, (%rbx,%rsi)
jne 0x826e
cmpb $-0x1, 0x1(%rbx,%rsi)
jne 0x824f
cmpb $-0x12, 0x2(%rbx,%rsi)
jne 0x8230
cmpb $-0x12, 0x3(%rbx,%rsi)
jne 0x8211
cmpb $-0x23, 0x4(%rbx,%rsi)
jne 0x81f2
incl %ecx
addl $0x40, %edx
addq $0x40, %rax
cmpl $0x3, %ecx
jne 0x8138
xorl %eax, %eax
cmpb $0x0, 0x100(%rbx,%rax)
jne 0x828d
incq %rax
cmpq $0x20, %rax
jne 0x8194
cmpq $0x0, 0xe0(%rsp)
jne 0x843f
xorl %eax, %eax
callq 0xcf29
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd1a7(%rip), %rdi      # 0x15381
leaq 0xbebb(%rip), %rsi      # 0x1409c
leaq 0xcfd3(%rip), %rcx      # 0x151bb
movl $0x511, %edx            # imm = 0x511
callq 0x3040
leaq 0xd24f(%rip), %rdi      # 0x15448
leaq 0xbe9c(%rip), %rsi      # 0x1409c
leaq 0xcfb4(%rip), %rcx      # 0x151bb
movl $0x517, %edx            # imm = 0x517
callq 0x3040
leaq 0xd1fd(%rip), %rdi      # 0x15415
leaq 0xbe7d(%rip), %rsi      # 0x1409c
leaq 0xcf95(%rip), %rcx      # 0x151bb
movl $0x516, %edx            # imm = 0x516
callq 0x3040
leaq 0xd1de(%rip), %rdi      # 0x15415
leaq 0xbe5e(%rip), %rsi      # 0x1409c
leaq 0xcf76(%rip), %rcx      # 0x151bb
movl $0x515, %edx            # imm = 0x515
callq 0x3040
leaq 0xd18c(%rip), %rdi      # 0x153e2
leaq 0xbe3f(%rip), %rsi      # 0x1409c
leaq 0xcf57(%rip), %rcx      # 0x151bb
movl $0x514, %edx            # imm = 0x514
callq 0x3040
leaq 0xd13a(%rip), %rdi      # 0x153af
leaq 0xbe20(%rip), %rsi      # 0x1409c
leaq 0xcf38(%rip), %rcx      # 0x151bb
movl $0x513, %edx            # imm = 0x513
callq 0x3040
leaq 0xd0ed(%rip), %rdi      # 0x15381
leaq 0xbe01(%rip), %rsi      # 0x1409c
leaq 0xcf19(%rip), %rcx      # 0x151bb
movl $0x51a, %edx            # imm = 0x51A
callq 0x3040
leaq 0xc670(%rip), %rdi      # 0x14923
leaq 0xbde2(%rip), %rsi      # 0x1409c
leaq 0xcefa(%rip), %rcx      # 0x151bb
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x3040
leaq 0xc690(%rip), %rdi      # 0x14962
leaq 0xbdc3(%rip), %rsi      # 0x1409c
leaq 0xcedb(%rip), %rcx      # 0x151bb
movl $0x4f5, %edx            # imm = 0x4F5
callq 0x3040
leaq 0xc6a1(%rip), %rdi      # 0x14992
leaq 0xbda4(%rip), %rsi      # 0x1409c
leaq 0xcebc(%rip), %rcx      # 0x151bb
movl $0x4f6, %edx            # imm = 0x4F6
callq 0x3040
leaq 0xc6ba(%rip), %rdi      # 0x149ca
leaq 0xbd85(%rip), %rsi      # 0x1409c
leaq 0xce9d(%rip), %rcx      # 0x151bb
movl $0x4f7, %edx            # imm = 0x4F7
callq 0x3040
leaq 0xcea6(%rip), %rdi      # 0x151d5
leaq 0xbd66(%rip), %rsi      # 0x1409c
leaq 0xce7e(%rip), %rcx      # 0x151bb
movl $0x4f8, %edx            # imm = 0x4F8
callq 0x3040
leaq 0xceba(%rip), %rdi      # 0x15208
leaq 0xbd47(%rip), %rsi      # 0x1409c
leaq 0xce5f(%rip), %rcx      # 0x151bb
movl $0x4f9, %edx            # imm = 0x4F9
callq 0x3040
leaq 0xc703(%rip), %rdi      # 0x14a70
leaq 0xbd28(%rip), %rsi      # 0x1409c
leaq 0xce40(%rip), %rcx      # 0x151bb
movl $0x4fa, %edx            # imm = 0x4FA
callq 0x3040
leaq 0xcec9(%rip), %rdi      # 0x15255
leaq 0xbd09(%rip), %rsi      # 0x1409c
leaq 0xce21(%rip), %rcx      # 0x151bb
movl $0x508, %edx            # imm = 0x508
callq 0x3040
leaq 0xced7(%rip), %rdi      # 0x15282
leaq 0xbcea(%rip), %rsi      # 0x1409c
leaq 0xce02(%rip), %rcx      # 0x151bb
movl $0x509, %edx            # imm = 0x509
callq 0x3040
leaq 0xcee5(%rip), %rdi      # 0x152af
leaq 0xbccb(%rip), %rsi      # 0x1409c
leaq 0xcde3(%rip), %rcx      # 0x151bb
movl $0x50a, %edx            # imm = 0x50A
callq 0x3040
leaq 0xcef3(%rip), %rdi      # 0x152dc
leaq 0xbcac(%rip), %rsi      # 0x1409c
leaq 0xcdc4(%rip), %rcx      # 0x151bb
movl $0x50b, %edx            # imm = 0x50B
callq 0x3040
leaq 0xcf01(%rip), %rdi      # 0x15309
leaq 0xbc8d(%rip), %rsi      # 0x1409c
leaq 0xcda5(%rip), %rcx      # 0x151bb
movl $0x50c, %edx            # imm = 0x50C
callq 0x3040
leaq 0xcf0c(%rip), %rdi      # 0x15333
leaq 0xbc6e(%rip), %rsi      # 0x1409c
leaq 0xcd86(%rip), %rcx      # 0x151bb
movl $0x50d, %edx            # imm = 0x50D
callq 0x3040
leaq 0xd035(%rip), %rdi      # 0x1547b
leaq 0xbc4f(%rip), %rsi      # 0x1409c
leaq 0xcd67(%rip), %rcx      # 0x151bb
movl $0x51c, %edx            # imm = 0x51C
callq 0x3040