// File: /workspace/github_c_makefile_star2_O1/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 0xca7b
leaq 0x10b2b(%rip), %rsi     # 0x184a0
leaq 0x170(%rsp), %rax
movl $0x9, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movb $-0xd, 0x48(%rax)
movq $-0x2, %r14
leaq 0x50(%rsp), %r15
leaq 0xc6b1(%rip), %r12      # 0x14050
movq 0x16652(%rip), %r13     # 0x1dff8
leaq 0xf710(%rip), %rbx      # 0x170bd
movzbl 0x4(%r14,%r12), %ecx
leal -0x30(%rcx), %ebp
cmpb $0xa, %bpl
jb 0x79d4
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x79c8
addb $-0x57, %cl
jmp 0x79d2
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7a12
addb $-0x37, %cl
movl %ecx, %ebp
movzbl 0x5(%r14,%r12), %ecx
leal -0x30(%rcx), %eax
cmpb $0xa, %al
jb 0x79f9
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x79ed
addb $-0x57, %cl
jmp 0x79f7
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x7a27
addb $-0x37, %cl
movl %ecx, %eax
shlb $0x4, %bpl
addb %al, %bpl
movb %bpl, (%r15)
addq $0x2, %r14
incq %r15
cmpq $0x26, %r14
jb 0x79ad
jmp 0x7a3b
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %bpl
jmp 0x79d4
movq (%r13), %rdi
movq %rbx, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x30a0
movb $-0x1, %al
jmp 0x79f9
leaq 0x64(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movl 0x60(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x70(%rsp), %rbx
leaq 0x170(%rsp), %r8
movl $0x105ae, %esi          # imm = 0x105AE
movl $0x49, %ecx
movq %rbx, %rdi
callq 0xd845
cmpq $0x0, 0x10(%rbx)
jne 0x7cba
movl $0x80d9b122, %eax       # imm = 0x80D9B122
cmpq %rax, 0x88(%rsp)
jne 0x7cd9
movabsq $-0x23c5e9023be06931, %rax # imm = 0xDC3A16FDC41F96CF
cmpq %rax, 0x90(%rsp)
jne 0x7cf8
movabsq $0x10ffe7e38d227c3, %rax # imm = 0x10FFE7E38D227C3
cmpq %rax, 0x98(%rsp)
jne 0x7d17
cmpq $0x40, 0x70(%rsp)
jne 0x7d36
movq 0x78(%rsp), %rdi
leaq 0x1097c(%rip), %rsi     # 0x18460
movl $0x40, %edx
callq 0x30d0
testl %eax, %eax
jne 0x7d55
cmpq $0x0, 0xa0(%rsp)
jne 0x7d74
xorps %xmm0, %xmm0
leaq 0xf0(%rsp), %r8
movaps %xmm0, 0x10(%r8)
movaps %xmm0, (%r8)
movw $0xc801, 0x1e(%r8)      # imm = 0xC801
movl 0x88(%rsp), %eax
bswapl %eax
movl %eax, 0x38(%rsp)
movq 0x90(%rsp), %rax
bswapq %rax
movq %rax, 0x3c(%rsp)
movq 0x98(%rsp), %rax
bswapq %rax
movq %rax, 0x44(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x28(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb0(%rsp), %rbx
leaq 0x64(%rsp), %rdx
movl $0x1c94852, %esi        # imm = 0x1C94852
movl $0x20, %ecx
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0xd30c
cmpq $0x0, 0x10(%rbx)
jne 0x7d93
cmpq $0x0, 0xc8(%rsp)
jne 0x7db2
cmpq $0x0, 0xd0(%rsp)
jne 0x7dd1
cmpq $0x1, 0xd8(%rsp)
jne 0x7df0
cmpq $0x1c20b45, 0xe0(%rsp) # imm = 0x1C20B45
jne 0x7e0f
cmpq $0x3900, 0xb0(%rsp) # imm = 0x3900
jne 0x7e2e
leaq 0xf0(%rsp), %rdi
leaq 0x130(%rsp), %r14
movq %r14, %rsi
callq 0x111bd
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
callq 0x11396
movq $0x1, 0x18(%rbx)
movq 0xb8(%rsp), %rbx
movq %r14, %rdi
callq 0x11302
testb %al, %al
jne 0x7c82
leaq 0x110(%rsp), %r14
leaq 0x130(%rsp), %r15
leaq 0x150(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x11e53
movq %rbx, %rdi
movq %r12, %rsi
callq 0x111bd
movq %r15, %rdi
movq %r12, %rsi
callq 0x11bae
testb %al, %al
je 0x7c9b
addq $0x20, %rbx
movq %r15, %rdi
callq 0x11302
testb %al, %al
je 0x7c4a
xorl %eax, %eax
callq 0xcf29
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd4fc(%rip), %rdi      # 0x1519e
leaq 0xc3f3(%rip), %rsi      # 0x1409c
leaq 0xd38a(%rip), %rcx      # 0x1503a
movl $0x4c5, %edx            # imm = 0x4C5
callq 0x3040
leaq 0xcc62(%rip), %rdi      # 0x14923
leaq 0xc3d4(%rip), %rsi      # 0x1409c
leaq 0xd36b(%rip), %rcx      # 0x1503a
movl $0x4a1, %edx            # imm = 0x4A1
callq 0x3040
leaq 0xcc82(%rip), %rdi      # 0x14962
leaq 0xc3b5(%rip), %rsi      # 0x1409c
leaq 0xd34c(%rip), %rcx      # 0x1503a
movl $0x4a2, %edx            # imm = 0x4A2
callq 0x3040
leaq 0xcc93(%rip), %rdi      # 0x14992
leaq 0xc396(%rip), %rsi      # 0x1409c
leaq 0xd32d(%rip), %rcx      # 0x1503a
movl $0x4a3, %edx            # imm = 0x4A3
callq 0x3040
leaq 0xccac(%rip), %rdi      # 0x149ca
leaq 0xc377(%rip), %rsi      # 0x1409c
leaq 0xd30e(%rip), %rcx      # 0x1503a
movl $0x4a4, %edx            # imm = 0x4A4
callq 0x3040
leaq 0xd312(%rip), %rdi      # 0x1504f
leaq 0xc358(%rip), %rsi      # 0x1409c
leaq 0xd2ef(%rip), %rcx      # 0x1503a
movl $0x4a5, %edx            # imm = 0x4A5
callq 0x3040
leaq 0xd320(%rip), %rdi      # 0x1507c
leaq 0xc339(%rip), %rsi      # 0x1409c
leaq 0xd2d0(%rip), %rcx      # 0x1503a
movl $0x4a6, %edx            # imm = 0x4A6
callq 0x3040
leaq 0xccf5(%rip), %rdi      # 0x14a70
leaq 0xc31a(%rip), %rsi      # 0x1409c
leaq 0xd2b1(%rip), %rcx      # 0x1503a
movl $0x4a7, %edx            # imm = 0x4A7
callq 0x3040
leaq 0xd323(%rip), %rdi      # 0x150bd
leaq 0xc2fb(%rip), %rsi      # 0x1409c
leaq 0xd292(%rip), %rcx      # 0x1503a
movl $0x4b4, %edx            # imm = 0x4B4
callq 0x3040
leaq 0xd329(%rip), %rdi      # 0x150e2
leaq 0xc2dc(%rip), %rsi      # 0x1409c
leaq 0xd273(%rip), %rcx      # 0x1503a
movl $0x4b5, %edx            # imm = 0x4B5
callq 0x3040
leaq 0xd32f(%rip), %rdi      # 0x15107
leaq 0xc2bd(%rip), %rsi      # 0x1409c
leaq 0xd254(%rip), %rcx      # 0x1503a
movl $0x4b6, %edx            # imm = 0x4B6
callq 0x3040
leaq 0xd335(%rip), %rdi      # 0x1512c
leaq 0xc29e(%rip), %rsi      # 0x1409c
leaq 0xd235(%rip), %rcx      # 0x1503a
movl $0x4b7, %edx            # imm = 0x4B7
callq 0x3040
leaq 0xd33b(%rip), %rdi      # 0x15151
leaq 0xc27f(%rip), %rsi      # 0x1409c
leaq 0xd216(%rip), %rcx      # 0x1503a
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x3040
leaq 0xd340(%rip), %rdi      # 0x15175
leaq 0xc260(%rip), %rsi      # 0x1409c
leaq 0xd1f7(%rip), %rcx      # 0x1503a
movl $0x4b9, %edx            # imm = 0x4B9
callq 0x3040