// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movb $0x0, %al
callq 0xcfc0
leaq -0x18(%rbp), %rdi
leaq 0x13eb7(%rip), %rsi     # 0x1b004
addq $0x2, %rsi
callq 0x3380
movq $0x10848, -0x20(%rbp)   # imm = 0x10848
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0xffeeeedd, -0x24(%rbp) # imm = 0xFFEEEEDD
leaq -0x2c(%rbp), %rdi
leaq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0xd4e0
leaq -0x70(%rbp), %rdi
leaq 0x1830e(%rip), %rsi     # 0x1f4b0
movl $0x43, %edx
callq 0x30c0
leaq -0xc0(%rbp), %rdi
leaq 0x18346(%rip), %rsi     # 0x1f500
movl $0x4c, %edx
callq 0x30c0
leaq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq $0x4c, -0xd0(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movq -0xc8(%rbp), %r8
leaq -0x110(%rbp), %rdi
leaq -0x18(%rbp), %rax
movq (%rax), %r9
movq %r9, (%rsp)
movq 0x8(%rax), %r9
movq %r9, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0xe270
cmpq $0x0, -0x100(%rbp)
jne 0x7226
jmp 0x7245
leaq 0x146aa(%rip), %rdi     # 0x1b8d7
leaq 0x13e1c(%rip), %rsi     # 0x1b050
movl $0x4f4, %edx            # imm = 0x4F4
leaq 0x14f2f(%rip), %rcx     # 0x1c16f
callq 0x3040
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, -0xf8(%rbp)
jne 0x7255
jmp 0x7274
leaq 0x146ba(%rip), %rdi     # 0x1b916
leaq 0x13ded(%rip), %rsi     # 0x1b050
movl $0x4f5, %edx            # imm = 0x4F5
leaq 0x14f00(%rip), %rcx     # 0x1c16f
callq 0x3040
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, -0xf0(%rbp)
jne 0x7289
jmp 0x72a8
leaq 0x146b6(%rip), %rdi     # 0x1b946
leaq 0x13db9(%rip), %rsi     # 0x1b050
movl $0x4f6, %edx            # imm = 0x4F6
leaq 0x14ecc(%rip), %rcx     # 0x1c16f
callq 0x3040
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, -0xe8(%rbp)
jne 0x72bd
jmp 0x72dc
leaq 0x146ba(%rip), %rdi     # 0x1b97e
leaq 0x13d85(%rip), %rsi     # 0x1b050
movl $0x4f7, %edx            # imm = 0x4F7
leaq 0x14e98(%rip), %rcx     # 0x1c16f
callq 0x3040
cmpq $0x43, -0x110(%rbp)
jne 0x72e8
jmp 0x7307
leaq 0x14e9a(%rip), %rdi     # 0x1c189
leaq 0x13d5a(%rip), %rsi     # 0x1b050
movl $0x4f8, %edx            # imm = 0x4F8
leaq 0x14e6d(%rip), %rcx     # 0x1c16f
callq 0x3040
movq -0x108(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x43, %edx
callq 0x3090
cmpl $0x0, %eax
jne 0x7323
jmp 0x7342
leaq 0x14e92(%rip), %rdi     # 0x1c1bc
leaq 0x13d1f(%rip), %rsi     # 0x1b050
movl $0x4f9, %edx            # imm = 0x4F9
leaq 0x14e32(%rip), %rcx     # 0x1c16f
callq 0x3040
cmpq $0x0, -0xe0(%rbp)
jne 0x734e
jmp 0x736d
leaq 0x146cf(%rip), %rdi     # 0x1ba24
leaq 0x13cf4(%rip), %rsi     # 0x1b050
movl $0x4fa, %edx            # imm = 0x4FA
leaq 0x14e07(%rip), %rcx     # 0x1c16f
callq 0x3040
movl $0x22, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x2c(%rbp), %rdi
leaq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0xd4e0
movq $0x40, -0xd0(%rbp)
movl $0x1, %edi
movl $0x40, %esi
callq 0x30a0
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movb $0x1, 0x3f(%rax)
movq $0x194d8, -0x20(%rbp)   # imm = 0x194D8
leaq -0x110(%rbp), %rsi
addq $0x10, %rsi
leaq -0x128(%rbp), %rdi
callq 0x6b50
movq -0x20(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movq -0xc8(%rbp), %r8
leaq -0x168(%rbp), %rdi
leaq -0x18(%rbp), %r10
leaq -0x128(%rbp), %rax
xorl %r9d, %r9d
movq (%r10), %r11
movq %r11, (%rsp)
movq 0x8(%r10), %r11
movq %r11, 0x8(%rsp)
movl 0x10(%r10), %r10d
movl %r10d, 0x10(%rsp)
movq (%rax), %r10
movq %r10, 0x18(%rsp)
movq 0x8(%rax), %r10
movq %r10, 0x20(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x28(%rsp)
callq 0xdaa0
cmpq $0x0, -0x158(%rbp)
jne 0x7457
jmp 0x7476
leaq 0x14dab(%rip), %rdi     # 0x1c209
leaq 0x13beb(%rip), %rsi     # 0x1b050
movl $0x508, %edx            # imm = 0x508
leaq 0x14cfe(%rip), %rcx     # 0x1c16f
callq 0x3040
cmpq $0x0, -0x150(%rbp)
jne 0x7482
jmp 0x74a1
leaq 0x14dad(%rip), %rdi     # 0x1c236
leaq 0x13bc0(%rip), %rsi     # 0x1b050
movl $0x509, %edx            # imm = 0x509
leaq 0x14cd3(%rip), %rcx     # 0x1c16f
callq 0x3040
cmpq $0x0, -0x148(%rbp)
jne 0x74ad
jmp 0x74cc
leaq 0x14daf(%rip), %rdi     # 0x1c263
leaq 0x13b95(%rip), %rsi     # 0x1b050
movl $0x50a, %edx            # imm = 0x50A
leaq 0x14ca8(%rip), %rcx     # 0x1c16f
callq 0x3040
cmpq $0x1, -0x140(%rbp)
jne 0x74d8
jmp 0x74f7
leaq 0x14db1(%rip), %rdi     # 0x1c290
leaq 0x13b6a(%rip), %rsi     # 0x1b050
movl $0x50b, %edx            # imm = 0x50B
leaq 0x14c7d(%rip), %rcx     # 0x1c16f
callq 0x3040
cmpq $0x120, -0x168(%rbp) # imm = 0x120
jne 0x7506
jmp 0x7525
leaq 0x14db0(%rip), %rdi     # 0x1c2bd
leaq 0x13b3c(%rip), %rsi     # 0x1b050
movl $0x50c, %edx            # imm = 0x50C
leaq 0x14c4f(%rip), %rcx     # 0x1c16f
callq 0x3040
movq -0xc8(%rbp), %rdi
movq -0x160(%rbp), %rsi
movq -0xd0(%rbp), %rdx
callq 0x3090
cmpl $0x0, %eax
jne 0x7546
jmp 0x7565
leaq 0x14d9a(%rip), %rdi     # 0x1c2e7
leaq 0x13afc(%rip), %rsi     # 0x1b050
movl $0x50d, %edx            # imm = 0x50D
leaq 0x14c0f(%rip), %rcx     # 0x1c16f
callq 0x3040
movl $0x0, -0x16c(%rbp)
cmpl $0x3, -0x16c(%rbp)
jge 0x776f
movl -0x16c(%rbp), %eax
shll $0x6, %eax
movl %eax, -0x174(%rbp)
movl -0x174(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x170(%rbp)
movl -0x170(%rbp), %eax
movl -0x174(%rbp), %ecx
addl $0x7b, %ecx
cmpl %ecx, %eax
jge 0x75f8
movq -0x160(%rbp), %rax
movslq -0x170(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x75c6
jmp 0x75e5
leaq 0x14d68(%rip), %rdi     # 0x1c335
leaq 0x13a7c(%rip), %rsi     # 0x1b050
movl $0x511, %edx            # imm = 0x511
leaq 0x14b8f(%rip), %rcx     # 0x1c16f
callq 0x3040
jmp 0x75e7
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x759a
movq -0x160(%rbp), %rax
movl -0x170(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x170(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x761e
jmp 0x763d
leaq 0x14d3e(%rip), %rdi     # 0x1c363
leaq 0x13a24(%rip), %rsi     # 0x1b050
movl $0x513, %edx            # imm = 0x513
leaq 0x14b37(%rip), %rcx     # 0x1c16f
callq 0x3040
movq -0x160(%rbp), %rax
movl -0x170(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x170(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xff, %eax
jne 0x7665
jmp 0x7684
leaq 0x14d2a(%rip), %rdi     # 0x1c396
leaq 0x139dd(%rip), %rsi     # 0x1b050
movl $0x514, %edx            # imm = 0x514
leaq 0x14af0(%rip), %rcx     # 0x1c16f
callq 0x3040
movq -0x160(%rbp), %rax
movl -0x170(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x170(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xee, %eax
jne 0x76ac
jmp 0x76cb
leaq 0x14d16(%rip), %rdi     # 0x1c3c9
leaq 0x13996(%rip), %rsi     # 0x1b050
movl $0x515, %edx            # imm = 0x515
leaq 0x14aa9(%rip), %rcx     # 0x1c16f
callq 0x3040
movq -0x160(%rbp), %rax
movl -0x170(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x170(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xee, %eax
jne 0x76f3
jmp 0x7712
leaq 0x14ccf(%rip), %rdi     # 0x1c3c9
leaq 0x1394f(%rip), %rsi     # 0x1b050
movl $0x516, %edx            # imm = 0x516
leaq 0x14a62(%rip), %rcx     # 0x1c16f
callq 0x3040
movq -0x160(%rbp), %rax
movl -0x170(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x170(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xdd, %eax
jne 0x773a
jmp 0x7759
leaq 0x14cbb(%rip), %rdi     # 0x1c3fc
leaq 0x13908(%rip), %rsi     # 0x1b050
movl $0x517, %edx            # imm = 0x517
leaq 0x14a1b(%rip), %rcx     # 0x1c16f
callq 0x3040
jmp 0x775b
movl -0x16c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16c(%rbp)
jmp 0x756f
movl $0x100, -0x178(%rbp)    # imm = 0x100
cmpl $0x120, -0x178(%rbp)    # imm = 0x120
jge 0x77d0
movq -0x160(%rbp), %rax
movslq -0x178(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x779e
jmp 0x77bd
leaq 0x14b90(%rip), %rdi     # 0x1c335
leaq 0x138a4(%rip), %rsi     # 0x1b050
movl $0x51a, %edx            # imm = 0x51A
leaq 0x149b7(%rip), %rcx     # 0x1c16f
callq 0x3040
jmp 0x77bf
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0x7779
cmpq $0x0, -0x138(%rbp)
jne 0x77dc
jmp 0x77fb
leaq 0x14c4c(%rip), %rdi     # 0x1c42f
leaq 0x13866(%rip), %rsi     # 0x1b050
movl $0x51c, %edx            # imm = 0x51C
leaq 0x14979(%rip), %rcx     # 0x1c16f
callq 0x3040
movb $0x0, %al
callq 0xd4d0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
nopl (%rax,%rax)