// File: /workspace/github_c_makefile_star2_O0/wjmelements[P]evm/src/evm.c
// Function: evmConstruct
static result_t _evmConstruct(address_t from, account_t *to, uint64_t gas, val_t value, data_t input) {
    context_t *callContext = callstack.next;
    callContext->gas = gas;
    if (callstack.next == callstack.bottom) {
        callContext->gas -= G_TXCREATE + G_TX;
        callContext->gas -= calldataGas(&input, true);
        if (gas < callContext->gas) {
            // underflow indicates insufficient initial gas
            fprintf(stderr, "Insufficient intrinsic gas %" PRIu64 " (need %" PRIu64 ")\n", gas, gas - callContext->gas);
            result_t result;
            result.gasRemaining = 0;
            clear256(&result.status);
            result.returnData.size = 0;
            return result;
        }
    }
    callContext->readonly = false;

    BalanceCopy(callContext->callValue, value);
    AddressCopy(callContext->caller, from);
    callContext->account = to;
    callContext->account->warm = evmIteration;
    BalanceAdd(callContext->account->balance, value);
    callContext->code = input;
    callContext->callData.size = 0;

    result_t result = _evmCall(callContext);

    if (!zero256(&result.status)) {
        uint64_t codeGas = result.returnData.size * G_PER_CODEBYTE;
        if (codeGas > callContext->gas) {
            fprintf(stderr, "Insufficient gas to insert code, codeGas %" PRIu64 " > gas %" PRIu64 "\n", codeGas, callContext->gas);
            LOWER(LOWER(result.status)) = 0;
        } else {
            result.gasRemaining -= codeGas;
            AddressToUint256(&result.status, &callContext->account->address);
            callContext->account->code.size = result.returnData.size;
            callContext->account->code.content = malloc(result.returnData.size);
            memcpy(callContext->account->code.content, result.returnData.content, result.returnData.size);
        }
    }
    if (zero256(&result.status)) {
        evmRevert(&result.stateChanges);
    }
    uint64_t gasUsed = gas - result.gasRemaining;
    if (callstack.next == callstack.bottom) {
        // Apply refund
        uint64_t refund = gasUsed / MAX_REFUND_DIVISOR;
        if (refund > refundCounter) {
            refund = refundCounter;
        }
        result.gasRemaining += refund;
        refundCounter = 0;
    }

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x60(%rbp)
movq %rdi, -0x58(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq %r8, -0x10(%rbp)
movq %r9, -0x8(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq 0x20439fd(%rip), %rax   # 0x204ca50
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8080(%rax)
leaq 0x1f9e3(%rip), %rax     # 0x28a50
cmpq %rax, 0x20439dc(%rip)   # 0x204ca50
jne 0x911c
movq -0x30(%rbp), %rax
movq 0x8080(%rax), %rcx
subq $0xcf08, %rcx           # imm = 0xCF08
movq %rcx, 0x8080(%rax)
leaq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x9610
movq %rax, %rdx
movq -0x30(%rbp), %rax
movq 0x8080(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x8080(%rax)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8080(%rcx), %rax
jae 0x911a
movq 0x16f27(%rip), %rax     # 0x1fff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
subq 0x8080(%rax), %rcx
leaq 0x11a09(%rip), %rsi     # 0x1aaf7
movb $0x0, %al
callq 0x31e0
movq -0x60(%rbp), %rdi
movq $0x0, 0x30(%rdi)
addq $0x10, %rdi
callq 0xf8d0
movq -0x60(%rbp), %rax
movq $0x0, (%rax)
jmp 0x9344
jmp 0x911c
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movb $0x0, 0x8088(%rax)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rdx
movq (%rdx), %rsi
movq %rsi, 0x8038(%rax)
movl 0x8(%rdx), %edx
movl %edx, 0x8040(%rax)
movq -0x30(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, 0x8010(%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8018(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x8020(%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8008(%rax)
movq 0x20578f2(%rip), %rcx   # 0x2060a70
movq -0x30(%rbp), %rax
movq 0x8008(%rax), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
movq 0x8008(%rax), %rdi
addq $0x14, %rdi
movq -0x28(%rbp), %rsi
callq 0x9e60
movq -0x60(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x8028(%rax)
movq -0x8(%rbp), %rcx
movq %rcx, 0x8030(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x8070(%rax)
movq -0x30(%rbp), %rsi
callq 0x9ee0
movq -0x60(%rbp), %rdi
addq $0x10, %rdi
callq 0xf7b0
testb $0x1, %al
jne 0x92bd
movq -0x60(%rbp), %rax
imulq $0xc8, (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8080(%rcx), %rax
jbe 0x9245
movq 0x16de1(%rip), %rax     # 0x1fff8
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x8080(%rax), %rcx
leaq 0x11906(%rip), %rsi     # 0x1ab36
movb $0x0, %al
callq 0x31e0
movq -0x60(%rbp), %rax
movq $0x0, 0x28(%rax)
jmp 0x92bb
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq 0x30(%rdi), %rax
subq %rcx, %rax
movq %rax, 0x30(%rdi)
addq $0x10, %rdi
movq -0x30(%rbp), %rax
movq 0x8008(%rax), %rsi
callq 0xa050
movq -0x60(%rbp), %rax
movq (%rax), %rdx
movq -0x30(%rbp), %rcx
movq 0x8008(%rcx), %rcx
movq %rdx, 0x20(%rcx)
movq (%rax), %rdi
callq 0x3210
movq %rax, %rdx
movq -0x60(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x8008(%rcx), %rcx
movq %rdx, 0x28(%rcx)
movq -0x30(%rbp), %rcx
movq 0x8008(%rcx), %rcx
movq 0x28(%rcx), %rdi
movq 0x8(%rax), %rsi
movq (%rax), %rdx
callq 0x3200
jmp 0x92bd
movq -0x60(%rbp), %rdi
addq $0x10, %rdi
callq 0xf7b0
testb $0x1, %al
jne 0x92d0
jmp 0x92dd
movq -0x60(%rbp), %rdi
addq $0x38, %rdi
callq 0xa1a0
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
subq 0x30(%rcx), %rax
movq %rax, -0x40(%rbp)
leaq 0x1f75c(%rip), %rax     # 0x28a50
cmpq %rax, 0x2043755(%rip)   # 0x204ca50
jne 0x9342
movq -0x40(%rbp), %rax
movl $0x5, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq 0x205775e(%rip), %rax   # 0x2060a78
jbe 0x9327
movq 0x2057755(%rip), %rax   # 0x2060a78
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rax
movq -0x48(%rbp), %rcx
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq $0x0, 0x2057736(%rip) # 0x2060a78
jmp 0x9344
movq -0x58(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop