// File: /workspace/github_c_makefile_star2_O0/wjmelements[P]evm/src/dio.c
// Function: applyEntry
static void applyEntry(entry_t *entry) {
    if (entry->importPath) {
        loadConfig(entry->importPath, false);
        return;
    }
    if (entry->address == NULL) {
        entry->address = calloc(1, sizeof(address_t));
        entry->address->address[0] = 0xaa;
        entry->address->address[1] = 0xbb;
        static uint32_t anonymousId;
        *(uint32_t *)(&entry->address->address[15]) = anonymousId++;
    }
    if (entry->constructPath) {
        int rw[2];
        if (pipe(rw) == -1) {
            perror("pipe");
            _exit(-1);
        }
        derivePath();
        //fprintf(stderr, "Loading from %s with %s\n", entry->constructPath, derivedPath);
        pid_t pid = fork();
        if (pid == 0) {
            close(1);
            close(rw[0]);
            if (dup2(rw[1], 1) == -1) {
                perror("dup2");
                _exit(-1);
            }
            // child
            char *const args[4] = {
                derivedPath,
                "-c",
                entry->constructPath,
                NULL
            };
            if (execve(derivedPath, args, NULL) == -1) {
                perror(derivedPath);
                _exit(-1);
            }
        }
        close(rw[1]);
        int status;
        pid_t finished = wait(&status);
        if (finished == -1) {
            perror("wait");
            _exit(-1);
        }
        size_t bufferSize = 0x10000;
        data_t input;
        input.size = 0;
        char *content = malloc(bufferSize);
        while (1) {
            ssize_t red = read(rw[0], content + input.size, bufferSize - input.size);
            if (red == -1) {
                perror("read");
                _exit(-1);
            }
            if (red == 0) {
                break;
            }
            input.size += red;
            if (input.size == bufferSize) {
                char *next = malloc(bufferSize * 2);
                memcpy(next, content, input.size);
                free(content);
                content = next;
                bufferSize *= 2;
            }
        }
        for (size_t i = 0; i < input.size / 2; i++) {
            content[i] = hexString16ToUint8(content + i * 2);
        }
        input.content = (uint8_t *)content;
        input.size /= 2;

        address_t from;
        if (entry->creator) {
            AddressCopy(from, (*entry->creator));
        }
        // TODO support these parameters
        uint64_t gas = 0xffffffffffffffff;
        val_t value;
        value[0] = 0;
        value[1] = 0;
        value[2] = 0;

        evmSetDebug(0);
        result_t constructResult = evmConstruct(from, *entry->address, gas, value, input);
        verifyConstructResult(&constructResult, entry);
    } else if (entry->initCode.size) {
        address_t from;
        if (entry->creator) {
            AddressCopy(from, (*entry->creator));
        }
        // TODO support these parameters
        uint64_t gas = 0xffffffffffffffff;
        val_t value;
        value[0] = 0;
        value[1] = 0;
        value[2] = 0;

        result_t constructResult = evmConstruct(from, *entry->address, gas, value, entry->initCode);
        verifyConstructResult(&constructResult, entry);
    } else if (entry->code.size) {
        evmMockCode(*entry->address, entry->code);
    }
    evmMockNonce(*entry->address, entry->nonce);
    evmMockBalance(*entry->address, entry->balance);
    while (entry->storage != NULL) {
        storageEntry_t *prev = entry->storage;
        evmMockStorage(*entry->address, &prev->key, &prev->value);
        entry->storage = prev->prev;
        free(prev);
    }
    runTests(entry, entry->tests);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x61ce
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
xorl %esi, %esi
callq 0x5970
jmp 0x67f3
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x6221
movl $0x1, %edi
movl $0x14, %esi
callq 0x31c0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movb $-0x56, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movb $-0x45, 0x1(%rax)
movl 0x22838(%rip), %ecx     # 0x28a44
movl %ecx, %eax
addl $0x1, %eax
movl %eax, 0x2282d(%rip)     # 0x28a44
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0xf(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x653e
leaq -0x10(%rbp), %rdi
callq 0x3170
cmpl $-0x1, %eax
jne 0x6254
leaq 0x14125(%rip), %rdi     # 0x1a36a
callq 0x3260
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3080
callq 0x7890
callq 0x32b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x6300
movl $0x1, %edi
callq 0x3160
movl -0x10(%rbp), %edi
callq 0x3160
movl -0xc(%rbp), %edi
movl $0x1, %esi
callq 0x30e0
cmpl $-0x1, %eax
jne 0x62a5
leaq 0x140d9(%rip), %rdi     # 0x1a36f
callq 0x3260
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3080
movq 0x2279c(%rip), %rax     # 0x28a48
movq %rax, -0x40(%rbp)
leaq 0x140bd(%rip), %rax     # 0x1a374
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x28(%rbp)
movq 0x22772(%rip), %rdi     # 0x28a48
leaq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x31b0
cmpl $-0x1, %eax
jne 0x62fe
movq 0x22759(%rip), %rdi     # 0x28a48
callq 0x3260
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3080
jmp 0x6300
movl -0xc(%rbp), %edi
callq 0x3160
leaq -0x44(%rbp), %rdi
callq 0x32a0
movl %eax, -0x48(%rbp)
cmpl $-0x1, -0x48(%rbp)
jne 0x6330
leaq 0x14056(%rip), %rdi     # 0x1a377
callq 0x3260
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3080
movq $0x10000, -0x50(%rbp)   # imm = 0x10000
movq $0x0, -0x60(%rbp)
movq -0x50(%rbp), %rdi
callq 0x3210
movq %rax, -0x68(%rbp)
movl -0x10(%rbp), %edi
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movq -0x50(%rbp), %rdx
subq -0x60(%rbp), %rdx
callq 0x3190
movq %rax, -0x70(%rbp)
cmpq $-0x1, -0x70(%rbp)
jne 0x6386
leaq 0x14005(%rip), %rdi     # 0x1a37c
callq 0x3260
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3080
cmpq $0x0, -0x70(%rbp)
jne 0x638f
jmp 0x63e7
movq -0x70(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x63e2
movq -0x50(%rbp), %rdi
shlq %rdi
callq 0x3210
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x3200
movq -0x68(%rbp), %rdi
callq 0x3040
movq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x634d
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x60(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x642d
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %rax
shlq %rax
addq %rax, %rdi
callq 0x5f30
movb %al, %dl
movq -0x68(%rbp), %rax
movq -0x80(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x63ef
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
shrq %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6471
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rcx
movq %rcx, -0x98(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x90(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x88(%rbp)
movq $-0x1, -0xa0(%rbp)
movl $0x0, -0xac(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0xa4(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x8850
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0xa0(%rbp), %rsi
leaq -0xac(%rbp), %rdx
movq (%rax), %rcx
movq %rcx, -0x108(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x100(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0xf8(%rbp)
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %r8
leaq -0xf0(%rbp), %rdi
leaq -0x98(%rbp), %r9
leaq -0x108(%rbp), %rax
movq (%r9), %r10
movq %r10, (%rsp)
movq 0x8(%r9), %r10
movq %r10, 0x8(%rsp)
movl 0x10(%r9), %r9d
movl %r9d, 0x10(%rsp)
movq (%rax), %r9
movq %r9, 0x18(%rsp)
movq 0x8(%rax), %r9
movq %r9, 0x20(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x28(%rsp)
callq 0x8f90
movq -0x8(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x6cc0
jmp 0x66a6
movq -0x8(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x6643
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x657e
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rcx
movq %rcx, -0x120(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x118(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x110(%rbp)
movq $-0x1, -0x128(%rbp)
movl $0x0, -0x134(%rbp)
movl $0x0, -0x130(%rbp)
movl $0x0, -0x12c(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x128(%rbp), %rsi
leaq -0x134(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rcx), %rdi
movq %rdi, -0x190(%rbp)
movq 0x8(%rcx), %rdi
movq %rdi, -0x188(%rbp)
movl 0x10(%rcx), %ecx
movl %ecx, -0x180(%rbp)
movq 0x28(%rax), %rcx
movq 0x30(%rax), %r8
leaq -0x178(%rbp), %rdi
leaq -0x120(%rbp), %r9
leaq -0x190(%rbp), %rax
movq (%r9), %r10
movq %r10, (%rsp)
movq 0x8(%r9), %r10
movq %r10, 0x8(%rsp)
movl 0x10(%r9), %r9d
movl %r9d, 0x10(%rsp)
movq (%rax), %r9
movq %r9, 0x18(%rsp)
movq 0x8(%rax), %r9
movq %r9, 0x20(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x28(%rsp)
callq 0x8f90
movq -0x8(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x6cc0
jmp 0x66a4
movq -0x8(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x66a2
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, -0x1a8(%rbp)
movq 0x8(%rcx), %rdx
movq %rdx, -0x1a0(%rbp)
movl 0x10(%rcx), %ecx
movl %ecx, -0x198(%rbp)
movq 0x38(%rax), %rdi
movq 0x40(%rax), %rsi
leaq -0x1a8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0x8df0
jmp 0x66a4
jmp 0x66a6
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rdi
movq (%rax), %rcx
movq %rcx, -0x1c0(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x1b8(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x1b0(%rbp)
leaq -0x1c0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0x8e40
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
movq (%rax), %rcx
movq %rcx, -0x1d8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x1d0(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x1c8(%rbp)
leaq -0x1d8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0x8d90
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x67e2
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x1e0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x1e0(%rbp), %rdi
movq -0x1e0(%rbp), %rsi
addq $0x20, %rsi
movq (%rax), %rcx
movq %rcx, -0x1f8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x1f0(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x1e8(%rbp)
leaq -0x1f8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0x8e90
movq -0x1e0(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x1e0(%rbp), %rdi
callq 0x3040
jmp 0x6746
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x6f50
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nopl (%rax)