// File: /workspace/github_c_makefile_star2_O3/wjmelements[P]evm/tst/evm.c
// Function: test_deepCall
void test_deepCall() {
    evmInit();
    // 3d3580600757005b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01805952590259595f34305af1603c57595ffd5b595ff3
#define PROGRAM_DIVE \
    RETURNDATASIZE, CALLDATALOAD, \
    DUP1, PUSH1, 0x07, JUMPI, STOP, JUMPDEST, \
    PUSH32, \
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
    ADD, \
    DUP1, MSIZE, MSTORE, \
    MSIZE, MUL, MSIZE, MSIZE, PUSH0, CALLVALUE, ADDRESS, GAS, CALL, \
    PUSH1, 60, JUMPI, \
    MSIZE, PUSH0, REVERT, \
    JUMPDEST, \
    MSIZE, PUSH0, RETURN

    op_t dive[] = {
        PROGRAM_DIVE
    };
    // 60408060093d393df33d3580600757005b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01805952590259595f34305af1603c57595ffd5b595ff3
    op_t createDive[] = {
        PUSH1, 0x40, DUP1, PUSH1, 0x09, RETURNDATASIZE, CODECOPY, RETURNDATASIZE, RETURN,
        PROGRAM_DIVE
    };

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

    data_t input;
    input.content = createDive;
    input.size = sizeof(createDive);
    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(dive));
    assert(memcmp(createResult.returnData.content, dive, sizeof(dive)) == 0);
    assert(createResult.gasRemaining == 0);

    uint8_t param[32];
    bzero(param, 32);
    param[30] = 0x01;
    param[31] = 0xc8;
    address_t to = AddressFromUint256(&createResult.status);
    gas = 29968466;

    input.content = param;
    input.size = sizeof(param);
    result_t diveResult = txCall(from, gas, to, value, input, NULL);

    assert(UPPER(UPPER(diveResult.status)) == 0);
    assert(LOWER(UPPER(diveResult.status)) == 0);
    assert(UPPER(LOWER(diveResult.status)) == 0);
    assert(LOWER(LOWER(diveResult.status)) == 1);
    assert(diveResult.gasRemaining == 29494085);
    assert(diveResult.returnData.size == 32 * 0x1c8);

    uint256_t expected;
    readu256BE(param, &expected);
    uint256_t one;
    clear256(&one);
    LOWER(LOWER(one)) = 1;
    uint256_t actual;
    uint8_t *current = diveResult.returnData.content;
    while (!zero256(&expected)) {
        minus256(&expected, &one, &expected);
        readu256BE(current, &actual);
        assert(equal256(&expected, &actual));
        current += 32;
    }

    evmFinalize();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
