// File: /workspace/github_c_makefile_star2_O0/robertdavidgraham[P]wc2/wcdiff.c
// Function: main
int main(int argc, char *argv[])
{
    unsigned char *buf;
    unsigned seed = 0;
    unsigned length = 1024 * 1024;
    unsigned i;
    unsigned min = 0;
    unsigned max = length;
    unsigned min_diff, max_diff;
    long x, y;
    const char *progname1 = "./wc2";
    const char *progname2 = "./wc2";
    const char *parms1 = NULL;
    char *parms2 = NULL;

    signal(SIGPIPE, SIG_IGN);

    /* The first parameter is the program we are testing against 'wc' */
    if (argc < 2 || !is_executable(argv[1])) {
        fprintf(stderr, "[-] first parameter must be an executable program\n");
        return 1;
    } else
        progname2 = argv[1];

    /* The second parameter is option parameters */
    if (argc >= 3) {
        parms1 = argv[2];
    } else
        parms1 = NULL;

    if (parms1) {
        parms2 = malloc(strlen(parms1) + 2);
        strcpy(parms2, parms1);
        strcat(parms2, "P");
    }

    /* Create a buffer of deterministically random data. This will be the
     * same data whenever we run this program, on any CPu, any OS, and
     * any compiler */
    buf = malloc(length);
    for (i=0; i<length; i++)
        buf[i] = r_rand(&seed);

    /* First, make sure there's a difference */
    x = word_count(progname1, parms1, buf, max);
    y = word_count(progname2, parms2, buf, max);
    if (x == -1) {
        fprintf(stderr, "[-] %s: failed\n", progname1);
        exit(1);
    }
    if (y == -1) {
        fprintf(stderr, "[-] %s: failed\n", progname2);
        exit(1);
    }
    if (x == y) {
        fprintf(stderr, "[+] difference: none! (identical results)\n");
        return 0;
    } else {
        fprintf(stderr, "[+] difference: %s=%lu %s=%lu\n", progname1, x, progname2, y);
    }

    /* Now search for one past the first difference */
    min = 0;
    max = length;
    while (min < max) {
        unsigned half = (max - min)/2 + min;
        fprintf(stderr, "max=%8lu\b\b\b\b\b\b\b\b\b\b\b\b", (unsigned long)(max));
        x = word_count(progname1, parms1, buf, half);
        y = word_count(progname2, parms2, buf, half);
        if (x == y) {
            /* we went too far, so we need to go back */
            min = half + 1;
        } else {
            /* we didn't go far enough */
            max = half;
        }
    }
    max_diff = max;
    fprintf(stderr, "max=%8lu\n", (unsigned long)(max_diff));

    /* Now search for one before the first difference */
    min = 0;
    max = max_diff;
    while (min < max) {
        unsigned half = (max - min)/2 + min;
        fprintf(stderr, "min=%8lu\b\b\b\b\b\b\b\b\b\b\b\b", (unsigned long)(min));
        /* fprintf(stderr, "min=%u, half=%u, max=%u\n", min, half, max); */
        x = word_count(progname1, parms1, buf + half, max_diff - half);
        y = word_count(progname2, parms2, buf + half, max_diff - half);
        if (x == y) {
            /* we went too far, so we need to go back */
            max = half;
        } else {
            /* we didn't go far enough */
            min = half + 1;
        }
    }
    min_diff = min;

    /* If they are equal, reduce min by one */
    if (min_diff > 0) {
        x = word_count(progname1, parms1, buf + min_diff, max_diff - min_diff);
        y = word_count(progname2, parms2, buf + min_diff, max_diff - min_diff);
        if (x == y) {
            min_diff--;
        }
    }
    fprintf(stderr, "min=%8lu\n", (unsigned long)(min_diff));

    /* print results */
    x = word_count(progname1, parms1, buf + min_diff, max_diff - min_diff);
    y = word_count(progname2, parms2, buf + min_diff, max_diff - min_diff);
    printf("Diff string: wc=%ld wc2=%ld \n", x, y);
    /* print_diff(buf, min_diff, max_diff); */
    printf("\"");
    for (i=min_diff; i<max_diff; i++) {
        printf("\\\\x%02x", buf[i]);
    }
    printf("\"\n");



/*

    if (argc < 3 || argv[2][0] != '-') {
        fprintf(stderr, "[-] second parameter must be option like -m or -w\n");
        return 1;
    }

    if (argc < 4 || !is_exists(argv[3])) {
        fprintf(stderr, "[-] third parameter must be file\n");
        return 1;
    }
*/

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x100000, -0x20(%rbp)  # imm = 0x100000
movl $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq 0x5b7(%rip), %rax       # 0x208f
movq %rax, -0x50(%rbp)
leaq 0x5ac(%rip), %rax       # 0x208f
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0xd, %edi
movl $0x1, %esi
callq 0x10d0
cmpl $0x2, -0x8(%rbp)
jl 0x1b1e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1320
cmpl $0x0, %eax
jne 0x1b42
movq 0x24d3(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x566(%rip), %rsi       # 0x2095
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x4(%rbp)
jmp 0x1f6a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
cmpl $0x3, -0x8(%rbp)
jl 0x1b62
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x1b6a
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x1ba7
movq -0x60(%rbp), %rdi
callq 0x1060
movq %rax, %rdi
addq $0x2, %rdi
callq 0x1100
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1040
movq -0x68(%rbp), %rdi
leaq 0x526(%rip), %rsi       # 0x20c8
callq 0x1140
movl -0x20(%rbp), %eax
movl %eax, %edi
callq 0x1100
movq %rax, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x1be4
leaq -0x1c(%rbp), %rdi
callq 0x1f80
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1bbc
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x48(%rbp)
cmpq $-0x1, -0x40(%rbp)
jne 0x1c45
movq 0x23d2(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
leaq 0x496(%rip), %rsi       # 0x20ca
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1150
cmpq $-0x1, -0x48(%rbp)
jne 0x1c72
movq 0x23a5(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x469(%rip), %rsi       # 0x20ca
movb $0x0, %al
callq 0x10e0
movl $0x1, %edi
callq 0x1150
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1ca0
movq 0x2375(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x44d(%rip), %rsi       # 0x20da
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x4(%rbp)
jmp 0x1f6a
movq 0x2351(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x48(%rbp), %r9
leaq 0x444(%rip), %rsi       # 0x2105
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x1d5c
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
shrl %eax
addl -0x28(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq 0x2306(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %edx
leaq 0x423(%rip), %rsi       # 0x2124
movb $0x0, %al
callq 0x10e0
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x6c(%rbp), %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x6c(%rbp), %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d51
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1d57
movl -0x6c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1cd5
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
movq 0x228f(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl -0x34(%rbp), %eax
movl %eax, %edx
leaq 0x3c1(%rip), %rsi       # 0x2139
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x28(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x1e2d
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
shrl %eax
addl -0x28(%rbp), %eax
movl %eax, -0x70(%rbp)
movq 0x224b(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl -0x28(%rbp), %eax
movl %eax, %edx
leaq 0x387(%rip), %rsi       # 0x2143
movb $0x0, %al
callq 0x10e0
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x70(%rbp), %eax
addq %rax, %rdx
movl -0x34(%rbp), %eax
subl -0x70(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x70(%rbp), %eax
addq %rax, %rdx
movl -0x34(%rbp), %eax
subl -0x70(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1e1f
movl -0x70(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1e28
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1d8c
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jbe 0x1e98
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1e96
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1e98
movq 0x2159(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl -0x30(%rbp), %eax
movl %eax, %edx
leaq 0x2aa(%rip), %rsi       # 0x2158
movb $0x0, %al
callq 0x10e0
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x17f0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq 0x254(%rip), %rdi       # 0x2162
movb $0x0, %al
callq 0x1080
leaq 0x264(%rip), %rdi       # 0x2180
movb $0x0, %al
callq 0x1080
movl -0x30(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x1f55
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %esi
leaq 0x23f(%rip), %rdi       # 0x2182
movb $0x0, %al
callq 0x1080
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1f29
leaq 0x22e(%rip), %rdi       # 0x218a
movb $0x0, %al
callq 0x1080
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)