// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
xorl %eax, %eax
callq 0xaa8d
leaq 0xf467(%rip), %rsi      # 0x15460
pushq $0x49
popq %rbx
leaq 0x180(%rsp), %r14
movq %rbx, %rcx
movq %r14, %rdi
rep  movsb (%rsi), %es:(%rdi)
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x332c
leaq 0x3c(%rsp), %rdx
andq $0x0, (%rdx)
andl $0x0, 0x8(%rdx)
movl 0x10(%r15), %eax
movl %eax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
leaq 0x60(%rsp), %r15
movl $0x105ae, %esi          # imm = 0x105AE
movq %r15, %rdi
movq %rbx, %rcx
movq %r14, %r8
callq 0xb68f
cmpq $0x0, 0x10(%r15)
jne 0x624b
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, 0x78(%rsp)
jne 0x626a
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, 0x80(%rsp)
jne 0x6289
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, 0x88(%rsp)
jne 0x62a8
cmpq $0x40, 0x60(%rsp)
jne 0x62c7
movq 0x68(%rsp), %rdi
leaq 0xf36f(%rip), %rsi      # 0x15420
pushq $0x40
popq %rdx
callq 0x30d0
testl %eax, %eax
jne 0x62e6
cmpq $0x0, 0x90(%rsp)
jne 0x6305
leaq 0x70(%rsp), %rsi
xorps %xmm0, %xmm0
leaq 0xe0(%rsp), %rbx
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movw $0xc801, 0x1e(%rbx)     # imm = 0xC801
leaq 0x108(%rsp), %r14
movq %r14, %rdi
callq 0x5fbc
movl 0x10(%r14), %eax
movl %eax, 0x28(%rsp)
movups (%r14), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x58(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x48(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa0(%rsp), %r14
leaq 0x3c(%rsp), %rdx
pushq $0x20
popq %rcx
movl $0x1c94852, %esi        # imm = 0x1C94852
movq %r14, %rdi
movq %rbx, %r8
xorl %r9d, %r9d
callq 0xb135
cmpq $0x0, 0x10(%r14)
jne 0x6324
cmpq $0x0, 0xb8(%rsp)
jne 0x6343
cmpq $0x0, 0xc0(%rsp)
jne 0x6362
cmpq $0x1, 0xc8(%rsp)
jne 0x6381
cmpq $0x1c20b45, 0xd0(%rsp) # imm = 0x1C20B45
jne 0x63a0
cmpq $0x3900, 0xa0(%rsp) # imm = 0x3900
jne 0x63bf
leaq 0xe0(%rsp), %rdi
leaq 0x160(%rsp), %rbx
movq %rbx, %rsi
callq 0xdedd
leaq 0x140(%rsp), %r14
movq %r14, %rdi
callq 0xe081
movq $0x1, 0x18(%r14)
movq 0xa8(%rsp), %r15
leaq 0x120(%rsp), %r12
movq %rbx, %rdi
callq 0xdfed
testb %al, %al
jne 0x6235
movq %rbx, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe97e
movq %r15, %rdi
movq %r12, %rsi
callq 0xdedd
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe780
addq $0x20, %r15
testb %al, %al
jne 0x61de
leaq 0xbf35(%rip), %rdi      # 0x12152
leaq 0xae2c(%rip), %rsi      # 0x11050
leaq 0xbdc3(%rip), %rcx      # 0x11fee
movl $0x4c5, %edx            # imm = 0x4C5
callq 0x3040
xorl %eax, %eax
callq 0xada8
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0xb685(%rip), %rdi      # 0x118d7
leaq 0xadf7(%rip), %rsi      # 0x11050
leaq 0xbd8e(%rip), %rcx      # 0x11fee
movl $0x4a1, %edx            # imm = 0x4A1
callq 0x3040
leaq 0xb6a5(%rip), %rdi      # 0x11916
leaq 0xadd8(%rip), %rsi      # 0x11050
leaq 0xbd6f(%rip), %rcx      # 0x11fee
movl $0x4a2, %edx            # imm = 0x4A2
callq 0x3040
leaq 0xb6b6(%rip), %rdi      # 0x11946
leaq 0xadb9(%rip), %rsi      # 0x11050
leaq 0xbd50(%rip), %rcx      # 0x11fee
movl $0x4a3, %edx            # imm = 0x4A3
callq 0x3040
leaq 0xb6cf(%rip), %rdi      # 0x1197e
leaq 0xad9a(%rip), %rsi      # 0x11050
leaq 0xbd31(%rip), %rcx      # 0x11fee
movl $0x4a4, %edx            # imm = 0x4A4
callq 0x3040
leaq 0xbd35(%rip), %rdi      # 0x12003
leaq 0xad7b(%rip), %rsi      # 0x11050
leaq 0xbd12(%rip), %rcx      # 0x11fee
movl $0x4a5, %edx            # imm = 0x4A5
callq 0x3040
leaq 0xbd43(%rip), %rdi      # 0x12030
leaq 0xad5c(%rip), %rsi      # 0x11050
leaq 0xbcf3(%rip), %rcx      # 0x11fee
movl $0x4a6, %edx            # imm = 0x4A6
callq 0x3040
leaq 0xb718(%rip), %rdi      # 0x11a24
leaq 0xad3d(%rip), %rsi      # 0x11050
leaq 0xbcd4(%rip), %rcx      # 0x11fee
movl $0x4a7, %edx            # imm = 0x4A7
callq 0x3040
leaq 0xbd46(%rip), %rdi      # 0x12071
leaq 0xad1e(%rip), %rsi      # 0x11050
leaq 0xbcb5(%rip), %rcx      # 0x11fee
movl $0x4b4, %edx            # imm = 0x4B4
callq 0x3040
leaq 0xbd4c(%rip), %rdi      # 0x12096
leaq 0xacff(%rip), %rsi      # 0x11050
leaq 0xbc96(%rip), %rcx      # 0x11fee
movl $0x4b5, %edx            # imm = 0x4B5
callq 0x3040
leaq 0xbd52(%rip), %rdi      # 0x120bb
leaq 0xace0(%rip), %rsi      # 0x11050
leaq 0xbc77(%rip), %rcx      # 0x11fee
movl $0x4b6, %edx            # imm = 0x4B6
callq 0x3040
leaq 0xbd58(%rip), %rdi      # 0x120e0
leaq 0xacc1(%rip), %rsi      # 0x11050
leaq 0xbc58(%rip), %rcx      # 0x11fee
movl $0x4b7, %edx            # imm = 0x4B7
callq 0x3040
leaq 0xbd5e(%rip), %rdi      # 0x12105
leaq 0xaca2(%rip), %rsi      # 0x11050
leaq 0xbc39(%rip), %rcx      # 0x11fee
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x3040
leaq 0xbd63(%rip), %rdi      # 0x12129
leaq 0xac83(%rip), %rsi      # 0x11050
leaq 0xbc1a(%rip), %rcx      # 0x11fee
movl $0x4b9, %edx            # imm = 0x4B9
callq 0x3040