// File: /workspace/github_c_makefile_star2_O3/esheldon[P]xshear/src/xshear.c
// Function: main
int main(int argc, char** argv) {
    int64 nsource=0;

    if (argc < 3) {
        usage_and_exit();
    }

    const char* config_url=argv[1];
    const char* lens_url=argv[2];
    Shear* shear=shear_init(config_url, lens_url);
    
    if(shear->config->pairlog_rmax>shear->config->pairlog_rmin) { // print pair ids to file
      if (argc < 4) {
	wlog("no pair logfile given\n");
        usage_and_exit();
      }
      sconfig_open_pair_url(shear->config,argv[3]);
      fprintf(shear->config->pair_fd, "# lens_id source_id r_bin weight\n");
    }

    Source* src=source_new(shear->config);
    src->zlens = (const dvector*) shear->config->zl;

    while (source_read(stdin, src)) {
        nsource++;

        if (src->scstyle == SIGMACRIT_STYLE_POINT) {
            src->dc = Dc(shear->cosmo, 0.0, src->z);
        } else if (src->scstyle == SIGMACRIT_STYLE_SAMPLE) {
            src->dc  = Dc(shear->cosmo, 0.0, src->z);
            src->dcs = Dc(shear->cosmo, 0.0, src->zs);
        }

        if (nsource == 1) {
            wlog("first source:\n");
            source_print(src);
        }
        if (nsource == 2) {
            wlog("second source:\n");
            source_print(src);
        }
        if ((nsource % 10000) == 0) {
            wlog(".");
        }


        shear_process_source(shear, src);
    }
    wlog("\nlast source:\n");
    source_print(src);

    wlog("processed %lld sources\n", nsource);

    // print some summary info
    shear_print_sum(shear);

    wlog("Writing results to stdout\n");
    lensums_write(shear->lensums, stdout);

    if(shear->config->pairlog_rmax>shear->config->pairlog_rmin) {
     fclose(shear->config->pair_fd);
    }
    
    src=source_free(src);
    shear=shear_free(shear);
    wlog("Done\n");

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, %edi
jle 0x958d
movq %rsi, %r14
movl %edi, %ebp
movq 0x8(%rsi), %rdi
movq 0x10(%rsi), %rsi
callq 0x7a80
movq %rax, %r13
movq (%rax), %rdi
movq 0x50(%rdi), %rax
cmpq 0x58(%rdi), %rax
jle 0x9388
cmpl $0x3, %ebp
je 0x9592
movq 0x18(%r14), %rsi
callq 0x4647
movq (%r13), %rax
movq 0x60(%rax), %rcx
leaq 0x20e7(%rip), %rdi      # 0xb45c
movl $0x21, %esi
movl $0x1, %edx
callq 0x22a0
movq (%r13), %rdi
callq 0x62f0
movq %rax, %r14
movq (%r13), %rax
movq 0x38(%rax), %rax
movq %rax, 0x60(%r14)
movq 0x6c35(%rip), %rax      # 0xffd8
movq (%rax), %rdi
movq %r14, %rsi
callq 0x6382
testl %eax, %eax
jne 0x947a
xorl %r15d, %r15d
movq 0x6c38(%rip), %rbx      # 0xfff8
movq (%rbx), %rcx
leaq 0x20d3(%rip), %rdi      # 0xb49d
movl $0xe, %esi
movl $0x1, %edx
callq 0x22a0
movq %r14, %rdi
callq 0x308a
movq (%rbx), %rdi
leaq 0x20c1(%rip), %rsi      # 0xb4ac
movq %r15, %rdx
xorl %eax, %eax
callq 0x21b0
movq %r13, %rdi
callq 0x385e
movq (%rbx), %rcx
leaq 0x20bd(%rip), %rdi      # 0xb4c4
movl $0x1a, %esi
movl $0x1, %edx
callq 0x22a0
movq 0x20(%r13), %rdi
movq 0x6baf(%rip), %rax      # 0xffd0
movq (%rax), %rsi
callq 0x8184
movq (%r13), %rax
movq 0x50(%rax), %rcx
cmpq 0x58(%rax), %rcx
jle 0x9440
movq 0x60(%rax), %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x634c
movq %r13, %rdi
callq 0x8131
movq (%rbx), %rcx
leaq 0x2085(%rip), %rdi      # 0xb4df
movl $0x5, %esi
movl $0x1, %edx
callq 0x22a0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x70(%r14), %rax
movq %rax, 0x8(%rsp)
leaq 0x78(%r14), %rax
movq %rax, 0x20(%rsp)
movq %r14, %rax
subq $-0x80, %rax
movq %rax, 0x18(%rsp)
movl $0x1, %r12d
xorl %r15d, %r15d
movq %r13, %rbp
movq %r12, %rax
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
mulq %rcx
movq %rdx, %r13
movl 0x8(%r14), %ecx
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rbx
cmpl $0x1, %ecx
je 0x9500
cmpl $0x3, %ecx
jne 0x9514
movq 0x8(%rbp), %rdi
movq 0x10(%rsp), %rax
movsd (%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x6b59
movq 0x8(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rbx
movq 0x8(%rbp), %rdi
movsd (%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x6b59
movsd %xmm0, (%rbx)
testq %r15, %r15
je 0x9579
cmpq $0x1, %r15
je 0x9583
shrq $0xb, %r13
imulq $0x2710, %r13, %rax     # imm = 0x2710
decq %rax
cmpq %r15, %rax
jne 0x9546
movq 0x6abf(%rip), %rax      # 0xfff8
movq (%rax), %rsi
movl $0x2e, %edi
callq 0x2160
movq %rbp, %r13
movq %rbp, %rdi
movq %r14, %rsi
callq 0x7abe
movq 0x6a7d(%rip), %rax      # 0xffd8
movq (%rax), %rdi
movq %r14, %rsi
callq 0x6382
incq %r12
incq %r15
testl %eax, %eax
jne 0x94aa
jmp 0x93b9
movq %r14, %rdi
callq 0x40e8
jmp 0x9546
movq %r14, %rdi
callq 0x40bf
jmp 0x9546
callq 0x928c
callq 0x4111
nop