// File: /workspace/github_c_makefile_star2_O1/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 0x8969
movq 0x8(%rsi), %rdi
callq 0x2d93
movq %rax, %r14
movq 0x40(%rax), %rdi
movl 0x18(%rax), %esi
movl 0x20(%rax), %edx
movl 0x4c(%rax), %ecx
callq 0x5783
movq %rax, %rbx
movq 0x40(%r14), %rdi
movl 0x18(%r14), %esi
movl 0x20(%r14), %edx
movl 0x4c(%r14), %ecx
callq 0x5783
movq %rax, %r14
movq 0x5b1a(%rip), %rbp      # 0xdfd8
movq (%rbp), %rsi
movq %rbx, %rdi
callq 0x5bc7
xorl %r13d, %r13d
movl $0x0, %r12d
testl %eax, %eax
jne 0x84f9
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x3b45
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r14, 0x8(%rsp)
movq %r12, %r15
testq %r12, %r12
je 0x8935
leaq 0x1(%r15), %r12
movq %r12, %rax
movabsq $-0x2d77318fc504816f, %rcx # imm = 0xD288CE703AFB7E91
imulq %rcx, %rax
rorq $0x4, %rax
movabsq $0x68db8bac710cb, %rcx  # imm = 0x68DB8BAC710CB
cmpq %rcx, %rax
ja 0x854c
movq 0x5ab9(%rip), %rax      # 0xdff8
movq (%rax), %rsi
movl $0x2e, %edi
callq 0x2150
addq $0x2, %r15
movq %r15, %rax
movabsq $0x790fb65668c26139, %rcx # imm = 0x790FB65668C26139
imulq %rcx, %rax
rorq $0x6, %rax
movabsq $0x10c6f7a0b5ed, %rcx   # imm = 0x10C6F7A0B5ED
cmpq %rcx, %rax
ja 0x85c4
movq 0x5a7d(%rip), %rax      # 0xdff8
movq %rbx, %rbp
movq %r14, %rbx
movq %r12, %r14
movq %r13, %r12
movq %rax, %r13
movq (%rax), %rsi
movl $0xa, %edi
callq 0x2150
movq (%r13), %rdi
movq %r15, %rsi
callq 0x81fc
movq (%r13), %rsi
movq %r12, %r13
movq %r14, %r12
movq %rbx, %r14
movq %rbp, %rbx
movq 0x5a1e(%rip), %rbp      # 0xdfd8
movl $0xa, %edi
callq 0x2150
movq 0x10(%rbx), %rsi
movq %r13, %rdi
callq 0x8317
testq %rax, %rax
je 0x85e5
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x58ef
jmp 0x87f0
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %rbp
movq %rbx, %rdi
callq 0x5edb
movq %rax, %r15
movq %rax, (%rbp)
leaq 0x8(%rbp), %rdi
movq $0x0, 0x18(%rbp)
addq $0x10, %rax
movq %rax, 0x30(%rbp)
movl $0x8, 0x38(%rbp)
testq %r13, %r13
je 0x8643
movq 0x8(%r13), %rax
movq 0x18(%rax), %rcx
movq %rbp, 0x10(%rcx)
subq 0x20(%rax), %rcx
movq %rcx, 0x10(%rbp)
movq %rdi, 0x18(%rax)
jmp 0x86c8
movq %rdi, %r14
movq $0x0, 0x10(%rbp)
movl $0x40, %edi
callq 0x2200
movq %rax, 0x8(%rbp)
testq %rax, %rax
je 0x895f
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movq %r14, 0x18(%rax)
movabsq $0x500000020, %rax      # imm = 0x500000020
movq %rax, 0x8(%r13)
movq $0x8, 0x20(%r13)
movl $0x200, %edi            # imm = 0x200
callq 0x2200
movq %rax, (%r13)
testq %rax, %rax
je 0x895f
movl $0x200, %edx            # imm = 0x200
movq %rax, %rdi
xorl %esi, %esi
callq 0x2120
movl $0xa0111fe1, 0x38(%r13) # imm = 0xA0111FE1
movq %rbp, %r13
movq %r14, %rdi
movq 0x8(%r13), %r14
incl 0x10(%r14)
movq %r14, 0x8(%rbp)
movl $0xfeedbef7, %eax       # imm = 0xFEEDBEF7
movl %eax, 0x3c(%rbp)
movzbl 0x17(%r15), %eax
shll $0x18, %eax
movsbl 0x16(%r15), %ecx
shll $0x10, %ecx
addl %eax, %ecx
movsbl 0x15(%r15), %eax
shll $0x8, %eax
addl %ecx, %eax
movsbl 0x14(%r15), %ecx
addl %ecx, %eax
addl $0x9e3779b9, %eax       # imm = 0x9E3779B9
movzbl 0x13(%r15), %ecx
shll $0x18, %ecx
movsbl 0x12(%r15), %edx
shll $0x10, %edx
movsbl 0x11(%r15), %esi
shll $0x8, %esi
addl %edx, %esi
movsbl 0x10(%r15), %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(%rbp)
movq 0x8(%r13), %rax
movl 0x8(%rax), %ecx
decl %ecx
andl %esi, %ecx
movq (%rax), %rax
shlq $0x4, %rcx
incl 0x8(%rax,%rcx)
movq (%rax,%rcx), %rdx
movq %rdx, 0x28(%rbp)
movq $0x0, 0x20(%rbp)
testq %rdx, %rdx
je 0x87c5
movq %rdi, 0x18(%rdx)
addq %rcx, %rax
movq %rdi, (%rax)
movl 0xc(%rax), %ecx
leal (%rcx,%rcx,4), %ecx
leal 0xa(,%rcx,2), %ecx
cmpl %ecx, 0x8(%rax)
movq 0x57f6(%rip), %rbp      # 0xdfd8
jb 0x87eb
cmpl $0x1, 0x34(%r14)
jne 0x8814
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x58ef
movq (%rbp), %rsi
movq %rbx, %rdi
callq 0x5bc7
testl %eax, %eax
jne 0x8504
jmp 0x84d7
movq %rdi, 0x10(%rsp)
movl 0x8(%r14), %r15d
addl %r15d, %r15d
shlq $0x4, %r15
movq %r15, %rdi
callq 0x2200
testq %rax, %rax
je 0x895f
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2120
movl 0x10(%r14), %esi
movb 0xc(%r14), %cl
incb %cl
movl 0x8(%r14), %edi
leal -0x1(,%rdi,2), %r8d
movl %r8d, %eax
andl %esi, %eax
shrl %cl, %esi
cmpl $0x1, %eax
sbbl $-0x1, %esi
movl %esi, 0x28(%r14)
movl $0x0, 0x2c(%r14)
testq %rdi, %rdi
je 0x88e7
movq (%r14), %rcx
xorl %r9d, %r9d
movq %r9, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %r10
testq %r10, %r10
je 0x88df
movq 0x20(%r10), %r11
movl 0x34(%r10), %edx
andl %r8d, %edx
shlq $0x4, %rdx
leaq (%rdx,%rbp), %r15
movl 0x8(%rbp,%rdx), %eax
incl %eax
movl %eax, 0x8(%rbp,%rdx)
cmpl %esi, %eax
jbe 0x88bc
incl 0x2c(%r14)
xorl %edx, %edx
divl %esi
movl %eax, 0xc(%r15)
movq $0x0, 0x18(%r10)
movq (%r15), %rax
movq %rax, 0x20(%r10)
testq %rax, %rax
je 0x88d4
movq %r10, 0x18(%rax)
movq %r10, (%r15)
movq %r11, %r10
testq %r11, %r11
jne 0x888f
incq %r9
cmpq %rdi, %r9
jne 0x887f
movq (%r14), %rdi
callq 0x2030
movq 0x10(%rsp), %rax
movq (%rax), %rax
shll 0x8(%rax)
incl 0xc(%rax)
movq %rbp, (%rax)
movl 0x10(%rax), %edx
shrl %edx
xorl %ecx, %ecx
cmpl %edx, 0x2c(%rax)
jbe 0x8911
movl 0x30(%rax), %ecx
incl %ecx
movl %ecx, 0x30(%rax)
cmpl $0x2, %ecx
movq 0x8(%rsp), %r14
movq 0x56b5(%rip), %rbp      # 0xdfd8
jb 0x87f0
movl $0x1, 0x34(%rax)
jmp 0x87f0
movq 0x56bc(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x10(%rbx), %rdx
movsd 0x18(%rbx), %xmm0
movq 0x20(%rbx), %rcx
leaq 0x169b(%rip), %rsi      # 0x9fee
movb $0x1, %al
callq 0x21a0
jmp 0x8510
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2280
callq 0x8423
nop