// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movq 0xb1f3(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x6817(%rip), %rsi      # 0x9626
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21a0
leaq 0x8(%rsp), %r14
andl $0x0, (%r14)
andl $0x0, 0xc(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6969
movl (%r14), %edi
testl %edi, %edi
jne 0x31f7
movq %rax, %rbx
pushq $0x1
popq %rdi
movl $0xa0, %esi
callq 0x2170
movq %rax, %r14
movq $0x40, 0x10(%rax)
leaq 0x20(%rsp), %rsi
movb $0x0, 0x2(%rsi)
movw $0x3048, (%rsi)         # imm = 0x3048
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0x6f71
movsd %xmm0, (%r14)
movl (%r15), %edi
testl %edi, %edi
jne 0x31c7
movabsq $0x6d5f6167656d6f, %rax # imm = 0x6D5F6167656D6F
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0x6f71
movsd %xmm0, 0x8(%r14)
movl (%r15), %edi
testl %edi, %edi
jne 0x31c7
leaq 0x20(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x6e69626e, (%rsi)     # imm = 0x6E69626E
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x7113
movq %rax, 0x40(%r14)
movl (%r12), %edi
testl %edi, %edi
jne 0x31c7
movq %rax, %r15
leaq 0x20(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x6e696d72, (%rsi)     # imm = 0x6E696D72
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6f71
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x68(%r14)
movl (%r12), %edi
testl %edi, %edi
jne 0x31c7
leaq 0x20(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x78616d72, (%rsi)     # imm = 0x78616D72
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6f71
movsd %xmm0, 0x18(%rsp)
movsd %xmm0, 0x70(%r14)
movl (%r12), %edi
testl %edi, %edi
jne 0x31c7
movq %rbx, %rdi
callq 0x6230
movl %eax, 0x1c(%r14)
movq %rbx, %rdi
callq 0x62c7
movl %eax, 0x18(%r14)
movq %rbx, %rdi
callq 0x6344
movl %eax, %ebp
movl %eax, 0x20(%r14)
movq %rbx, %rdi
callq 0x63db
movl %eax, %r12d
movl %eax, 0x2c(%r14)
movq %rbx, %rdi
callq 0x640e
movl %eax, 0x24(%r14)
movq %rbx, %rdi
callq 0x648a
movl %eax, 0x48(%r14)
movq %rbx, %rdi
callq 0x650d
movl %eax, 0x4c(%r14)
movq %rbx, %rdi
callq 0x65aa
movl %eax, 0x28(%r14)
testl %r12d, %r12d
je 0x3016
cmpl $0x2, %ebp
je 0x301b
movq 0xb029(%rip), %r14      # 0xdff8
movq (%r14), %rcx
leaq 0x667f(%rip), %rdi      # 0x9658
pushq $0x26
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rcx
leaq 0x668e(%rip), %rdi      # 0x967f
pushq $0x28
popq %rsi
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rcx
leaq 0x66a2(%rip), %rdi      # 0x96a8
pushq $0x2d
popq %rsi
movq %rbx, %rdx
callq 0x2290
jmp 0x31ef
cmpl $0x2, %ebp
jne 0x3067
xorl %eax, %eax
callq 0x7b4b
movq %rax, %r12
movq %rax, 0x38(%r14)
leaq 0x20(%rsp), %rsi
movl $0x61766c7a, (%rsi)     # imm = 0x61766C7A
movl $0x736c61, 0x3(%rsi)    # imm = 0x736C61
leaq 0x8(%rsp), %r13
movq %rbx, %rdi
movq %rax, %rdx
movq %r13, %rcx
callq 0x7065
movq %rax, 0x10(%r12)
movl (%r13), %edi
testl %edi, %edi
jne 0x31c7
movq (%r12), %rax
movq %rax, 0x30(%r14)
leaq 0x666f(%rip), %rsi      # 0x96dd
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6f71
cmpl $0x0, (%r12)
jne 0x308e
movsd %xmm0, 0x90(%r14)
leaq 0x6659(%rip), %rsi      # 0x96ee
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6f71
cmpl $0x0, (%r12)
jne 0x30b5
movsd %xmm0, 0x98(%r14)
movabsq $0x656469736e5f78, %rax # imm = 0x656469736E5F78
leaq 0x20(%rsp), %rsi
movq %rax, 0x6(%rsi)
movabsq $0x5f7869706c616568, %rax # imm = 0x5F7869706C616568
movq %rax, (%rsi)
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x7113
cmpl $0x0, (%r12)
jne 0x30f2
cltq
movq %rax, 0x10(%r14)
movabsq $0x78616d725f676f, %rax # imm = 0x78616D725F676F
leaq 0x20(%rsp), %rsi
movq %rax, 0x5(%rsi)
movabsq $0x5f676f6c72696170, %r13 # imm = 0x5F676F6C72696170
movq %r13, (%rsi)
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x7113
cmpl $0x0, (%r12)
jne 0x312f
cltq
movq %rax, 0x50(%r14)
movabsq $0x6e696d725f676f, %rax # imm = 0x6E696D725F676F
leaq 0x20(%rsp), %rsi
movq %rax, 0x5(%rsi)
movq %r13, (%rsi)
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x7113
cmpl $0x0, (%r12)
jne 0x3162
cltq
movq %rax, 0x58(%r14)
movsd 0x10(%rsp), %xmm0
callq 0x2190
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x78(%r14)
movsd 0x18(%rsp), %xmm0
callq 0x2190
movsd %xmm0, 0x80(%r14)
subsd 0x10(%rsp), %xmm0
cvtsi2sd %r15, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x88(%r14)
movl 0x8(%rsp), %edi
testl %edi, %edi
jne 0x31c7
movq %rbx, %rdi
callq 0x670e
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xae2a(%rip), %rax      # 0xdff8
movq (%rax), %rbx
callq 0x66f5
leaq 0x6543(%rip), %rsi      # 0x9720
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x21a0
pushq $0x1
popq %rdi
callq 0x2280
movq 0xadfa(%rip), %rax      # 0xdff8
movq (%rax), %rbx
callq 0x66f5
leaq 0x6431(%rip), %rsi      # 0x963e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x21a0
jmp 0x31ef