// File: /workspace/github_c_makefile_star2_O2/wjmelements[P]evm/src/dio.c
// Function: runTests
static uint64_t runTests(const entry_t *entry, testEntry_t *test) {
    if (test == NULL) {
        return 0;
    }
    uint64_t testsRun = runTests(entry, test->prev);
    if (!testsRun) {
        fputs("# ", stderr);
        if (entry->constructPath) {
            fputs(entry->constructPath, stderr);
        } else {
            fprintAddress(stderr, (*entry->address));
        }
        fputc('\n', stderr);
    }

    evmSetDebug(test->debug);
    if (test->blockNumber) {
        evmSetBlockNumber(*test->blockNumber);
        free(test->blockNumber);
    }
    if (test->timestamp) {
        evmSetTimestamp(*test->timestamp);
        free(test->timestamp);
    }
    uint64_t gas = 0xffffffffffffffff;
    if (test->gas) {
        gas = test->gas;
    }
    // TODO support evmStaticCall
    result_t result = txCall(test->from, gas, test->to ? *test->to : *entry->address, test->value, test->input, test->accessList);
    uint64_t gasUsed = gas - result.gasRemaining;
    test->result.gasUsed = gasUsed;

    if (test->name) {
        fputs(test->name, stderr);
    } else {
        fprintf(stderr, "%" PRIu64, testsRun);
    }
    fputs(": ", stderr);
    int testFailure = 0;
    if (!equal256(&result.status, &test->status) || test->op == CREATE) {
        if (zero256(&result.status)) {
            if (result.returnData.size) {
                fputs("\033[0;31mreverted: ", stderr);
                fprintData(stderr, result.returnData);
                fputs("\033[0m\n", stderr);
            } else {
                fputs("\033[0;31mreverted\033[0m\n", stderr);
            }
        } else {
            fputs("\033[0;31mshould revert\033[0m\n", stderr);
        }
        testFailure = anyTestFailure = 1;
    } else {
        const logsEntry_t *expectedLogs = test->logs;
        while (expectedLogs) {
            // find corresponding acccount
            const stateChanges_t *actualLogs = result.stateChanges;
            while (actualLogs) {
                if (AddressEqual(&actualLogs->account, &expectedLogs->address)) {
                    break;
                }
                actualLogs = actualLogs->next;
            }
            if (actualLogs) {
                // compare all logs
                const logChanges_t *expectedLog = expectedLogs->logs;
                const logChanges_t *actualLog = actualLogs->logChanges;
                if (!LogsEqual(expectedLog, actualLog)) {
                    // mismatch
                    fputs("logs expected:\n", stderr);
                    fprintLog(stderr, expectedLog, false);
                    fputc('\n', stderr);
                    fputs("logs actual:\n", stderr);
                    fprintLogDiff(stderr, actualLog, expectedLog, false);
                    fputc('\n', stderr);
                    testFailure = anyTestFailure = 1;
                }
            } else {
                // Missing!
                fputs("expected logs missing:\n", stderr);
                fprintLog(stderr, expectedLogs->logs, false);
                fputc('\n', stderr);
                testFailure = anyTestFailure = 1;
            }
            expectedLogs = expectedLogs->prev;
        }
    }

    if (test->outputSpecified && (result.returnData.size != test->output.size || memcmp(result.returnData.content, test->output.content, test->output.size))) {
        fputs("Output data mismatch\nactual:\n", stderr);

        fprintData(stderr, result.returnData);
        fputs("\nexpected:\n", stderr);
        fprintData(stderr, test->output);
        fputc('\n', stderr);
        testFailure = anyTestFailure = 1;
    } else if (test->gasUsed) {
        if (test->gasUsed < gasUsed) {
            // more actual gasUsed than expected
            fprintf(stderr, "gasUsed \033[0;31m%" PRIu64 "\033[0m expected %" PRIu64 " (\033[0;31m+%" PRIu64 "\033[0m)\n", gasUsed, test->gasUsed, gasUsed - test->gasUsed);
        } else if (test->gasUsed > gas - result.gasRemaining) {
            // less actual gasUsed than expected
            fprintf(stderr, "gasUsed \033[0;32m%" PRIu64 "\033[0m expected %" PRIu64 " (\033[0;32m-%" PRIu64 "\033[0m)\n", gasUsed, test->gasUsed, test->gasUsed - gasUsed);
        } else if (testFailure) {
            fprintf(stderr, "\033[0;31mfail\033[0m\n");
        } else {
            fprintf(stderr, "\033[0;32mpass\033[0m\n");
        }
    } else if (testFailure) {
        fprintf(stderr, "\033[0;31mfail\033[0m\n");
    } else {
        fprintf(stderr, "\033[0;32mpass\033[0m\n");
    }

    return ++testsRun;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
testq %rsi, %rsi
jne 0x5c81
xorl %r14d, %r14d
movq %r14, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r13
movq %rdi, %r12
movq 0xd8(%rsi), %rsi
callq 0x5c53
movq %rax, %r14
testq %rax, %rax
jne 0x5dd3
movq 0x10352(%rip), %rbx     # 0x15ff8
movq (%rbx), %rsi
leaq 0x96ee(%rip), %rdi      # 0xf39e
callq 0x3130
movq 0x58(%r12), %rdi
movq (%rbx), %rax
testq %rdi, %rdi
jne 0x5dc0
movq (%r12), %rsi
movzbl (%rsi), %edx
movzbl 0x1(%rsi), %ecx
movzbl 0x2(%rsi), %r8d
movzbl 0x3(%rsi), %r9d
movzbl 0x4(%rsi), %edi
movq %rdi, 0x30(%rsp)
movzbl 0x5(%rsi), %edi
movq %rdi, 0x10(%rsp)
movzbl 0x6(%rsi), %edi
movq %rdi, 0x8(%rsp)
movzbl 0x7(%rsi), %edi
movq %rdi, 0x28(%rsp)
movzbl 0x8(%rsi), %edi
movq %rdi, 0x18(%rsp)
movzbl 0x9(%rsi), %edi
movq %rdi, 0x58(%rsp)
movzbl 0xa(%rsi), %edi
movq %rdi, 0x50(%rsp)
movzbl 0xb(%rsi), %edi
movq %rdi, 0x48(%rsp)
movzbl 0xc(%rsi), %edi
movq %rdi, 0x40(%rsp)
movzbl 0xd(%rsi), %edi
movq %rdi, 0x38(%rsp)
movq %r14, 0x20(%rsp)
movzbl 0xe(%rsi), %r15d
movzbl 0xf(%rsi), %ebp
movzbl 0x10(%rsi), %r10d
movzbl 0x11(%rsi), %r11d
movzbl 0x12(%rsi), %r14d
movzbl 0x13(%rsi), %ebx
leaq 0x95d3(%rip), %rsi      # 0xf330
movq %rax, %rdi
xorl %eax, %eax
pushq %rbx
movq 0x1028e(%rip), %rbx     # 0x15ff8
pushq %r14
pushq %r11
pushq %r10
pushq %rbp
pushq %r15
movq 0x50(%rsp), %r14
pushq 0x68(%rsp)
pushq 0x78(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
pushq 0xa8(%rsp)
pushq 0x70(%rsp)
pushq 0x88(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
pushq 0xa8(%rsp)
callq 0x31d0
addq $0x80, %rsp
jmp 0x5dc8
movq %rax, %rsi
callq 0x3130
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x3180
movq 0xb0(%r13), %rdi
callq 0x694d
movq 0xa0(%r13), %rax
testq %rax, %rax
je 0x5dff
movq (%rax), %rdi
callq 0x693d
movq 0xa0(%r13), %rdi
callq 0x3040
movq 0xa8(%r13), %rax
testq %rax, %rax
je 0x5e1f
movq (%rax), %rdi
callq 0x6945
movq 0xa8(%r13), %rdi
callq 0x3040
movq 0x60(%r13), %rax
xorl %ecx, %ecx
cmpq $0x1, %rax
sbbq %rcx, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
leaq 0x9(%r13), %rax
movq 0x20(%r13), %rcx
testq %rcx, %rcx
jne 0x5e45
movq (%r12), %rcx
movl 0x10(%rcx), %edx
movl %edx, 0x90(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x80(%rsp)
leaq 0x28(%r13), %rdx
movq 0x68(%r13), %r9
movl 0x10(%rax), %ecx
movl %ecx, 0x70(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x38(%r13), %rcx
movq 0x40(%r13), %r8
subq $0x30, %rsp
movl 0xc0(%rsp), %eax
movl %eax, 0x28(%rsp)
movaps 0xb0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0x10(%rsp)
movaps 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq 0x38(%rsp), %r15
movq %r15, %rsi
callq 0x6ffd
addq $0x30, %rsp
subq 0x30(%rbx), %r15
movq %r15, 0x28(%rsp)
movq %r15, 0xc0(%r13)
movq (%r13), %rdi
movq 0x10115(%rip), %rax     # 0x15ff8
movq (%rax), %rax
testq %rdi, %rdi
jne 0x5f01
leaq 0x9b7e(%rip), %rsi      # 0xfa70
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x31d0
jmp 0x5f09
movq %rax, %rsi
callq 0x3130
movq 0x100e8(%rip), %rax     # 0x15ff8
movq (%rax), %rsi
leaq 0x9496(%rip), %rdi      # 0xf3b0
callq 0x3130
leaq 0xa8(%rsp), %rbx
leaq 0x70(%r13), %rsi
movq %rbx, %rdi
callq 0xa648
testb %al, %al
je 0x5f3e
cmpb $-0x10, 0x8(%r13)
jne 0x5f85
movq %rbx, %rdi
callq 0x9eb5
testb %al, %al
je 0x5f6f
cmpq $0x0, 0x98(%rsp)
movq 0x1009e(%rip), %rbx     # 0x15ff8
movq (%rbx), %rsi
jne 0x610e
leaq 0x9449(%rip), %rdi      # 0xf3b3
jmp 0x613c
movq 0x10082(%rip), %rax     # 0x15ff8
movq (%rax), %rsi
leaq 0x9448(%rip), %rdi      # 0xf3c8
jmp 0x613c
movq %r14, 0x20(%rsp)
movq %r13, 0x18(%rsp)
addq $0x98, %r13
movq $0x0, 0x10(%rsp)
pushq $0xa
popq %r14
movq (%r13), %r13
testq %r13, %r13
je 0x60fa
leaq 0xd0(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x60d4
xorl %ecx, %ecx
cmpq $0x14, %rcx
je 0x5fe3
movb (%rax,%rcx), %dl
leaq 0x1(%rcx), %rsi
cmpb (%r13,%rcx), %dl
movq %rsi, %rcx
je 0x5fc6
addq $0x28, %rax
jmp 0x5fb8
movq 0x18(%r13), %rbp
movq 0x18(%rax), %rbx
movq %rbp, %r15
movq %rbx, 0x30(%rsp)
testq %r15, %r15
je 0x6059
testq %rbx, %rbx
je 0x6059
movq 0x10(%r15), %rdx
cmpq 0x10(%rbx), %rdx
jne 0x605e
movq 0x18(%r15), %rdi
movq 0x18(%rbx), %rsi
callq 0x3210
testl %eax, %eax
jne 0x605e
movb 0x8(%r15), %al
cmpb 0x8(%rbx), %al
jne 0x605e
pushq $-0x1
popq %r12
xorl %esi, %esi
movzbl 0x8(%r15), %eax
incq %r12
cmpq %rax, %r12
jae 0x604f
leaq 0x20(%rsi), %r14
movq (%r15), %rdi
addq %rsi, %rdi
addq (%rbx), %rsi
callq 0xa648
movq %r14, %rsi
testb %al, %al
jne 0x6027
jmp 0x605e
movq 0x20(%r15), %r15
movq 0x20(%rbx), %rbx
jmp 0x5ff3
orq %rbx, %r15
je 0x60cb
movq 0xff93(%rip), %rbx      # 0x15ff8
movq (%rbx), %rsi
leaq 0x9373(%rip), %rdi      # 0xf3e2
callq 0x3130
movq (%rbx), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x6310
movq (%rbx), %rsi
pushq $0xa
popq %r14
movl %r14d, %edi
callq 0x3180
movq (%rbx), %rsi
leaq 0x9358(%rip), %rdi      # 0xf3f2
callq 0x3130
movq (%rbx), %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x6429
movq (%rbx), %rsi
movl %r14d, %edi
callq 0x3180
movb $0x1, 0x1898d(%rip)     # 0x1ea50
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
addq $0x20, %r13
jmp 0x5f9f
movq 0xff1d(%rip), %rbx      # 0x15ff8
movq (%rbx), %rsi
leaq 0x931b(%rip), %rdi      # 0xf400
callq 0x3130
movq (%rbx), %rdi
movq 0x18(%r13), %rsi
xorl %edx, %edx
callq 0x6310
jmp 0x60b1
cmpl $0x0, 0x10(%rsp)
sete %bl
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
jmp 0x614a
leaq 0x928c(%rip), %rdi      # 0xf3a1
callq 0x3130
movq (%rbx), %rdi
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x6286
movq (%rbx), %rsi
leaq 0x9286(%rip), %rdi      # 0xf3c2
callq 0x3130
movb $0x1, 0x18908(%rip)     # 0x1ea50
xorl %ebx, %ebx
cmpb $0x1, 0x58(%r13)
jne 0x6174
movq 0x98(%rsp), %rdx
cmpq 0x48(%r13), %rdx
jne 0x619e
movq 0xa0(%rsp), %rdi
movq 0x50(%r13), %rsi
callq 0x3210
testl %eax, %eax
jne 0x619e
movq 0x90(%r13), %rcx
testq %rcx, %rcx
jne 0x61ff
movq 0xfe71(%rip), %rax      # 0x15ff8
movq (%rax), %rcx
testb %bl, %bl
je 0x6225
leaq 0x931c(%rip), %rdi      # 0xf4b5
jmp 0x622c
movq 0xfe53(%rip), %rbx      # 0x15ff8
movq (%rbx), %rsi
leaq 0x9269(%rip), %rdi      # 0xf418
callq 0x3130
movq (%rbx), %rdi
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x6286
movq (%rbx), %rsi
leaq 0x91bc(%rip), %rdi      # 0xf392
callq 0x3130
movq (%rbx), %rdi
movq 0x48(%r13), %rsi
movq 0x50(%r13), %rdx
callq 0x6286
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x3180
movb $0x1, 0x18853(%rip)     # 0x1ea50
jmp 0x625f
movq %rcx, %r8
movq 0x28(%rsp), %rdx
subq %rdx, %r8
movq 0xfde7(%rip), %rax      # 0x15ff8
jae 0x6239
movq (%rax), %rdi
movq %rdx, %r8
subq %rcx, %r8
leaq 0x9213(%rip), %rsi      # 0xf436
jmp 0x6258
leaq 0x9278(%rip), %rdi      # 0xf4a4
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x3290
jmp 0x625f
movq 0x8(%rsp), %rsi
subq 0xc8(%rsp), %rsi
movq (%rax), %rax
cmpq %rsi, %rcx
jbe 0x6267
leaq 0x9218(%rip), %rsi      # 0xf46d
movq %rax, %rdi
xorl %eax, %eax
callq 0x31d0
incq %r14
jmp 0x5c6c
testb %bl, %bl
je 0x6274
leaq 0x9243(%rip), %rdi      # 0xf4b5
jmp 0x627b
leaq 0x9229(%rip), %rdi      # 0xf4a4
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
jmp 0x6232