// File: /workspace/github_c_makefile_star2_O3/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 0x7579
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r14
movq %rdi, %r12
movq 0xd8(%rsi), %rsi
callq 0x7571
movq %rax, %rbx
testq %rax, %rax
jne 0x75ac
movq %r12, %rdi
callq 0x379f
movq 0xb0(%r14), %rdi
callq 0x80e5
movq 0xa0(%r14), %rax
testq %rax, %rax
je 0x75d8
movq (%rax), %rdi
callq 0x80d5
movq 0xa0(%r14), %rdi
callq 0x3040
movq 0xa8(%r14), %rax
testq %rax, %rax
je 0x75f8
movq (%rax), %rdi
callq 0x80dd
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 0x761a
movq (%r12), %rcx
movl 0x10(%rcx), %edx
movl %edx, 0x90(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x80(%rsp)
leaq 0x28(%r14), %rdx
movq 0x68(%r14), %r9
movl 0x10(%rax), %ecx
movl %ecx, 0x70(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x38(%r14), %rcx
movq 0x40(%r14), %r8
movl 0x90(%rsp), %eax
movl %eax, 0x28(%rsp)
movaps 0x80(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x87c6
movq %r15, %r13
subq 0x30(%r12), %r13
movq %r13, 0xc0(%r14)
movq (%r14), %rdi
movq 0x10955(%rip), %rax     # 0x17ff8
movq (%rax), %rax
testq %rdi, %rdi
jne 0x76c1
leaq 0xb3be(%rip), %rsi      # 0x12a70
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x31d0
jmp 0x76c9
movq %rax, %rsi
callq 0x3130
movq 0x10928(%rip), %rax     # 0x17ff8
movq (%rax), %rsi
leaq 0xacd6(%rip), %rdi      # 0x123b0
callq 0x3130
leaq 0xa8(%rsp), %r12
leaq 0x70(%r14), %rsi
movq %r12, %rdi
callq 0xce67
testb %al, %al
movq %rbx, 0x30(%rsp)
movq %r14, 0x58(%rsp)
movq %r15, 0x50(%rsp)
movq %r13, 0x48(%rsp)
je 0x7712
cmpb $-0x10, 0x8(%r14)
jne 0x7755
movq %r12, %rdi
callq 0xc61a
testb %al, %al
je 0x774b
cmpq $0x0, 0x98(%rsp)
movq 0x108ca(%rip), %rax     # 0x17ff8
movq (%rax), %rax
jne 0x78ab
leaq 0xac75(%rip), %rdi      # 0x123b3
movq %rax, %rsi
callq 0x3130
jmp 0x78bb
callq 0x3963
jmp 0x78bb
movq 0x98(%r14), %r13
movb $0x1, %bl
testq %r13, %r13
je 0x78c4
movq $0x0, 0x40(%rsp)
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0x77b4
movb (%r13), %cl
cmpb %cl, (%rax)
jne 0x77ab
movq $-0x1, %rdx
cmpq $0x12, %rdx
je 0x77c1
movb 0x2(%rax,%rdx), %dil
leaq 0x1(%rdx), %rsi
cmpb 0x2(%r13,%rdx), %dil
movq %rsi, %rdx
je 0x778c
cmpq $0x12, %rsi
ja 0x77c1
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x7781
movq %r13, %rdi
callq 0x3930
jmp 0x786f
movq 0x18(%r13), %rbx
movq 0x18(%rax), %r12
movq %rbx, %rbp
movq %r12, 0x38(%rsp)
testq %rbx, %rbx
je 0x785d
movq %rbx, %rbp
movq 0x38(%rsp), %rax
movq %rax, %r12
testq %rax, %rax
je 0x785d
movq 0x38(%rsp), %r12
movq %rbx, %rbp
movq 0x10(%rbp), %rdx
cmpq 0x10(%r12), %rdx
jne 0x7862
movq 0x18(%rbp), %rdi
movq 0x18(%r12), %rsi
callq 0x3210
testl %eax, %eax
jne 0x7862
movb 0x8(%rbp), %al
cmpb 0x8(%r12), %al
jne 0x7862
testb %al, %al
je 0x784a
xorl %r15d, %r15d
xorl %r14d, %r14d
movq (%rbp), %rdi
addq %r15, %rdi
movq (%r12), %rsi
addq %r15, %rsi
callq 0xce67
testb %al, %al
je 0x7862
incq %r14
movzbl 0x8(%rbp), %eax
addq $0x20, %r15
cmpq %rax, %r14
jb 0x7823
movq 0x20(%rbp), %rbp
movq 0x20(%r12), %r12
testq %rbp, %rbp
je 0x785d
testq %r12, %r12
jne 0x77f2
orq %r12, %rbp
je 0x7894
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
callq 0x38d2
movq 0x10782(%rip), %rax     # 0x17ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x3180
movb $0x1, 0x191c6(%rip)     # 0x20a50
movl $0x1, %eax
movq %rax, 0x40(%rsp)
movq 0x20(%r13), %r13
testq %r13, %r13
jne 0x7770
cmpl $0x0, 0x40(%rsp)
sete %bl
jmp 0x78c4
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x397f
movb $0x1, 0x1918e(%rip)     # 0x20a50
xorl %ebx, %ebx
movq 0x58(%rsp), %r14
cmpb $0x1, 0x58(%r14)
movq 0x50(%rsp), %r15
jne 0x78f8
movq 0x98(%rsp), %rdx
cmpq 0x48(%r14), %rdx
jne 0x7919
movq 0xa0(%rsp), %rdi
movq 0x50(%r14), %rsi
callq 0x3210
testl %eax, %eax
jne 0x7919
movq 0x90(%r14), %rcx
testq %rcx, %rcx
jne 0x792f
movq 0x106ed(%rip), %rax     # 0x17ff8
movq (%rax), %rdi
testb %bl, %bl
je 0x7955
callq 0x3b23
jmp 0x7981
leaq 0x48(%r14), %rsi
leaq 0x98(%rsp), %rdi
movq %r14, %rdx
callq 0x39f7
jmp 0x7981
movq %rcx, %r8
movq 0x48(%rsp), %rdx
subq %rdx, %r8
jae 0x795c
movq 0x106b5(%rip), %rax     # 0x17ff8
movq (%rax), %rdi
movq %rdx, %r8
subq %rcx, %r8
leaq 0xaae3(%rip), %rsi      # 0x12436
jmp 0x797a
callq 0x3b08
jmp 0x7981
subq 0xc8(%rsp), %r15
movq 0x1068d(%rip), %rax     # 0x17ff8
movq (%rax), %rdi
cmpq %r15, %rcx
jbe 0x799b
leaq 0xaaf3(%rip), %rsi      # 0x1246d
xorl %eax, %eax
callq 0x31d0
movq 0x30(%rsp), %rax
incq %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %bl, %bl
je 0x79a6
callq 0x3aed
jmp 0x7981
callq 0x3ad2
jmp 0x7981