xorl %eax, %eax
callq 0xca4d
leaq 0x10b0f(%rip), %rsi     # 0x184c0
leaq 0x170(%rsp), %rax
movl $0x9, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movb $-0xd, 0x48(%rax)
movq $-0x2, %r14
leaq 0x38(%rsp), %r15
leaq 0xc695(%rip), %r12      # 0x14070
movq 0x16616(%rip), %r13     # 0x1dff8
leaq 0xf6f4(%rip), %rbx      # 0x170dd
movzbl 0x4(%r14,%r12), %ecx
leal -0x30(%rcx), %ebp
cmpb $0xa, %bpl
jb 0x7a10
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x7a04
addb $-0x57, %cl
jmp 0x7a0e
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7a4e
addb $-0x37, %cl
movl %ecx, %ebp
movzbl 0x5(%r14,%r12), %ecx
leal -0x30(%rcx), %eax
cmpb $0xa, %al
jb 0x7a35
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x7a29
addb $-0x57, %cl
jmp 0x7a33
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7a63
addb $-0x37, %cl
movl %ecx, %eax
shlb $0x4, %bpl
addb %al, %bpl
movb %bpl, (%r15)
addq $0x2, %r14
incq %r15
cmpq $0x26, %r14
jb 0x79e9
jmp 0x7a77
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %bpl
jmp 0x7a10
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %al
jmp 0x7a35
leaq 0x64(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb0(%rsp), %rbx
leaq 0x170(%rsp), %r8
movl $0x105ae, %esi          # imm = 0x105AE
movl $0x49, %ecx
movq %rbx, %rdi
callq 0xd683
cmpq $0x0, 0x10(%rbx)
jne 0x7cdd
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, 0xc8(%rsp)
jne 0x7cfc
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, 0xd0(%rsp)
jne 0x7d1b
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, 0xd8(%rsp)
jne 0x7d3a
cmpq $0x40, 0xb0(%rsp)
jne 0x7d59
movq 0xb8(%rsp), %rdi
leaq 0x10957(%rip), %rsi     # 0x18480
movl $0x40, %edx
callq 0x30d0
testl %eax, %eax
jne 0x7d78
cmpq $0x0, 0xe0(%rsp)
jne 0x7d97
xorps %xmm0, %xmm0
leaq 0xf0(%rsp), %r8
movaps %xmm0, 0x10(%r8)
movaps %xmm0, (%r8)
movw $0xc801, 0x1e(%r8)      # imm = 0xC801
movaps 0xc4c4(%rip), %xmm0     # 0x14030
movaps %xmm0, 0x50(%rsp)
movl $0xc327d238, 0x60(%rsp) # imm = 0xC327D238
movl 0x60(%rsp), %eax
movl %eax, 0x28(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x70(%rsp), %rbx
leaq 0x64(%rsp), %rdx
movl $0x1c94852, %esi        # imm = 0x1C94852
movl $0x20, %ecx
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0xd126
cmpq $0x0, 0x10(%rbx)
jne 0x7db6
cmpq $0x0, 0x88(%rsp)
jne 0x7dd5
cmpq $0x0, 0x90(%rsp)
jne 0x7df4
cmpq $0x1, 0x98(%rsp)
jne 0x7e13
cmpq $0x1c20b45, 0xa0(%rsp) # imm = 0x1C20B45
jne 0x7e32
cmpq $0x3900, 0x70(%rsp)     # imm = 0x3900
jne 0x7e51
leaq 0xf0(%rsp), %rdi
leaq 0x130(%rsp), %r14
movq %r14, %rsi
callq 0x10e35
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
callq 0x1100e
movq $0x1, 0x18(%rbx)
movq 0x78(%rsp), %rbx
movq %r14, %rdi
callq 0x10f7a
testb %al, %al
jne 0x7ca5
leaq 0x110(%rsp), %r14
leaq 0x130(%rsp), %r15
leaq 0x150(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x11a33
movq %rbx, %rdi
movq %r12, %rsi
callq 0x10e35
movq %r15, %rdi
movq %r12, %rsi
callq 0x117c7
testb %al, %al
je 0x7cbe
addq $0x20, %rbx
movq %r15, %rdi
callq 0x10f7a
testb %al, %al
je 0x7c6d
xorl %eax, %eax
callq 0xcd49
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd4f9(%rip), %rdi      # 0x151be
leaq 0xc3f0(%rip), %rsi      # 0x140bc
leaq 0xd387(%rip), %rcx      # 0x1505a
movl $0x4c5, %edx            # imm = 0x4C5
callq 0x3040
leaq 0xcc5f(%rip), %rdi      # 0x14943
leaq 0xc3d1(%rip), %rsi      # 0x140bc
leaq 0xd368(%rip), %rcx      # 0x1505a
movl $0x4a1, %edx            # imm = 0x4A1
callq 0x3040
leaq 0xcc7f(%rip), %rdi      # 0x14982
leaq 0xc3b2(%rip), %rsi      # 0x140bc
leaq 0xd349(%rip), %rcx      # 0x1505a
movl $0x4a2, %edx            # imm = 0x4A2
callq 0x3040
leaq 0xcc90(%rip), %rdi      # 0x149b2
leaq 0xc393(%rip), %rsi      # 0x140bc
leaq 0xd32a(%rip), %rcx      # 0x1505a
movl $0x4a3, %edx            # imm = 0x4A3
callq 0x3040
leaq 0xcca9(%rip), %rdi      # 0x149ea
leaq 0xc374(%rip), %rsi      # 0x140bc
leaq 0xd30b(%rip), %rcx      # 0x1505a
movl $0x4a4, %edx            # imm = 0x4A4
callq 0x3040
leaq 0xd30f(%rip), %rdi      # 0x1506f
leaq 0xc355(%rip), %rsi      # 0x140bc
leaq 0xd2ec(%rip), %rcx      # 0x1505a
movl $0x4a5, %edx            # imm = 0x4A5
callq 0x3040
leaq 0xd31d(%rip), %rdi      # 0x1509c
leaq 0xc336(%rip), %rsi      # 0x140bc
leaq 0xd2cd(%rip), %rcx      # 0x1505a
movl $0x4a6, %edx            # imm = 0x4A6
callq 0x3040
leaq 0xccf2(%rip), %rdi      # 0x14a90
leaq 0xc317(%rip), %rsi      # 0x140bc
leaq 0xd2ae(%rip), %rcx      # 0x1505a
movl $0x4a7, %edx            # imm = 0x4A7
callq 0x3040
leaq 0xd320(%rip), %rdi      # 0x150dd
leaq 0xc2f8(%rip), %rsi      # 0x140bc
leaq 0xd28f(%rip), %rcx      # 0x1505a
movl $0x4b4, %edx            # imm = 0x4B4
callq 0x3040
leaq 0xd326(%rip), %rdi      # 0x15102
leaq 0xc2d9(%rip), %rsi      # 0x140bc
leaq 0xd270(%rip), %rcx      # 0x1505a
movl $0x4b5, %edx            # imm = 0x4B5
callq 0x3040
leaq 0xd32c(%rip), %rdi      # 0x15127
leaq 0xc2ba(%rip), %rsi      # 0x140bc
leaq 0xd251(%rip), %rcx      # 0x1505a
movl $0x4b6, %edx            # imm = 0x4B6
callq 0x3040
leaq 0xd332(%rip), %rdi      # 0x1514c
leaq 0xc29b(%rip), %rsi      # 0x140bc
leaq 0xd232(%rip), %rcx      # 0x1505a
movl $0x4b7, %edx            # imm = 0x4B7
callq 0x3040
leaq 0xd338(%rip), %rdi      # 0x15171
leaq 0xc27c(%rip), %rsi      # 0x140bc
leaq 0xd213(%rip), %rcx      # 0x1505a
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x3040
leaq 0xd33d(%rip), %rdi      # 0x15195
leaq 0xc25d(%rip), %rsi      # 0x140bc
leaq 0xd1f4(%rip), %rcx      # 0x1505a
movl $0x4b9, %edx            # imm = 0x4B9
callq 0x3040