// File: /workspace/github_c_makefile_star2_O0/esheldon[P]xshear/src/shear.c
// Function: shear_init
Shear* shear_init(const char* config_url, const char* lens_url) {

    Shear* shear = calloc(1, sizeof(Shear));
    if (shear == NULL) {
        wlog("Failed to alloc shear struct\n");
        exit(EXIT_FAILURE);
    }

    shear->config=sconfig_read(config_url);

    ShearConfig* config=shear->config;
    wlog("config structure:\n");
    sconfig_print(config);

    // now initialize the structures we need
    wlog("Initalizing cosmo in flat universe\n");
    int flat=1;
    double omega_k=0;
    shear->cosmo = cosmo_new(config->H0, flat, 
                             config->omega_m, 
                             1-config->omega_m, 
                             omega_k);

    wlog("cosmo structure:\n");
    cosmo_print(shear->cosmo);

    wlog("Initalizing healpix at nside: %lld\n", config->healpix_nside);
    shear->hpix = hpix_new(config->healpix_nside);

    shear->lcat = lcat_read(config, lens_url);

    // order is important here
    if (!config->Dlens_input) {
        wlog("Adding Da to lenses\n");
        lcat_add_da(shear->lcat, shear->cosmo);
    } else {

    }

    wlog("Adding cos(search_angle) to lenses\n");
    lcat_add_search_angle(shear->lcat, config->rmax);

    wlog("Intersecting all lenses with healpix at rmax: %lf\n", config->rmax);
    lcat_disc_intersect(shear->lcat, shear->hpix, config->rmax);

    wlog("Building hpix tree for lenses\n");
    lcat_build_hpix_tree(shear->hpix, shear->lcat);

    lcat_print_firstlast(shear->lcat);

    // this holds the sums for each lens
    shear->lensums = lensums_new(shear->lcat->size,
                                 config->nbin,
                                 config->shear_style,
                                 config->scstyle,
                                 config->shear_units);

    for (size_t i=0; i<shear->lensums->size; i++) {
        shear->lensums->data[i].index = shear->lcat->data[i].index;
    }

    if (config->scstyle == SIGMACRIT_STYLE_INTERP) {
        // interpolation region
        double* zl=config->zl->data;
        int64 nzl=config->nzl;
        shear->max_zlens = zl[nzl-1];
        shear->min_zlens = fmax(zl[0], shear->config->min_zlens_interp);
    } else {
        shear->min_zlens = 0;
        shear->max_zlens = 9999;
    }

    wlog("min_zlens: %lf  max_zlens: %lf\n", shear->min_zlens, shear->max_zlens);


    return shear;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x2140
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xa47c
movq 0x9b97(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x5ad5(%rip), %rsi      # 0xff40
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movq -0x8(%rbp), %rdi
callq 0x2390
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq 0x9b57(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x5ab3(%rip), %rsi      # 0xff5e
movb $0x0, %al
callq 0x2170
movq -0x20(%rbp), %rdi
callq 0x3080
movq 0x9b36(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x5aa5(%rip), %rsi      # 0xff71
movb $0x0, %al
callq 0x2170
movl $0x1, -0x24(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movl -0x24(%rbp), %edi
movq -0x20(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x20(%rbp), %rax
movsd 0x53ce(%rip), %xmm2     # 0xf8d0
subsd 0x8(%rax), %xmm2
movsd -0x30(%rbp), %xmm3
callq 0x8390
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x9ad5(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x5a68(%rip), %rsi      # 0xff95
movb $0x0, %al
callq 0x2170
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x8880
movq 0x9ab0(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x5a4d(%rip), %rsi      # 0xffa7
movb $0x0, %al
callq 0x2170
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x8fd0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x7af0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0xa5ca
movq 0x9a56(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x5a1f(%rip), %rsi      # 0xffcb
movb $0x0, %al
callq 0x2170
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7e10
jmp 0xa5cc
jmp 0xa5cc
movq 0x9a25(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x5a03(%rip), %rsi      # 0xffe0
movb $0x0, %al
callq 0x2170
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movsd 0x70(%rax), %xmm0
callq 0x7e80
movq 0x99f7(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movsd 0x70(%rax), %xmm0
leaq 0x59f0(%rip), %rsi      # 0x10004
movb $0x1, %al
callq 0x2170
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rax
movsd 0x70(%rax), %xmm0
callq 0x7f00
movq 0x99b8(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x59ed(%rip), %rsi      # 0x10037
movb $0x0, %al
callq 0x2170
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x7fc0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x8280
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x20(%rbp), %rax
movl 0x18(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0x4c(%rax), %r8d
callq 0xb4e0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq (%rcx), %rax
jae 0xa708
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rdx
shlq $0x7, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa6b4
movq -0x20(%rbp), %rax
cmpl $0x2, 0x20(%rax)
jne 0xa788
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x40(%rbp), %rax
movsd (%rax), %xmm3
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsd 0x90(%rax), %xmm2
movaps %xmm2, %xmm4
movaps %xmm3, %xmm0
cmpunordsd %xmm0, %xmm0
movaps %xmm0, %xmm1
pand %xmm4, %xmm1
maxsd %xmm3, %xmm2
pandn %xmm2, %xmm0
por %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x28(%rax)
jmp 0xa7a5
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x28(%rax)
movq -0x18(%rbp), %rax
movsd 0x5778(%rip), %xmm0     # 0xff18
movsd %xmm0, 0x30(%rax)
movq 0x984c(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd 0x30(%rax), %xmm1
leaq 0x588e(%rip), %rsi      # 0x10056
movb $0x2, %al
callq 0x2170
movq -0x18(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)