// File: /workspace/github_c_makefile_star2_O3/esheldon[P]xshear/src/redshear.c
// Function: main
int main(int argc, char** argv) {
    int64 counter=0;
    if (argc < 2) {
        usage_and_exit();
    }

    const char* config_url = argv[1];
    ShearConfig* config=sconfig_read(config_url);

    // this is the beginning of the table
    LensumHash* hash = NULL;

    Lensum* lensum = lensum_new(config->nbin, config->shear_style, config->scstyle, config->shear_units);
    Lensum* lensum_tot = lensum_new(config->nbin, config->shear_style, config->scstyle, config->shear_units);
    while (lensum_read_into(lensum, stdin)) {
        counter++;
        if (counter == 1) {
            wlog("first lensum: %ld %.8g %ld\n", 
                 lensum->index, lensum->weight, 
                 lensum->totpairs);
        }
        if ((counter % 10000) == 0) {
            wlog(".");
        }
        if (((counter+1) % 1000000) == 0) {
            wlog("\n");
            comma_print(stderr,counter+1);
            wlog("\n");
        }

        LensumHash* this_lens = find_lens(hash, lensum->index);
        if (this_lens == NULL) {
            // copy of lensum made inside
            LensumHash* lh = lensum_hash_fromlensum(lensum);
            // this gets expanded to lh->lensum->index
            HASH_ADD_INT64(hash, lensum->index, lh);
        } else {
            lensum_add(this_lens->lensum, lensum);
        }
        lensum_add(lensum_tot, lensum);

    }

    wlog("\nlast lensum: %ld %.8g %ld\n", 
            lensum->index, lensum->weight, lensum->totpairs);

    wlog("Read a total of %ld\n", counter);

    // this is the summary
    lensum_print(lensum_tot);

    wlog("Writing results to stdout\n");
    LensumHash *tlensum=NULL;
    for(tlensum=hash; tlensum != NULL; tlensum=tlensum->hh.next) {
        lensum_write(tlensum->lensum, stdout);
    }

    wlog("Done\n");

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x1, %edi
jle 0x8ad9
movq 0x8(%rsi), %rdi
callq 0x2ded
movq %rax, %r14
movq 0x40(%rax), %rdi
movl 0x18(%rax), %esi
movl 0x20(%rax), %edx
movl 0x4c(%rax), %ecx
callq 0x5840
movq %rax, %rbx
movq 0x40(%r14), %rdi
movl 0x18(%r14), %esi
movl 0x20(%r14), %edx
movl 0x4c(%r14), %ecx
callq 0x5840
movq %rax, 0x8(%rsp)
movq 0x5977(%rip), %r13      # 0xdfd8
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x5ce2
movq $0x0, (%rsp)
movl $0x0, %r15d
testl %eax, %eax
je 0x8aaa
xorl %r15d, %r15d
movq 0x596b(%rip), %rbp      # 0xdff8
movq $0x0, (%rsp)
movq %r15, %r14
incq %r15
testq %r14, %r14
je 0x8a50
movq %r15, %rax
movabsq $-0x2d77318fc504816f, %rcx # imm = 0xD288CE703AFB7E91
imulq %rcx, %rax
rorq $0x4, %rax
movabsq $0x68db8bac710cb, %rcx  # imm = 0x68DB8BAC710CB
cmpq %rcx, %rax
ja 0x86d6
movq (%rbp), %rsi
movl $0x2e, %edi
callq 0x2150
addq $0x2, %r14
movq %r14, %rax
movabsq $0x790fb65668c26139, %rcx # imm = 0x790FB65668C26139
imulq %rcx, %rax
rorq $0x6, %rax
movabsq $0x10c6f7a0b5ed, %rcx   # imm = 0x10C6F7A0B5ED
cmpq %rcx, %rax
ja 0x8726
movq (%rbp), %rsi
movl $0xa, %edi
callq 0x2150
movq (%rbp), %rdi
movq %r14, %rsi
callq 0x8388
movq (%rbp), %rsi
movl $0xa, %edi
callq 0x2150
movq 0x10(%rbx), %rsi
movq (%rsp), %r12
movq %r12, %rdi
callq 0x84a3
testq %rax, %rax
je 0x874b
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x5a04
jmp 0x8a89
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r13
movq %rbx, %rdi
callq 0x6005
movq %rax, %r14
movq %rax, (%r13)
leaq 0x8(%r13), %r8
movq $0x0, 0x18(%r13)
addq $0x10, %rax
movq %rax, 0x30(%r13)
movl $0x8, 0x38(%r13)
testq %r12, %r12
je 0x87ab
movq 0x8(%r12), %rbp
movq %r12, %rdi
movq 0x18(%rbp), %rax
movq %r13, 0x10(%rax)
subq 0x20(%rbp), %rax
movq %rax, 0x10(%r13)
movq %r8, 0x18(%rbp)
jmp 0x8818
movq %r8, %r12
movq $0x0, 0x10(%r13)
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x8acf
movq %rax, %rbp
movq %r12, 0x18(%rax)
movabsq $0x500000020, %rax      # imm = 0x500000020
movq %rax, 0x8(%rbp)
movq $0x8, 0x20(%rbp)
movl $0x1, %edi
movl $0x200, %esi            # imm = 0x200
callq 0x2170
movq %rax, (%rbp)
testq %rax, %rax
je 0x8acf
movl $0xa0111fe1, 0x38(%rbp) # imm = 0xA0111FE1
movq %r13, %rdi
movq %r12, %r8
incl 0x10(%rbp)
movq %rbp, 0x8(%r13)
movl $0xfeedbef7, %eax       # imm = 0xFEEDBEF7
movl %eax, 0x3c(%r13)
movzbl 0x17(%r14), %eax
shll $0x18, %eax
movsbl 0x16(%r14), %ecx
shll $0x10, %ecx
addl %eax, %ecx
movsbl 0x15(%r14), %eax
shll $0x8, %eax
addl %ecx, %eax
movsbl 0x14(%r14), %ecx
addl %ecx, %eax
addl $0x9e3779b9, %eax       # imm = 0x9E3779B9
movzbl 0x13(%r14), %ecx
shll $0x18, %ecx
movsbl 0x12(%r14), %edx
shll $0x10, %edx
movsbl 0x11(%r14), %esi
shll $0x8, %esi
addl %edx, %esi
movsbl 0x10(%r14), %edx
subl %eax, %ecx
addl %esi, %ecx
addl %edx, %ecx
addl $0x9f49bac2, %ecx       # imm = 0x9F49BAC2
xorl $0x7f76d, %ecx          # imm = 0x7F76D
subl %ecx, %eax
addl $0x1124109, %eax        # imm = 0x1124109
movl %ecx, %edx
shll $0x8, %edx
xorl %eax, %edx
movl $0xfeedbef7, %esi       # imm = 0xFEEDBEF7
subl %ecx, %esi
subl %edx, %esi
movl %edx, %eax
shrl $0xd, %eax
xorl %esi, %eax
subl %edx, %ecx
subl %eax, %ecx
movl %eax, %esi
shrl $0xc, %esi
xorl %ecx, %esi
subl %eax, %edx
subl %esi, %edx
movl %esi, %ecx
shll $0x10, %ecx
xorl %edx, %ecx
subl %esi, %eax
subl %ecx, %eax
movl %ecx, %edx
shrl $0x5, %edx
xorl %eax, %edx
subl %ecx, %esi
subl %edx, %esi
movl %edx, %eax
shrl $0x3, %eax
xorl %esi, %eax
subl %edx, %ecx
subl %eax, %ecx
movl %eax, %esi
shll $0xa, %esi
xorl %ecx, %esi
addl %esi, %eax
subl %eax, %edx
shrl $0xf, %esi
xorl %edx, %esi
movl %esi, 0x3c(%r13)
movq %rdi, (%rsp)
movq 0x8(%rdi), %rcx
movl 0x8(%rcx), %eax
decl %eax
andl %esi, %eax
movq (%rcx), %rdx
shlq $0x4, %rax
movl 0x8(%rdx,%rax), %ecx
incl %ecx
movl %ecx, 0x8(%rdx,%rax)
movq (%rdx,%rax), %rsi
movq %rsi, 0x28(%r13)
movq $0x0, 0x20(%r13)
testq %rsi, %rsi
je 0x891c
movq %r8, 0x18(%rsi)
addq %rax, %rdx
movq %r8, (%rdx)
movl 0xc(%rdx), %eax
leal (%rax,%rax,4), %eax
leal 0xa(,%rax,2), %eax
cmpl %eax, %ecx
jb 0x8a7b
cmpl $0x1, 0x34(%rbp)
je 0x8a7b
movq %r8, 0x10(%rsp)
movl 0x8(%rbp), %esi
addl %esi, %esi
shlq $0x4, %rsi
movl $0x1, %edi
callq 0x2170
testq %rax, %rax
je 0x8acf
movq %rax, %r13
movl 0x10(%rbp), %esi
movb 0xc(%rbp), %cl
incb %cl
movl 0x8(%rbp), %r8d
leal -0x1(,%r8,2), %r9d
movl %r9d, %eax
andl %esi, %eax
shrl %cl, %esi
cmpl $0x1, %eax
sbbl $-0x1, %esi
movl %esi, 0x28(%rbp)
movl $0x0, 0x2c(%rbp)
movq (%rbp), %rdi
testq %r8, %r8
je 0x8a0c
xorl %ecx, %ecx
xorl %r10d, %r10d
movq %r10, %rax
shlq $0x4, %rax
movq (%rdi,%rax), %r11
testq %r11, %r11
je 0x8a04
movq 0x20(%r11), %r14
movl 0x34(%r11), %edx
andl %r9d, %edx
shlq $0x4, %rdx
leaq (%rdx,%r13), %r12
movl 0x8(%r13,%rdx), %eax
incl %eax
movl %eax, 0x8(%r13,%rdx)
cmpl %esi, %eax
jbe 0x89df
incl %ecx
movl %ecx, 0x2c(%rbp)
xorl %edx, %edx
divl %esi
movl %eax, 0xc(%r12)
movq $0x0, 0x18(%r11)
movq (%r12), %rax
movq %rax, 0x20(%r11)
testq %rax, %rax
je 0x89f8
movq %r11, 0x18(%rax)
movq %r11, (%r12)
movq %r14, %r11
testq %r14, %r14
jne 0x89ae
incq %r10
cmpq %r8, %r10
jne 0x899e
callq 0x2030
movq 0x10(%rsp), %rax
movq (%rax), %rax
shll 0x8(%rax)
incl 0xc(%rax)
movq %r13, (%rax)
movl 0x10(%rax), %ecx
shrl %ecx
cmpl %ecx, 0x2c(%rax)
jbe 0x8a74
movl 0x30(%rax), %ecx
incl %ecx
movl %ecx, 0x30(%rax)
cmpl $0x2, %ecx
movq 0x559a(%rip), %r13      # 0xdfd8
movq 0x55b3(%rip), %rbp      # 0xdff8
jb 0x8a89
movl $0x1, 0x34(%rax)
jmp 0x8a89
movq (%rbp), %rdi
movq 0x10(%rbx), %rdx
movsd 0x18(%rbx), %xmm0
movq 0x20(%rbx), %rcx
leaq 0x1596(%rip), %rsi      # 0x9ffe
movb $0x1, %al
callq 0x21a0
jmp 0x8726
movl $0x0, 0x30(%rax)
movq 0x5556(%rip), %r13      # 0xdfd8
movq 0x556f(%rip), %rbp      # 0xdff8
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5a04
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x5ce2
testl %eax, %eax
jne 0x8695
movq (%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq 0x8(%rsp), %rcx
callq 0x3bab
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2280
callq 0x85c4
nop