// File: /workspace/github_c_makefile_star2_O3/wjmelements[P]evm/src/evm.c
// Function: evmCall
static result_t evmCall(address_t from, uint64_t gas, address_t to, val_t value, data_t input) {
    account_t *fromAccount = getAccount(from);
    if (!BalanceSub(fromAccount->balance, value)) {
        fprintf(stderr, "Insufficient balance [0x%08x%08x%08x] for call (need [0x%08x%08x%08x])\n",
            fromAccount->balance[0], fromAccount->balance[1], fromAccount->balance[2],
            value[0], value[1], value[2]
        );

        result_t result;
        result.gasRemaining = 0;
        result.stateChanges = NULL;
        clear256(&result.status);
        result.returnData.size = 0;
        return result;
    }

    context_t *callContext = callstack.next;
    callContext->gas = gas;
    if (callstack.next == callstack.bottom) {
        callContext->readonly = false;
    } else {
        callContext->readonly = callContext[-1].readonly;
    }

    BalanceCopy(callContext->callValue, value);
    AddressCopy(callContext->caller, from);
    callContext->account = getAccount(to);
    BalanceAdd(callContext->account->balance, value);
    callContext->code = callContext->account->code;
    callContext->callData = input;

    return _evmCall(callContext);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r12
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r13
leaq 0x70(%rsp), %r15
movl 0x10(%r15), %eax
movl %eax, 0x10(%rsp)
movaps (%r15), %xmm0
movups %xmm0, (%rsp)
callq 0x82de
xorl %edx, %edx
movl $0x3, %ecx
movl 0x10(%rax,%rcx,4), %esi
movl %edx, %edi
addl -0x4(%r14,%rcx,4), %edi
xorl %edx, %edx
movl %esi, %r8d
subl %edi, %r8d
setb %dl
movl %r8d, 0x24(%rsp,%rcx,4)
decq %rcx
jne 0x89ff
cmpl %edi, %esi
jb 0x8b09
movq %r13, 0x20(%rsp)
movq 0x28(%rsp), %rcx
movq %rcx, 0x14(%rax)
movl 0x30(%rsp), %ecx
movl %ecx, 0x1c(%rax)
leaq 0x1801d(%rip), %rax     # 0x20a60
movq 0x2024000(%rax), %r13
movq %rbp, 0x8080(%r13)
xorl %ebp, %ebp
cmpq %rax, %r13
je 0x8a5e
movb -0x8(%r13), %al
jmp 0x8a60
xorl %eax, %eax
movb %al, 0x8088(%r13)
movq (%r14), %rax
movq %rax, 0x8038(%r13)
movl 0x8(%r14), %eax
movl %eax, 0x8040(%r13)
movups (%r15), %xmm0
movups %xmm0, 0x8010(%r13)
movl 0x10(%r15), %eax
movl %eax, 0x8020(%r13)
leaq 0x88(%rsp), %rcx
movl 0x10(%rcx), %eax
movl %eax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x82de
movq %rax, 0x8008(%r13)
xorl %ecx, %ecx
addl 0x1c(%rax,%rcx,4), %ebp
xorl %edx, %edx
addl 0x8(%r14,%rcx,4), %ebp
setb %dl
movl %ebp, 0x1c(%rax,%rcx,4)
decq %rcx
movl %edx, %ebp
cmpq $-0x3, %rcx
jne 0x8ab7
movups 0x20(%rax), %xmm0
movups %xmm0, 0x8028(%r13)
movq %rbx, 0x8070(%r13)
movq %r12, 0x8078(%r13)
movq 0x20(%rsp), %rdi
movq %r13, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8db9
movq 0xf4e8(%rip), %rcx      # 0x17ff8
movq (%rcx), %rdi
movl 0x14(%rax), %edx
movl 0x18(%rax), %ecx
movl 0x1c(%rax), %r8d
movl (%r14), %r9d
movl 0x4(%r14), %eax
movl 0x8(%r14), %esi
movl %esi, 0x8(%rsp)
movl %eax, (%rsp)
leaq 0xa15a(%rip), %rsi      # 0x12c90
xorl %eax, %eax
callq 0x31d0
leaq 0x10(%r13), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%r13)
callq 0xc6ae
movq $0x0, (%r13)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq