// File: ctSkennerton[P]fxtract/util/tap.c
// Function: gen_result
unsigned int
_gen_result(int type, uint64_t got, uint64_t expected,
            int (*cmp)(const void * got, const void * expected),
            const char * (*to_str)(const void * object), const char *func,
            const char *file, unsigned int line, const char *test_name, ...)
{
    va_list ap;
    const void *got_ptr = (const void *)(uintptr_t)got;
    const void *exp_ptr = (const void *)(uintptr_t)expected;
    char  * local_test_name = NULL;
    char  * c;
    int     name_is_digits;
    int     ok;

    switch (type) {
    case 1:
        ok = (int)(got == expected);
        break;

    case 2:
        ok = (int)(got_ptr && exp_ptr && strcmp(got_ptr, exp_ptr) == 0);
        break;

    case 3:
        ok = (int)((*cmp)(got_ptr, exp_ptr) == 0);
        break;

    case 4:
        ok = (int)(got_ptr && exp_ptr && strncmp(got_ptr, exp_ptr, (size_t)cmp) == 0);
        break;

    case 5:
        ok = (int)(got_ptr && exp_ptr && strstr(got_ptr, exp_ptr) != NULL);
        break;

    default:
        ok = got;
        break;
    }

/* ===================  LOCK  =================== */
    LOCK;
    flockfile(tap_out);
    flockfile(stderr);

    test_count++;

    /* Start by taking the test name and performing any printf()
       expansions on it */
    if (test_name != NULL) {
        va_start(ap, test_name);
        if (my_vasprintf(&local_test_name, test_name, ap) < 0)
            local_test_name = NULL;
        va_end(ap);

        /* Make sure the test name contains more than digits
           and spaces.  Emit an error message and exit if it
           does */
        if(local_test_name) {
            name_is_digits = 1;
            for(c = local_test_name; *c != '\0'; c++) {
                if(!isdigit(*c) && !isspace(*c)) {
                    name_is_digits = 0;
                    break;
                }
            }

            if(name_is_digits) {
                _diag("    You named your test '%s'.  You shouldn't use numbers for your test names.", local_test_name);
                _diag("    Very confusing.");
            }
        }
    }

    if(!ok) {
        fprintf(tap_out, "not ");
        failures++;
    }

    fprintf(tap_out, "ok %d", test_count);

    if (test_case_name != NULL || test_name != NULL) {
        fprintf(tap_out, " - ");
    }

    if (test_case_name != NULL) {
        fputs(test_case_name, tap_out);
    }

    if(test_name != NULL) {
        if (test_case_name != NULL) {
            fprintf(tap_out, ": ");
        }

        /* Print the test name, escaping any '#' characters it
           might contain */
        if(local_test_name != NULL) {
            for(c = local_test_name; *c != '\0'; c++) {
                if(*c == '#')
                    fputc('\\', tap_out);
                fputc((int)*c, tap_out);
            }
        } else {    /* my_vasprintf() failed, use a fixed message */
            fprintf(tap_out, "%s", todo_msg_fixed);
        }
    }

    /* If we're in a todo_start() block then flag the test as being
       TODO.  todo_msg should contain the message to print at this
       point.  If it's NULL then asprintf() failed, and we should
       use the fixed message.

       This is not counted as a failure, so decrement the counter if
       the test failed. */
    if (todo) {
        fprintf(tap_out, " # TODO %s", todo_msg ? todo_msg : todo_msg_fixed);
        if(!ok)
            failures--;
    }

    fprintf(tap_out, "\n");

    if (!ok) {
        _diag("    Failed %stest (%s:%s() at line %d)",
              todo ? "(TODO) " : "", file, func, line);

        switch (type) {
        case 1:
            if (got > 256 || expected > 256) {
                _diag("         got: 0x%"PRIx64" (%"PRId64")", got, got);
                _diag("    expected: 0x%"PRIx64" (%"PRId64")", expected, expected);
            } else {
                _diag("         got: %"PRId64, got);
                _diag("    expected: %"PRId64, expected);
            }
            break;

        case 2:
            _diag("         got: \"%s\"", (const char *)got_ptr);
            _diag("    expected: \"%s\"", (const char *)exp_ptr);
            break;

        case 3:
            _diag("         got: %s", (*to_str)(got_ptr));
            _diag("    expected: %s", (*to_str)(exp_ptr));
            break;

        case 4:
            _diag("         got: %.*s", got_ptr ? (long)cmp : 0, (const char *)got_ptr);
            _diag("    expected: %.*s", exp_ptr ? (long)cmp : 0, (const char *)exp_ptr);
            break;

        case 5:
            _diag("                    got: \"%s\"", (const char *)got_ptr);
            _diag("    expected to contain: \"%s\"", (const char *)exp_ptr);
            break;

        default:
            break;
        }
    }

    free(local_test_name);

    funlockfile(stderr);
    funlockfile(tap_out);
    UNLOCK;
/* =================== UNLOCK =================== */

    if (!ok && !todo && (tap_flags & TAP_FLAG_ON_FAILURE_EXIT)) {
        exit(test_count);
    }

    /* We only care (when testing) that ok is positive, but here we
       specifically only want to return 1 or 0 */
    return ok ? 1 : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
testb %al, %al
je 0xaa17
movaps %xmm0, -0x100(%rbp)
movaps %xmm1, -0xf0(%rbp)
movaps %xmm2, -0xe0(%rbp)
movaps %xmm3, -0xd0(%rbp)
movaps %xmm4, -0xc0(%rbp)
movaps %xmm5, -0xb0(%rbp)
movaps %xmm6, -0xa0(%rbp)
movaps %xmm7, -0x90(%rbp)
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl -0x4(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x138(%rbp)
subl $0x4, %eax
ja 0xab95
movq -0x138(%rbp), %rax
leaq 0x1f7a(%rip), %rcx      # 0xc9f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
jmp 0xab9c
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0x139(%rbp)
je 0xaace
xorl %eax, %eax
cmpq $0x0, -0x60(%rbp)
movb %al, -0x139(%rbp)
je 0xaace
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x32a0
cmpl $0x0, %eax
sete %al
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
jmp 0xab9c
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
jmp 0xab9c
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0x13a(%rbp)
je 0xab3d
xorl %eax, %eax
cmpq $0x0, -0x60(%rbp)
movb %al, -0x13a(%rbp)
je 0xab3d
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x30f0
cmpl $0x0, %eax
sete %al
movb %al, -0x13a(%rbp)
movb -0x13a(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
jmp 0xab9c
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0x13b(%rbp)
je 0xab85
xorl %eax, %eax
cmpq $0x0, -0x60(%rbp)
movb %al, -0x13b(%rbp)
je 0xab85
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3080
cmpq $0x0, %rax
setne %al
movb %al, -0x13b(%rbp)
movb -0x13b(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
jmp 0xab9c
movq -0x10(%rbp), %rax
movl %eax, -0x78(%rbp)
movq 0x5c1d(%rip), %rdi      # 0x107c0
callq 0x30b0
movq 0x5429(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x30b0
movl 0x5c0b(%rip), %eax      # 0x107c8
addl $0x1, %eax
movl %eax, 0x5c02(%rip)      # 0x107c8
cmpq $0x0, 0x20(%rbp)
je 0xacc0
leaq -0x50(%rbp), %rax
leaq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x30, (%rax)
movq 0x20(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0xb0b0
cmpl $0x0, %eax
jge 0xac13
movq $0x0, -0x68(%rbp)
leaq -0x50(%rbp), %rax
cmpq $0x0, -0x68(%rbp)
je 0xacbe
movl $0x1, -0x74(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xac96
callq 0x31e0
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0xac86
callq 0x31e0
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0xac86
movl $0x0, -0x74(%rbp)
jmp 0xac96
jmp 0xac88
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xac31
cmpl $0x0, -0x74(%rbp)
je 0xacbc
movq -0x68(%rbp), %rsi
leaq 0x1d71(%rip), %rdi      # 0xca18
movb $0x0, %al
callq 0xb150
leaq 0x1db1(%rip), %rdi      # 0xca66
movb $0x0, %al
callq 0xb150
jmp 0xacbe
jmp 0xacc0
cmpl $0x0, -0x78(%rbp)
jne 0xacea
movq 0x5af3(%rip), %rdi      # 0x107c0
leaq 0x1da6(%rip), %rsi      # 0xca7a
movb $0x0, %al
callq 0x32c0
movl 0x5aeb(%rip), %eax      # 0x107cc
addl $0x1, %eax
movl %eax, 0x5ae2(%rip)      # 0x107cc
movq 0x5acf(%rip), %rdi      # 0x107c0
movl 0x5ad1(%rip), %edx      # 0x107c8
leaq 0x1d81(%rip), %rsi      # 0xca7f
movb $0x0, %al
callq 0x32c0
cmpq $0x0, 0x5ac3(%rip)      # 0x107d0
jne 0xad16
cmpq $0x0, 0x20(%rbp)
je 0xad2b
movq 0x5aa3(%rip), %rdi      # 0x107c0
leaq 0x1d61(%rip), %rsi      # 0xca85
movb $0x0, %al
callq 0x32c0
cmpq $0x0, 0x5a9d(%rip)      # 0x107d0
je 0xad48
movq 0x5a94(%rip), %rdi      # 0x107d0
movq 0x5a7d(%rip), %rsi      # 0x107c0
callq 0x3210
cmpq $0x0, 0x20(%rbp)
je 0xadeb
cmpq $0x0, 0x5a75(%rip)      # 0x107d0
je 0xad72
movq 0x5a5c(%rip), %rdi      # 0x107c0
leaq 0x1d1e(%rip), %rsi      # 0xca89
movb $0x0, %al
callq 0x32c0
cmpq $0x0, -0x68(%rbp)
je 0xadcd
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xadcb
movq -0x70(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0xadaa
movq 0x5a20(%rip), %rsi      # 0x107c0
movl $0x5c, %edi
callq 0x3260
movq -0x70(%rbp), %rax
movsbl (%rax), %edi
movq 0x5a08(%rip), %rsi      # 0x107c0
callq 0x3260
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xad81
jmp 0xade9
movq 0x59ec(%rip), %rdi      # 0x107c0
movq 0x59c5(%rip), %rdx      # 0x107a0
leaq 0x1d6e(%rip), %rsi      # 0xcb50
movb $0x0, %al
callq 0x32c0
jmp 0xadeb
cmpl $0x0, 0x59e6(%rip)      # 0x107d8
je 0xae5d
movq 0x59c5(%rip), %rax      # 0x107c0
movq %rax, -0x148(%rbp)
cmpq $0x0, 0x59d6(%rip)      # 0x107e0
je 0xae1c
movq 0x59cd(%rip), %rax      # 0x107e0
movq %rax, -0x150(%rbp)
jmp 0xae2a
movq 0x597d(%rip), %rax      # 0x107a0
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rdi
movq -0x150(%rbp), %rdx
leaq 0x1c4d(%rip), %rsi      # 0xca8c
movb $0x0, %al
callq 0x32c0
cmpl $0x0, -0x78(%rbp)
jne 0xae5b
movl 0x597a(%rip), %eax      # 0x107cc
addl $-0x1, %eax
movl %eax, 0x5971(%rip)      # 0x107cc
jmp 0xae5d
movq 0x595c(%rip), %rdi      # 0x107c0
leaq 0x1d62(%rip), %rsi      # 0xcbcd
movb $0x0, %al
callq 0x32c0
cmpl $0x0, -0x78(%rbp)
jne 0xb049
movl 0x5956(%rip), %eax      # 0x107d8
testl %eax, %eax
leaq 0x1c33(%rip), %rax      # 0xcabe
leaq 0x1d3c(%rip), %rsi      # 0xcbce
cmovneq %rax, %rsi
movq 0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl 0x18(%rbp), %r8d
leaq 0x1bee(%rip), %rdi      # 0xca97
xorl %eax, %eax
callq 0xb150
movl -0x4(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x158(%rbp)
subl $0x4, %eax
ja 0xb045
movq -0x158(%rbp), %rax
leaq 0x1b2f(%rip), %rcx      # 0xca04
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpq $0x100, -0x10(%rbp)     # imm = 0x100
ja 0xaef2
cmpq $0x100, -0x18(%rbp)     # imm = 0x100
jbe 0xaf20
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq 0x1bc5(%rip), %rdi      # 0xcac6
movb $0x0, %al
callq 0xb150
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x1bc9(%rip), %rdi      # 0xcae0
movb $0x0, %al
callq 0xb150
jmp 0xaf44
movq -0x10(%rbp), %rsi
leaq 0x1bcf(%rip), %rdi      # 0xcafa
movb $0x0, %al
callq 0xb150
movq -0x18(%rbp), %rsi
leaq 0x1bcf(%rip), %rdi      # 0xcb0c
movb $0x0, %al
callq 0xb150
jmp 0xb047
movq -0x58(%rbp), %rsi
leaq 0x1c30(%rip), %rdi      # 0xcb84
movb $0x0, %al
callq 0xb150
movq -0x60(%rbp), %rsi
leaq 0x1bb8(%rip), %rdi      # 0xcb1e
movb $0x0, %al
callq 0xb150
jmp 0xb047
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rdi
callq *%rax
movq %rax, %rsi
leaq 0x1bab(%rip), %rdi      # 0xcb31
movb $0x0, %al
callq 0xb150
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rdi
callq *%rax
movq %rax, %rsi
leaq 0x1ba1(%rip), %rdi      # 0xcb42
movb $0x0, %al
callq 0xb150
jmp 0xb047
cmpq $0x0, -0x58(%rbp)
je 0xafc1
movq -0x20(%rbp), %rax
movq %rax, -0x160(%rbp)
jmp 0xafcc
xorl %eax, %eax
movq %rax, -0x160(%rbp)
jmp 0xafcc
movq -0x160(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq 0x1b75(%rip), %rdi      # 0xcb53
movb $0x0, %al
callq 0xb150
cmpq $0x0, -0x60(%rbp)
je 0xaff9
movq -0x20(%rbp), %rax
movq %rax, -0x168(%rbp)
jmp 0xb004
xorl %eax, %eax
movq %rax, -0x168(%rbp)
jmp 0xb004
movq -0x168(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq 0x1b50(%rip), %rdi      # 0xcb66
movb $0x0, %al
callq 0xb150
jmp 0xb047
movq -0x58(%rbp), %rsi
leaq 0x1b4f(%rip), %rdi      # 0xcb79
movb $0x0, %al
callq 0xb150
movq -0x60(%rbp), %rsi
leaq 0x1b5b(%rip), %rdi      # 0xcb97
movb $0x0, %al
callq 0xb150
jmp 0xb047
jmp 0xb047
jmp 0xb049
movq -0x68(%rbp), %rdi
callq 0x3240
movq 0x4f7f(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x3170
movq 0x5758(%rip), %rdi      # 0x107c0
callq 0x3170
cmpl $0x0, -0x78(%rbp)
jne 0xb095
cmpl $0x0, 0x575e(%rip)      # 0x107d8
jne 0xb095
movl 0x5766(%rip), %eax      # 0x107e8
andl $0x1, %eax
cmpl $0x0, %eax
je 0xb095
movl 0x5738(%rip), %edi      # 0x107c8
callq 0x3250
movl -0x78(%rbp), %eax
testl %eax, %eax
setne %al
movzbl %al, %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax)