// File: /workspace/github_c_makefile_star2_O2/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 0x8a8a
movq %rsi, %r14
movl %edi, %ebp
movq 0x8(%rsi), %rdi
movq 0x10(%rsi), %rsi
callq 0x6b64
movq %rax, %rbx
movq (%rax), %rdi
movq 0x50(%rdi), %rax
cmpq 0x58(%rdi), %rax
jle 0x8886
cmpl $0x3, %ebp
je 0x8a8f
movq 0x18(%r14), %rsi
callq 0x2eb0
movq (%rbx), %rax
movq 0x60(%rax), %rcx
leaq 0x1be4(%rip), %rdi      # 0xa45c
pushq $0x21
popq %rsi
pushq $0x1
popq %rdx
callq 0x22a0
movq (%rbx), %rdi
callq 0x4d68
movq %rax, %r14
movq (%rbx), %rax
movq 0x38(%rax), %rax
movq %rax, 0x60(%r14)
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)
pushq $0x1
popq %r12
xorl %r15d, %r15d
movq %r12, %rax
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
divq %rcx
movq %rax, %rbp
movq 0x56fa(%rip), %rax      # 0xdfd8
movq (%rax), %rdi
movq %r14, %rsi
callq 0x4e29
testl %eax, %eax
je 0x89c8
movq %rbx, %r13
movl 0x8(%r14), %ecx
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rbx
cmpl $0x1, %ecx
je 0x8934
cmpl $0x3, %ecx
jne 0x8948
movq 0x8(%r13), %rdi
movq 0x10(%rsp), %rax
movsd (%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x5c9e
movq 0x8(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rbx
movq 0x8(%r13), %rdi
movsd (%rax), %xmm1
xorps %xmm0, %xmm0
callq 0x5c9e
movsd %xmm0, (%rbx)
testq %r15, %r15
movq %r13, %rbx
je 0x8979
cmpq $0x1, %r15
je 0x898e
imulq $0x2710, %rbp, %rax     # imm = 0x2710
decq %rax
cmpq %r15, %rax
jne 0x89b2
movq 0x568c(%rip), %rax      # 0xdff8
movq (%rax), %rsi
pushq $0x2e
popq %rdi
callq 0x2160
jmp 0x89b2
movq 0x5678(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x1af4(%rip), %rdi      # 0xa47e
pushq $0xe
jmp 0x89a1
movq 0x5663(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x1aee(%rip), %rdi      # 0xa48d
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x22a0
movq %r14, %rdi
callq 0x502e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6dd0
incq %r12
incq %r15
jmp 0x88c7
movq 0x5629(%rip), %r13      # 0xdff8
movq (%r13), %rcx
leaq 0x1ac3(%rip), %rdi      # 0xa49d
pushq $0xe
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
callq 0x22a0
movq %r14, %rdi
callq 0x502e
movq (%r13), %rdi
leaq 0x1ab0(%rip), %rsi      # 0xa4ac
movq %r15, %rdx
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0x7430
movq (%r13), %rcx
leaq 0x1aab(%rip), %rdi      # 0xa4c4
pushq $0x1a
popq %rsi
movq %r12, %rdx
callq 0x22a0
movq 0x20(%rbx), %rdi
movq 0x55a1(%rip), %rax      # 0xdfd0
movq (%rax), %rsi
callq 0x7747
movq (%rbx), %rax
movq 0x50(%rax), %rcx
cmpq 0x58(%rax), %rcx
jle 0x8a4d
movq 0x60(%rax), %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x4df3
movq %rbx, %rdi
callq 0x7463
movq 0x5594(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x1a71(%rip), %rdi      # 0xa4df
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x22a0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x87a0
movq 0x5562(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x19a5(%rip), %rdi      # 0xa445
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x22a0
callq 0x87a0