// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %rbx
movq %r8, 0x8(%rsp)
movq %r9, 0x10(%rsp)
leaq 0x17c39(%rip), %rbp     # 0x1ea60
movq 0x2024000(%rbp), %r15
movq %rdx, 0x8080(%r15)
cmpq %rbp, %r15
jne 0x6e72
leaq -0xcf08(%r14), %rbp
movq %rbp, 0x8080(%r15)
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x71de
subq %rax, %rbp
movq %rbp, 0x8080(%r15)
movq %r14, %rcx
subq %rbp, %rcx
leaq 0x17bf4(%rip), %rbp     # 0x1ea60
jb 0x6fcf
leaq 0x50(%rsp), %rax
movb $0x0, 0x8088(%r15)
movq (%r12), %rcx
movq %rcx, 0x8038(%r15)
movl 0x8(%r12), %ecx
movl %ecx, 0x8040(%r15)
movups (%rax), %xmm0
movups %xmm0, 0x8010(%r15)
movl 0x10(%rax), %eax
movl %eax, 0x8020(%r15)
movq %r13, 0x8008(%r15)
movq 0x204fbc7(%rip), %rax   # 0x2056a80
movq %rax, 0x38(%r13)
addq $0x14, %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x765d
movups 0x8(%rsp), %xmm0
movups %xmm0, 0x8028(%r15)
andq $0x0, 0x8070(%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7687
leaq 0x10(%rbx), %r12
movq %r12, %rdi
callq 0x9eb5
testb %al, %al
jne 0x6f4b
imulq $0xc8, (%rbx), %rdx
movq 0x8080(%r15), %rcx
cmpq %rcx, %rdx
ja 0x6fad
subq %rdx, 0x30(%rbx)
movq 0x8008(%r15), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x77a6
movq (%rbx), %r13
movq %r13, 0x20(%r15)
movq %r13, %rdi
callq 0x3200
movq %rax, 0x28(%r15)
movq 0x8(%rbx), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x31f0
movq %r12, %rdi
callq 0x9eb5
testb %al, %al
je 0x6f60
leaq 0x38(%rbx), %rdi
callq 0x77c9
cmpq %rbp, 0x2024000(%rbp)
jne 0x6f9b
movq 0x30(%rbx), %rsi
subq %rsi, %r14
pushq $0x5
popq %rcx
movq %r14, %rax
xorl %edx, %edx
divq %rcx
leaq 0x204fb06(%rip), %rcx   # 0x2056a88
movq 0x204faff(%rip), %rdx   # 0x2056a88
cmpq %rdx, %rax
cmovbq %rax, %rdx
addq %rsi, %rdx
movq %rdx, 0x30(%rbx)
andq $0x0, (%rcx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf044(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x8a68(%rip), %rsi      # 0xfa26
xorl %eax, %eax
callq 0x31d0
andq $0x0, 0x28(%rbx)
jmp 0x6f4b
movq 0xf022(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x8a07(%rip), %rsi      # 0xf9e7
movq %r14, %rdx
xorl %eax, %eax
callq 0x31d0
andq $0x0, 0x30(%rbx)
leaq 0x10(%rbx), %rdi
callq 0x9f49
movq %rbx, %rcx
jmp 0x6f97