// File: /workspace/github_c_makefile_star2_O1/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:
testq %rsi, %rsi
jne 0x7555
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %r12
movq 0xd8(%rsi), %rsi
callq 0x754d
movq %rax, %rbx
testq %rax, %rax
jne 0x7588
movq %r12, %rdi
callq 0x37af
movq 0xb0(%r14), %rdi
callq 0x80f7
movq 0xa0(%r14), %rax
testq %rax, %rax
je 0x75b4
movq (%rax), %rdi
callq 0x80e7
movq 0xa0(%r14), %rdi
callq 0x3040
movq 0xa8(%r14), %rax
testq %rax, %rax
je 0x75d4
movq (%rax), %rdi
callq 0x80ef
movq 0xa8(%r14), %rdi
callq 0x3040
movq 0x60(%r14), %rax
xorl %r15d, %r15d
cmpq $0x1, %rax
sbbq %r15, %r15
orq %rax, %r15
leaq 0x9(%r14), %rax
movq 0x20(%r14), %rcx
testq %rcx, %rcx
jne 0x75f6
movq (%r12), %rcx
movl 0x10(%rcx), %edx
movl %edx, 0xa0(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x90(%rsp)
leaq 0x28(%r14), %rdx
movq 0x68(%r14), %r9
movl 0x10(%rax), %ecx
movl %ecx, 0x80(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x70(%rsp)
movq 0x38(%r14), %rcx
movq 0x40(%r14), %r8
movl 0xa0(%rsp), %eax
movl %eax, 0x28(%rsp)
movaps 0x90(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x10(%rsp)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x8990
movq %r15, %r13
subq 0x30(%r12), %r13
movq %r13, 0xc0(%r14)
movq (%r14), %rdi
movq 0x11973(%rip), %rax     # 0x18ff8
movq (%rax), %rax
testq %rdi, %rdi
jne 0x76a3
leaq 0xb3dc(%rip), %rsi      # 0x12a70
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x31d0
jmp 0x76ab
movq %rax, %rsi
callq 0x3130
movq 0x11946(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
leaq 0xacf4(%rip), %rdi      # 0x123b0
callq 0x3130
leaq 0xb8(%rsp), %r12
leaq 0x70(%r14), %rsi
movq %r12, %rdi
callq 0xd232
testb %al, %al
movq %rbx, 0x38(%rsp)
movq %r14, 0x68(%rsp)
movq %r15, 0x60(%rsp)
movq %r13, 0x58(%rsp)
je 0x76f4
cmpb $-0x10, 0x8(%r14)
jne 0x7737
movq %r12, %rdi
callq 0xc986
testb %al, %al
je 0x772d
cmpq $0x0, 0xa8(%rsp)
movq 0x118e8(%rip), %rax     # 0x18ff8
movq (%rax), %rax
jne 0x78bf
leaq 0xac93(%rip), %rdi      # 0x123b3
movq %rax, %rsi
callq 0x3130
jmp 0x78cf
callq 0x3973
jmp 0x78cf
movq 0x98(%r14), %r13
movb $0x1, %bl
testq %r13, %r13
je 0x78d8
movq $0x0, 0x50(%rsp)
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x7791
movb (%r13), %cl
cmpb %cl, (%rax)
jne 0x7788
xorl %esi, %esi
movq %rsi, %rdx
cmpq $0x13, %rsi
je 0x7782
movb 0x1(%rax,%rdx), %dil
leaq 0x1(%rdx), %rsi
cmpb 0x1(%r13,%rdx), %dil
je 0x7769
cmpq $0x12, %rdx
ja 0x779e
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x7763
movq %r13, %rdi
callq 0x3940
jmp 0x7883
movq 0x18(%r13), %rcx
movq 0x18(%rax), %r12
movq %rcx, %rbp
movq %r12, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
testq %rcx, %rcx
je 0x786f
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rax
movq %rax, %r12
testq %rax, %rax
je 0x786f
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %rbp
movq 0x10(%r12), %rdx
cmpq %rdx, 0x10(%rbp)
jne 0x7874
movq 0x18(%rbp), %rdi
movq 0x18(%r12), %rsi
callq 0x3210
testl %eax, %eax
jne 0x7874
movb 0x8(%rbp), %al
cmpb 0x8(%r12), %al
jne 0x7874
testb %al, %al
setne %r14b
je 0x7858
movq (%rbp), %rdi
movq (%r12), %rsi
callq 0xd232
testb %al, %al
je 0x7853
movl $0x20, %esi
xorl %r15d, %r15d
incq %r15
movzbl 0x8(%rbp), %eax
cmpq %rax, %r15
setb %r14b
jae 0x7858
leaq 0x20(%rsi), %rbx
movq (%rbp), %rdi
addq %rsi, %rdi
addq (%r12), %rsi
callq 0xd232
movq %rbx, %rsi
testb %al, %al
jne 0x7828
testb %r14b, %r14b
jne 0x7874
movq 0x20(%rbp), %rbp
movq 0x20(%r12), %r12
testq %rbp, %rbp
je 0x786f
testq %r12, %r12
jne 0x77dc
orq %r12, %rbp
je 0x78a8
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x38e2
movq 0x1176e(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x3180
movb $0x1, 0x1a1b2(%rip)     # 0x21a50
movl $0x1, %eax
movq %rax, 0x50(%rsp)
movq 0x20(%r13), %r13
testq %r13, %r13
jne 0x7752
cmpl $0x0, 0x50(%rsp)
sete %bl
jmp 0x78d8
leaq 0xa8(%rsp), %rsi
movq %rax, %rdi
callq 0x398f
movb $0x1, 0x1a17a(%rip)     # 0x21a50
xorl %ebx, %ebx
movq 0x68(%rsp), %r14
cmpb $0x1, 0x58(%r14)
movq 0x60(%rsp), %r15
jne 0x790c
movq 0x48(%r14), %rdx
cmpq %rdx, 0xa8(%rsp)
jne 0x792d
movq 0xb0(%rsp), %rdi
movq 0x50(%r14), %rsi
callq 0x3210
testl %eax, %eax
jne 0x792d
movq 0x90(%r14), %rcx
testq %rcx, %rcx
jne 0x7943
movq 0x116d9(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
testb %bl, %bl
je 0x7969
callq 0x3b2c
jmp 0x7995
leaq 0x48(%r14), %rsi
leaq 0xa8(%rsp), %rdi
movq %r14, %rdx
callq 0x3a04
jmp 0x7995
movq %rcx, %r8
movq 0x58(%rsp), %rdx
subq %rdx, %r8
jae 0x7970
movq 0x116a1(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
movq %rdx, %r8
subq %rcx, %r8
leaq 0xaacf(%rip), %rsi      # 0x12436
jmp 0x798e
callq 0x3b11
jmp 0x7995
subq 0xd8(%rsp), %r15
movq 0x11679(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
cmpq %r15, %rcx
jbe 0x79af
leaq 0xaadf(%rip), %rsi      # 0x1246d
xorl %eax, %eax
callq 0x31d0
movq 0x38(%rsp), %rax
incq %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %bl, %bl
je 0x79ba
callq 0x3af6
jmp 0x7995
callq 0x3adb
jmp 0x7995