// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
xorl %eax, %eax
callq 0xaa8d
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x332c
leaq 0x4c(%rsp), %r14
andq $0x0, (%r14)
movl $0xffeeeedd, 0x8(%r14)  # imm = 0xFFEEEEDD
movl 0x10(%rbx), %eax
movl %eax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0xada9
leaq 0xf0d0(%rip), %rsi      # 0x15500
pushq $0x4c
popq %rax
leaq 0xf0(%rsp), %r8
movq %rax, %rcx
movq %r8, %rdi
rep  movsb (%rsi), %es:(%rdi)
movl 0x10(%rbx), %ecx
movl %ecx, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
leaq 0x58(%rsp), %rbx
movl $0x10848, %esi          # imm = 0x10848
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
callq 0xb68f
cmpq $0x0, 0x10(%rbx)
jne 0x6765
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, 0x70(%rsp)
jne 0x6784
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, 0x78(%rsp)
jne 0x67a3
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, 0x80(%rsp)
jne 0x67c2
cmpq $0x43, 0x58(%rsp)
jne 0x67e1
movq 0x60(%rsp), %rdi
leaq 0xefe7(%rip), %rsi      # 0x154b0
pushq $0x43
popq %rdx
callq 0x30d0
testl %eax, %eax
jne 0x6800
cmpq $0x0, 0x88(%rsp)
jne 0x681f
leaq 0x68(%rsp), %r15
leaq 0x4c(%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 0xada9
pushq $0x1
popq %rdi
pushq $0x40
popq %r12
movq %r12, %rsi
callq 0x3090
movq %rax, %r14
movb $0x1, 0x3f(%rax)
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x5fbc
movl 0x10(%r13), %eax
movl %eax, 0x28(%rsp)
movups (%r13), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %r15
movl $0x194d8, %esi          # imm = 0x194D8
movq %r15, %rdi
movq %rbx, %rdx
movq %r12, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0xb135
cmpq $0x0, 0x10(%r15)
jne 0x683e
cmpq $0x0, 0xb0(%rsp)
jne 0x685d
cmpq $0x0, 0xb8(%rsp)
jne 0x687c
cmpq $0x1, 0xc0(%rsp)
jne 0x689b
cmpq $0x120, 0x98(%rsp) # imm = 0x120
jne 0x68ba
movq 0xa0(%rsp), %rbx
pushq $0x40
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x30d0
testl %eax, %eax
jne 0x68d9
leaq 0x40(%rbx), %rax
xorl %ecx, %ecx
pushq $0x7b
popq %rdx
pushq $-0x3b
popq %rsi
cmpl $0x3, %ecx
je 0x666e
movq %rsi, %rdi
testq %rdi, %rdi
je 0x6611
cmpb $0x0, 0x3b(%rax,%rdi)
leaq 0x1(%rdi), %rdi
je 0x65fc
jmp 0x66ca
movl %edx, %edi
cmpb $0x22, (%rbx,%rdi)
jne 0x66e9
cmpb $-0x1, 0x1(%rbx,%rdi)
jne 0x6746
cmpb $-0x12, 0x2(%rbx,%rdi)
jne 0x6727
cmpb $-0x12, 0x3(%rbx,%rdi)
jne 0x6708
incl %ecx
addq $0x40, %rdx
addq $0x40, %rax
cmpb $-0x23, 0x4(%rbx,%rdi)
je 0x65f4
leaq 0xbda6(%rip), %rdi      # 0x123fc
leaq 0xa9f3(%rip), %rsi      # 0x11050
leaq 0xbb0b(%rip), %rcx      # 0x1216f
movl $0x517, %edx            # imm = 0x517
callq 0x3040
xorl %eax, %eax
cmpq $0x20, %rax
je 0x66a3
cmpb $0x0, 0x100(%rbx,%rax)
leaq 0x1(%rax), %rax
je 0x6670
leaq 0xbcaa(%rip), %rdi      # 0x12335
leaq 0xa9be(%rip), %rsi      # 0x11050
leaq 0xbad6(%rip), %rcx      # 0x1216f
movl $0x51a, %edx            # imm = 0x51A
callq 0x3040
cmpq $0x0, 0xc8(%rsp)
jne 0x68f8
xorl %eax, %eax
callq 0xada8
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xbc64(%rip), %rdi      # 0x12335
leaq 0xa978(%rip), %rsi      # 0x11050
leaq 0xba90(%rip), %rcx      # 0x1216f
movl $0x511, %edx            # imm = 0x511
callq 0x3040
leaq 0xbc73(%rip), %rdi      # 0x12363
leaq 0xa959(%rip), %rsi      # 0x11050
leaq 0xba71(%rip), %rcx      # 0x1216f
movl $0x513, %edx            # imm = 0x513
callq 0x3040
leaq 0xbcba(%rip), %rdi      # 0x123c9
leaq 0xa93a(%rip), %rsi      # 0x11050
leaq 0xba52(%rip), %rcx      # 0x1216f
movl $0x516, %edx            # imm = 0x516
callq 0x3040
leaq 0xbc9b(%rip), %rdi      # 0x123c9
leaq 0xa91b(%rip), %rsi      # 0x11050
leaq 0xba33(%rip), %rcx      # 0x1216f
movl $0x515, %edx            # imm = 0x515
callq 0x3040
leaq 0xbc49(%rip), %rdi      # 0x12396
leaq 0xa8fc(%rip), %rsi      # 0x11050
leaq 0xba14(%rip), %rcx      # 0x1216f
movl $0x514, %edx            # imm = 0x514
callq 0x3040
leaq 0xb16b(%rip), %rdi      # 0x118d7
leaq 0xa8dd(%rip), %rsi      # 0x11050
leaq 0xb9f5(%rip), %rcx      # 0x1216f
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x3040
leaq 0xb18b(%rip), %rdi      # 0x11916
leaq 0xa8be(%rip), %rsi      # 0x11050
leaq 0xb9d6(%rip), %rcx      # 0x1216f
movl $0x4f5, %edx            # imm = 0x4F5
callq 0x3040
leaq 0xb19c(%rip), %rdi      # 0x11946
leaq 0xa89f(%rip), %rsi      # 0x11050
leaq 0xb9b7(%rip), %rcx      # 0x1216f
movl $0x4f6, %edx            # imm = 0x4F6
callq 0x3040
leaq 0xb1b5(%rip), %rdi      # 0x1197e
leaq 0xa880(%rip), %rsi      # 0x11050
leaq 0xb998(%rip), %rcx      # 0x1216f
movl $0x4f7, %edx            # imm = 0x4F7
callq 0x3040
leaq 0xb9a1(%rip), %rdi      # 0x12189
leaq 0xa861(%rip), %rsi      # 0x11050
leaq 0xb979(%rip), %rcx      # 0x1216f
movl $0x4f8, %edx            # imm = 0x4F8
callq 0x3040
leaq 0xb9b5(%rip), %rdi      # 0x121bc
leaq 0xa842(%rip), %rsi      # 0x11050
leaq 0xb95a(%rip), %rcx      # 0x1216f
movl $0x4f9, %edx            # imm = 0x4F9
callq 0x3040
leaq 0xb1fe(%rip), %rdi      # 0x11a24
leaq 0xa823(%rip), %rsi      # 0x11050
leaq 0xb93b(%rip), %rcx      # 0x1216f
movl $0x4fa, %edx            # imm = 0x4FA
callq 0x3040
leaq 0xb9c4(%rip), %rdi      # 0x12209
leaq 0xa804(%rip), %rsi      # 0x11050
leaq 0xb91c(%rip), %rcx      # 0x1216f
movl $0x508, %edx            # imm = 0x508
callq 0x3040
leaq 0xb9d2(%rip), %rdi      # 0x12236
leaq 0xa7e5(%rip), %rsi      # 0x11050
leaq 0xb8fd(%rip), %rcx      # 0x1216f
movl $0x509, %edx            # imm = 0x509
callq 0x3040
leaq 0xb9e0(%rip), %rdi      # 0x12263
leaq 0xa7c6(%rip), %rsi      # 0x11050
leaq 0xb8de(%rip), %rcx      # 0x1216f
movl $0x50a, %edx            # imm = 0x50A
callq 0x3040
leaq 0xb9ee(%rip), %rdi      # 0x12290
leaq 0xa7a7(%rip), %rsi      # 0x11050
leaq 0xb8bf(%rip), %rcx      # 0x1216f
movl $0x50b, %edx            # imm = 0x50B
callq 0x3040
leaq 0xb9fc(%rip), %rdi      # 0x122bd
leaq 0xa788(%rip), %rsi      # 0x11050
leaq 0xb8a0(%rip), %rcx      # 0x1216f
movl $0x50c, %edx            # imm = 0x50C
callq 0x3040
leaq 0xba07(%rip), %rdi      # 0x122e7
leaq 0xa769(%rip), %rsi      # 0x11050
leaq 0xb881(%rip), %rcx      # 0x1216f
movl $0x50d, %edx            # imm = 0x50D
callq 0x3040
leaq 0xbb30(%rip), %rdi      # 0x1242f
leaq 0xa74a(%rip), %rsi      # 0x11050
leaq 0xb862(%rip), %rcx      # 0x1216f
movl $0x51c, %edx            # imm = 0x51C
callq 0x3040