// File: /workspace/github_c_makefile_star2_O2/wjmelements[P]evm/tst/evm.c
// Function: test_math
void test_math() {
    evmInit();

    address_t from = AddressFromHex42("0x4a6f6B9fF1fc974096f9063a45Fd12bD5B928AD1");
    uint64_t gas = 72856;
    val_t value;
    data_t input;

    // 60026004046007600302015f035f5262ce378160021c595262abcdef601e1a5952595ffd
    op_t program[] = {
        // 0 - (3 * 7 + 4 / 2)
        PUSH1, 0x02,
        PUSH1, 0x04,
        DIV,
        PUSH1, 0x07,
        PUSH1, 0x03,
        MUL,
        ADD,
        PUSH0,
        SUB,
        PUSH0,
        MSTORE,
        // 0xce3781 >> 2
        PUSH3, 0xce, 0x37, 0x81, PUSH1, 0x02, SHR, MSIZE, MSTORE,
        PUSH3, 0xab, 0xcd, 0xef, PUSH1, 0x1e, BYTE, MSIZE, MSTORE,
        MSIZE,
        PUSH0,
        REVERT,
    };

    input.size = sizeof(program);
    input.content = program;

    result_t result = txCreate(from, gas, value, input);
    evmFinalize();

    assert(zero256(&result.status));
    assert(result.returnData.size == 96);
    for (int i = 0; i < 31; i++) {
        assert(result.returnData.content[i] == 0xff);
    }
    assert(result.returnData.content[31] == 0xe9);
    for (int i = 32; i < 61; i++) {
        assert(result.returnData.content[i] == 0x00);
    }
    // 0x338de0
    assert(result.returnData.content[61] == 0x33);
    assert(result.returnData.content[62] == 0x8d);
    assert(result.returnData.content[63] == 0xe0);
    for (int i = 64; i < 95; i++) {
        assert(result.returnData.content[i] == 0x00);
    }
    assert(result.returnData.content[95] == 0xcd);

    assert(result.gasRemaining == G_PER_CODEBYTE * result.returnData.size);
}

// Assembly:
pushq %rbx
subq $0xb0, %rsp
xorl %eax, %eax
callq 0xaa8d
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x332c
movaps 0x10b9e(%rip), %xmm0    # 0x140f0
leaq 0x80(%rsp), %r8
movaps %xmm0, 0x10(%r8)
movaps 0x10b7a(%rip), %xmm0    # 0x140e0
movaps %xmm0, (%r8)
movl $0xfd5f5952, 0x20(%r8)  # imm = 0xFD5F5952
movl 0x10(%rbx), %eax
movl %eax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
pushq $0x24
popq %rcx
movl $0x11c98, %esi          # imm = 0x11C98
callq 0xb68f
xorl %eax, %eax
callq 0xada8
leaq 0x38(%rsp), %rdi
callq 0xdfed
testb %al, %al
je 0x3692
cmpq $0x60, 0x28(%rsp)
jne 0x36ab
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x1f, %rcx
je 0x35ec
cmpb $-0x1, (%rax,%rcx)
leaq 0x1(%rcx), %rcx
je 0x35c3
leaq 0xdc08(%rip), %rdi      # 0x111e2
leaq 0xda6f(%rip), %rsi      # 0x11050
leaq 0xdbcc(%rip), %rcx      # 0x111b4
pushq $0x6c
jmp 0x366a
cmpb $-0x17, 0x1f(%rax)
jne 0x36c4
pushq $-0x1d
popq %rcx
testq %rcx, %rcx
je 0x3622
cmpb $0x0, 0x3d(%rax,%rcx)
leaq 0x1(%rcx), %rcx
je 0x35f9
leaq 0xdc1d(%rip), %rdi      # 0x1122d
leaq 0xda39(%rip), %rsi      # 0x11050
leaq 0xdb96(%rip), %rcx      # 0x111b4
pushq $0x70
jmp 0x366a
cmpb $0x33, 0x3d(%rax)
jne 0x36dd
cmpb $-0x73, 0x3e(%rax)
jne 0x36f9
cmpb $-0x20, 0x3f(%rax)
jne 0x3715
pushq $-0x1f
popq %rcx
testq %rcx, %rcx
je 0x3670
cmpb $0x0, 0x5f(%rax,%rcx)
leaq 0x1(%rcx), %rcx
je 0x3643
leaq 0xdbd3(%rip), %rdi      # 0x1122d
leaq 0xd9ef(%rip), %rsi      # 0x11050
leaq 0xdb4c(%rip), %rcx      # 0x111b4
pushq $0x77
popq %rdx
callq 0x3040
cmpb $-0x33, 0x5f(%rax)
jne 0x3731
cmpq $0x4b00, 0x58(%rsp)     # imm = 0x4B00
jne 0x374d
addq $0xb0, %rsp
popq %rbx
retq
leaq 0xdb03(%rip), %rdi      # 0x1119c
leaq 0xd9b0(%rip), %rsi      # 0x11050
leaq 0xdb0d(%rip), %rcx      # 0x111b4
pushq $0x69
jmp 0x366a
leaq 0xdb13(%rip), %rdi      # 0x111c5
leaq 0xd997(%rip), %rsi      # 0x11050
leaq 0xdaf4(%rip), %rcx      # 0x111b4
pushq $0x6a
jmp 0x366a
leaq 0xdb3c(%rip), %rdi      # 0x11207
leaq 0xd97e(%rip), %rsi      # 0x11050
leaq 0xdadb(%rip), %rcx      # 0x111b4
pushq $0x6e
jmp 0x366a
leaq 0xdb6e(%rip), %rdi      # 0x11252
leaq 0xd965(%rip), %rsi      # 0x11050
leaq 0xdac2(%rip), %rcx      # 0x111b4
pushq $0x73
jmp 0x366a
leaq 0xdb78(%rip), %rdi      # 0x11278
leaq 0xd949(%rip), %rsi      # 0x11050
leaq 0xdaa6(%rip), %rcx      # 0x111b4
pushq $0x74
jmp 0x366a
leaq 0xdb82(%rip), %rdi      # 0x1129e
leaq 0xd92d(%rip), %rsi      # 0x11050
leaq 0xda8a(%rip), %rcx      # 0x111b4
pushq $0x75
jmp 0x366a
leaq 0xdb8c(%rip), %rdi      # 0x112c4
leaq 0xd911(%rip), %rsi      # 0x11050
leaq 0xda6e(%rip), %rcx      # 0x111b4
pushq $0x79
jmp 0x366a
leaq 0xdb96(%rip), %rdi      # 0x112ea
leaq 0xd8f5(%rip), %rsi      # 0x11050
leaq 0xda52(%rip), %rcx      # 0x111b4
pushq $0x7b
jmp 0x366a