// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
cmpl $0x1, %edi
jle 0x8016
movq 0x8(%rsi), %rdi
callq 0x4e90
movq %rax, %rbx
movq 0x40(%rax), %rdi
movl 0x18(%rax), %esi
movl 0x20(%rax), %edx
movl 0x4c(%rax), %ecx
callq 0x447f
movq %rax, 0x8(%rsp)
movq 0x40(%rbx), %rdi
movl 0x18(%rbx), %esi
movl 0x20(%rbx), %edx
movl 0x4c(%rbx), %ecx
callq 0x447f
movq %rax, %rbx
xorl %ebp, %ebp
movq 0x6442(%rip), %r13      # 0xdfd8
movq 0x645b(%rip), %r12      # 0xdff8
xorl %r14d, %r14d
movq %rax, 0x10(%rsp)
movq (%r13), %rsi
movq 0x8(%rsp), %rdi
callq 0x4a7d
testl %eax, %eax
je 0x7f72
leaq 0x1(%r14), %rax
testq %r14, %r14
movq %rax, 0x20(%rsp)
je 0x7f1b
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
divq %rcx
testq %rdx, %rdx
jne 0x7be8
movq (%r12), %rsi
pushq $0x2e
popq %rdi
callq 0x2150
addq $0x2, %r14
movq %r14, %rax
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divq %rcx
testq %rdx, %rdx
jne 0x7c26
movq (%r12), %rsi
pushq $0xa
popq %r15
movl %r15d, %edi
callq 0x2150
movq (%r12), %rdi
movq %r14, %rsi
callq 0x78c8
movq (%r12), %rsi
movl %r15d, %edi
callq 0x2150
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq %rbp, %rdi
callq 0x79c3
testq %rax, %rax
je 0x7c4e
movq (%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x464f
jmp 0x7f5b
movq 0x8(%rsp), %rdi
callq 0x7998
movq %rax, %r14
leaq 0x8(%rax), %r15
andq $0x0, 0x18(%rax)
movq (%rax), %rbx
leaq 0x10(%rbx), %rax
movq %rax, 0x30(%r14)
movl $0x8, 0x38(%r14)
testq %rbp, %rbp
je 0x7c96
movq 0x8(%rbp), %r13
movq 0x18(%r13), %rax
movq %r14, 0x10(%rax)
subq 0x20(%r13), %rax
movq %rax, 0x10(%r14)
movq %r15, 0x18(%r13)
jmp 0x7cf9
andq $0x0, 0x10(%r14)
pushq $0x1
popq %r12
movq %r12, %rdi
pushq $0x40
popq %rsi
callq 0x2170
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x800e
movq %rax, %r13
movq %r15, 0x18(%rax)
movabsq $0x500000020, %rax      # imm = 0x500000020
movq %rax, 0x8(%r13)
movq $0x8, 0x20(%r13)
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
callq 0x2170
movq %rax, (%r13)
testq %rax, %rax
je 0x800e
movl $0xa0111fe1, 0x38(%r13) # imm = 0xA0111FE1
movq %r14, %rbp
incl 0x10(%r13)
movq %r13, 0x8(%r14)
movl $0xfeedbef7, %eax       # imm = 0xFEEDBEF7
movl %eax, 0x3c(%r14)
movzbl 0x17(%rbx), %eax
shll $0x18, %eax
movsbl 0x16(%rbx), %ecx
shll $0x10, %ecx
addl %eax, %ecx
movsbl 0x15(%rbx), %eax
shll $0x8, %eax
addl %ecx, %eax
movsbl 0x14(%rbx), %ecx
addl %ecx, %eax
addl $0x9e3779b9, %eax       # imm = 0x9E3779B9
movzbl 0x13(%rbx), %ecx
shll $0x18, %ecx
movsbl 0x12(%rbx), %edx
shll $0x10, %edx
movsbl 0x11(%rbx), %esi
shll $0x8, %esi
addl %edx, %esi
movsbl 0x10(%rbx), %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(%r14)
movq 0x8(%rbp), %rcx
movl 0x8(%rcx), %eax
decl %eax
andl %esi, %eax
movq (%rcx), %rcx
shlq $0x4, %rax
movl 0x8(%rcx,%rax), %edx
incl %edx
movl %edx, 0x8(%rcx,%rax)
movq (%rcx,%rax), %rsi
movq %rsi, 0x28(%r14)
andq $0x0, 0x20(%r14)
testq %rsi, %rsi
je 0x7def
movq %r15, 0x18(%rsi)
addq %rax, %rcx
movq %r15, (%rcx)
imull $0xa, 0xc(%rcx), %eax
addl $0xa, %eax
cmpl %eax, %edx
jb 0x7f48
cmpl $0x1, 0x34(%r13)
je 0x7f48
movq %r15, 0x18(%rsp)
movl 0x8(%r13), %esi
addl %esi, %esi
shlq $0x4, %rsi
pushq $0x1
popq %rdi
callq 0x2170
testq %rax, %rax
je 0x800e
movq %rax, %r14
movl 0x10(%r13), %esi
movb 0xc(%r13), %cl
incb %cl
movl 0x8(%r13), %r8d
leal -0x1(,%r8,2), %r9d
movl %r9d, %eax
andl %esi, %eax
shrl %cl, %esi
cmpl $0x1, %eax
sbbl $-0x1, %esi
movl %esi, 0x28(%r13)
andl $0x0, 0x2c(%r13)
movq (%r13), %rdi
xorl %ecx, %ecx
xorl %r10d, %r10d
cmpq %r8, %r10
je 0x7ed2
movq %r10, %rax
shlq $0x4, %rax
movq (%rdi,%rax), %r11
testq %r11, %r11
je 0x7ecd
movq 0x20(%r11), %rbx
movl 0x34(%r11), %edx
andl %r9d, %edx
shlq $0x4, %rdx
leaq (%r14,%rdx), %r12
movl 0x8(%r14,%rdx), %eax
incl %eax
movl %eax, 0x8(%r14,%rdx)
cmpl %esi, %eax
jbe 0x7eae
incl %ecx
movl %ecx, 0x2c(%r13)
xorl %edx, %edx
divl %esi
movl %eax, 0xc(%r12)
andq $0x0, 0x18(%r11)
movq (%r12), %rax
movq %rax, 0x20(%r11)
testq %rax, %rax
je 0x7ec4
movq %r11, 0x18(%rax)
movq %r11, (%r12)
movq %rbx, %r11
jmp 0x7e77
incq %r10
jmp 0x7e67
callq 0x2030
movq 0x18(%rsp), %rax
movq (%rax), %rax
shll 0x8(%rax)
incl 0xc(%rax)
movq %r14, (%rax)
movl 0x10(%rax), %ecx
shrl %ecx
cmpl %ecx, 0x2c(%rax)
jbe 0x7f44
movl 0x30(%rax), %ecx
incl %ecx
movl %ecx, 0x30(%rax)
cmpl $0x2, %ecx
movq 0x60f4(%rip), %r12      # 0xdff8
movq 0x10(%rsp), %rbx
movq 0x60c8(%rip), %r13      # 0xdfd8
jb 0x7f5b
movl $0x1, 0x34(%rax)
jmp 0x7f5b
movq (%r12), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
movsd 0x18(%rax), %xmm0
movq 0x20(%rax), %rcx
leaq 0x20b6(%rip), %rsi      # 0x9fee
movb $0x1, %al
callq 0x21a0
jmp 0x7c26
andl $0x0, 0x30(%rax)
movq 0x60a9(%rip), %r12      # 0xdff8
movq 0x10(%rsp), %rbx
movq 0x607d(%rip), %r13      # 0xdfd8
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x464f
movq 0x20(%rsp), %r14
jmp 0x7ba5
movq (%r12), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
movsd 0x18(%rax), %xmm0
movq 0x20(%rax), %rcx
leaq 0x207b(%rip), %rsi      # 0xa00a
movb $0x1, %al
callq 0x21a0
movq (%r12), %rdi
leaq 0x2085(%rip), %rsi      # 0xa026
movq %r14, %rdx
xorl %eax, %eax
callq 0x21a0
movq %rbx, %rdi
callq 0x4774
movq (%r12), %rcx
leaq 0x207d(%rip), %rdi      # 0xa03b
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
movq 0x6000(%rip), %rbx      # 0xdfd0
testq %rbp, %rbp
je 0x7fe7
movq (%rbp), %rdi
movq (%rbx), %rsi
callq 0x4211
movq 0x18(%rbp), %rbp
jmp 0x7fd0
movq (%r12), %rcx
leaq 0x2064(%rip), %rdi      # 0xa056
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rdi
callq 0x2280
callq 0x7afe
nop