// File: /workspace/github_c_makefile_star2_O0/esheldon[P]xshear/src/sconfig.c
// Function: sconfig_read
ShearConfig* sconfig_read(const char* url) {

    wlog("Reading config from %s\n", url);

    enum cfg_status status=0, ostatus=0;
    struct cfg *cfg=cfg_read(url, &status);
    if (status) {
        fprintf(stderr,"Config Error: %s\n", cfg_status_string(status));
        exit(1);
    }

    ShearConfig* c=calloc(1, sizeof(ShearConfig));
    char key[CONFIG_KEYSZ];

    // set defaults for optional
    c->healpix_nside=HEALPIX_NSIDE_DEFAULT;

    c->min_zlens_interp=0;
    c->pairlog_rmax=0;
    c->pairlog_rmin=0;

    // this strcpy business is so we can print error messages
    // below
    c->H0 = cfg_get_double(cfg,strcpy(key,"H0"),&status);
    if (status) goto _sconfig_read_bail;

    c->omega_m = cfg_get_double(cfg,strcpy(key,"omega_m"),&status);
    if (status) goto _sconfig_read_bail;

    c->nbin = (int64) cfg_get_long(cfg,strcpy(key,"nbin"),&status);
    if (status) goto _sconfig_read_bail;

    c->rmin = cfg_get_double(cfg,strcpy(key,"rmin"),&status);
    if (status) goto _sconfig_read_bail;

    c->rmax = cfg_get_double(cfg,strcpy(key,"rmax"),&status);
    if (status) goto _sconfig_read_bail;

    // strings.  Error checking interior to functions
    c->mask_style = get_mask_style(cfg);

    c->shear_style = get_shear_style(cfg);

    c->scstyle = get_scstyle(cfg);

    c->Dlens_input = get_Dlens_input(cfg);

    c->sourceid_style = get_sourceid_style(cfg);

    c->r_units = get_r_units(cfg);
    
    c->shear_units = get_shear_units(cfg);

    c->weight_style = get_weight_style(cfg);

    if (c->Dlens_input && c->scstyle != SIGMACRIT_STYLE_INTERP) {
        fprintf(stderr,"Error: If the lens distance in input \n");
        fprintf(stderr,"       (Dlens_input set in config) the \n");
        fprintf(stderr,"       sigma crit style must be interpolated\n");
        exit(1);
    }
    if (c->scstyle == SIGMACRIT_STYLE_INTERP) {
        c->zl = dvector_new();

        c->zl->data=cfg_get_dblarr(cfg, strcpy(key,"zlvals"), &c->zl->size, &status);
        if (status) goto _sconfig_read_bail;

        c->nzl = (int64) c->zl->size;

    }

    // optional
    double mzl = cfg_get_double(cfg, "min_zlens_interp", &ostatus);
    if (!ostatus) {
        c->min_zlens_interp=mzl;
    }

    double dz = cfg_get_double(cfg, "zdiff_min", &ostatus);
    if (!ostatus) {
        c->zdiff_min=dz;
    }

    int nside = (int64) cfg_get_long(cfg,strcpy(key,"healpix_nside"),&ostatus);
    if (!ostatus) {
        c->healpix_nside = nside;
    }
    
    int pairlog_rmax = (int64) cfg_get_long(cfg,strcpy(key,"pairlog_rmax"),&ostatus);
    if (!ostatus) {
        c->pairlog_rmax = pairlog_rmax; 
    }
    int pairlog_rmin = (int64) cfg_get_long(cfg,strcpy(key,"pairlog_rmin"),&ostatus);
    if (!ostatus) {
        c->pairlog_rmin = pairlog_rmin; 
    }


    c->log_rmin = log10(c->rmin);
    c->log_rmax = log10(c->rmax);
    c->log_binsize = (c->log_rmax - c->log_rmin)/c->nbin;

_sconfig_read_bail:
    if (status) {
        fprintf(stderr,"Config Error for key '%s': %s\n", key,cfg_status_string(status));
        exit(1);
    }

    cfg=cfg_free(cfg);
    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq 0xb372(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x797a(%rip), %rsi      # 0xe60e
movb $0x0, %al
callq 0x2170
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x8140
movq %rax, -0x18(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x6cfb
movq 0xb331(%rip), %rax      # 0x11ff8
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movl -0xc(%rbp), %edi
callq 0x7dc0
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x793c(%rip), %rsi      # 0xe626
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movl $0x1, %edi
movl $0xa0, %esi
callq 0x2140
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x40, 0x10(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x90(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x78e1(%rip), %rsi      # 0xe638
callq 0x2060
movq -0x90(%rbp), %rdi
movq %rax, %rsi
leaq -0xc(%rbp), %rdx
callq 0x8540
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
cmpl $0x0, -0xc(%rbp)
je 0x6d82
jmp 0x718a
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x78a3(%rip), %rsi      # 0xe63b
callq 0x2060
movq -0x98(%rbp), %rdi
movq %rax, %rsi
leaq -0xc(%rbp), %rdx
callq 0x8540
movq -0x20(%rbp), %rax
movsd %xmm0, 0x8(%rax)
cmpl $0x0, -0xc(%rbp)
je 0x6dc4
jmp 0x718a
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x7869(%rip), %rsi      # 0xe643
callq 0x2060
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
leaq -0xc(%rbp), %rdx
callq 0x8910
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x40(%rax)
cmpl $0x0, -0xc(%rbp)
je 0x6e08
jmp 0x718a
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x78ed(%rip), %rsi      # 0xe70b
callq 0x2060
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
leaq -0xc(%rbp), %rdx
callq 0x8540
movq -0x20(%rbp), %rax
movsd %xmm0, 0x68(%rax)
cmpl $0x0, -0xc(%rbp)
je 0x6e4a
jmp 0x718a
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x789e(%rip), %rsi      # 0xe6fe
callq 0x2060
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
leaq -0xc(%rbp), %rdx
callq 0x8540
movq -0x20(%rbp), %rax
movsd %xmm0, 0x70(%rax)
cmpl $0x0, -0xc(%rbp)
je 0x6e8c
jmp 0x718a
movq -0x18(%rbp), %rdi
callq 0x7200
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x18(%rbp), %rdi
callq 0x7310
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rdi
callq 0x7400
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rdi
callq 0x7510
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x18(%rbp), %rdi
callq 0x7580
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rdi
callq 0x7650
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x18(%rbp), %rdi
callq 0x7730
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x18(%rbp), %rdi
callq 0x7840
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x6f82
movq -0x20(%rbp), %rax
cmpl $0x2, 0x20(%rax)
je 0x6f82
movq 0xb0c1(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x7707(%rip), %rsi      # 0xe648
movb $0x0, %al
callq 0x2170
movq 0xb0a9(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x7716(%rip), %rsi      # 0xe66f
movb $0x0, %al
callq 0x2170
movq 0xb091(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x7727(%rip), %rsi      # 0xe698
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movq -0x20(%rbp), %rax
cmpl $0x2, 0x20(%rax)
jne 0x7001
movb $0x0, %al
callq 0xaaa0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x7712(%rip), %rsi      # 0xe6c6
callq 0x2060
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdx
leaq -0xc(%rbp), %rcx
callq 0x8720
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x10(%rax)
cmpl $0x0, -0xc(%rbp)
je 0x6fee
jmp 0x718a
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rdi
leaq 0x76c1(%rip), %rsi      # 0xe6cd
leaq -0x10(%rbp), %rdx
callq 0x8540
movsd %xmm0, -0x68(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x7031
movsd -0x68(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x90(%rax)
movq -0x18(%rbp), %rdi
leaq 0x76a2(%rip), %rsi      # 0xe6de
leaq -0x10(%rbp), %rdx
callq 0x8540
movsd %xmm0, -0x70(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x7061
movsd -0x70(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x98(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x7671(%rip), %rsi      # 0xe6e8
callq 0x2060
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
leaq -0x10(%rbp), %rdx
callq 0x8910
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x70a4
movslq -0x74(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x763c(%rip), %rsi      # 0xe6f6
callq 0x2060
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
leaq -0x10(%rbp), %rdx
callq 0x8910
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x70e7
movslq -0x78(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x7606(%rip), %rsi      # 0xe703
callq 0x2060
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
leaq -0x10(%rbp), %rdx
callq 0x8910
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x712a
movslq -0x7c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x20(%rbp), %rax
movsd 0x68(%rax), %xmm0
callq 0x2160
movq -0x20(%rbp), %rax
movsd %xmm0, 0x78(%rax)
movq -0x20(%rbp), %rax
movsd 0x70(%rax), %xmm0
callq 0x2160
movq -0x20(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x20(%rbp), %rax
movsd 0x80(%rax), %xmm0
movq -0x20(%rbp), %rax
subsd 0x78(%rax), %xmm0
movq -0x20(%rbp), %rax
cvtsi2sdq 0x40(%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x88(%rax)
cmpl $0x0, -0xc(%rbp)
je 0x71dd
movq 0xae61(%rip), %rax      # 0x11ff8
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl -0xc(%rbp), %edi
callq 0x7dc0
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rdx
movq %rax, %rcx
leaq 0x7544(%rip), %rsi      # 0xe710
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movq -0x18(%rbp), %rdi
callq 0x7e00
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)