// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x19306(%rip), %rbp     # 0x21a60
movq 0x2024000(%rbp), %r15
movq %rdx, 0x8080(%r15)
cmpq %rbp, %r15
jne 0x87c1
leaq -0xcf08(%r14), %rdx
movq %rdx, 0x8080(%r15)
leaq (,%r8,4), %rax
leaq 0x1f(%r8), %rdi
shrq $0x5, %rdi
leaq (%rax,%rdi,2), %rax
testq %r8, %r8
je 0x87ab
xorl %edi, %edi
leaq 0xc(%rax), %r10
cmpb $0x0, (%r9,%rdi)
cmovneq %r10, %rax
incq %rdi
cmpq %rdi, %r8
jne 0x8796
subq %rax, %rdx
movq %rdx, 0x8080(%r15)
movq %r14, %rax
subq %rdx, %rax
jb 0x895c
leaq 0x40(%rsp), %rax
movb $0x0, 0x8088(%r15)
movq (%rcx), %rdx
movq %rdx, 0x8038(%r15)
movl 0x8(%rcx), %edx
movl %edx, 0x8040(%r15)
movups (%rax), %xmm0
movups %xmm0, 0x8010(%r15)
movl 0x10(%rax), %eax
movl %eax, 0x8020(%r15)
movq %rsi, 0x8008(%r15)
movq 0x205127b(%rip), %rax   # 0x2059a80
movq %rax, 0x38(%rsi)
xorl %eax, %eax
xorl %edx, %edx
addl 0x1c(%rsi,%rax,4), %edx
xorl %edi, %edi
addl 0x8(%rcx,%rax,4), %edx
setb %dil
movl %edx, 0x1c(%rsi,%rax,4)
decq %rax
movl %edi, %edx
cmpq $-0x3, %rax
jne 0x880d
movq %r8, 0x8028(%r15)
movq %r9, 0x8030(%r15)
movq $0x0, 0x8070(%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8f5f
leaq 0x10(%rbx), %r12
movq %r12, %rdi
callq 0xc986
testb %al, %al
jne 0x88c9
movq (%rbx), %r13
imulq $0xc8, %r13, %rdx
movq 0x8080(%r15), %rcx
cmpq %rcx, %rdx
ja 0x8937
subq %rdx, 0x30(%rbx)
movq 0x8008(%r15), %r15
movq $0x0, 0x10(%rbx)
movl (%r15), %eax
bswapl %eax
movq %rax, 0x18(%rbx)
movq 0x4(%r15), %rax
bswapq %rax
movq %rax, 0x20(%rbx)
movq 0xc(%r15), %rax
bswapq %rax
movq %rax, 0x28(%rbx)
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 0xc986
testb %al, %al
je 0x88de
leaq 0x38(%rbx), %rdi
callq 0x901f
cmpq %rbp, 0x2024000(%rbp)
jne 0x8925
movq 0x30(%rbx), %rcx
subq %rcx, %r14
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %r14, %rax
mulq %rdx
shrq $0x2, %rdx
leaq 0x205117f(%rip), %rax   # 0x2059a88
movq 0x2051178(%rip), %rsi   # 0x2059a88
cmpq %rsi, %rdx
cmovaeq %rsi, %rdx
addq %rcx, %rdx
movq %rdx, 0x30(%rbx)
movq $0x0, (%rax)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x106ba(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xa0de(%rip), %rsi      # 0x12a26
xorl %eax, %eax
callq 0x31d0
movq $0x0, 0x28(%rbx)
jmp 0x88c9
movq 0x10695(%rip), %rcx     # 0x18ff8
movq (%rcx), %rdi
leaq 0xa07a(%rip), %rsi      # 0x129e7
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x31d0
movq $0x0, 0x30(%rbx)
leaq 0x10(%rbx), %rdi
callq 0xca1a
movq %rbx, %rax
jmp 0x891e