// File: /workspace/github_c_makefile_star2_O1/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 0xb24d(%rip), %r13      # 0xdff8
movq (%r13), %rdi
leaq 0x6860(%rip), %rsi      # 0x9616
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 0x6846
movl (%r14), %edi
testl %edi, %edi
jne 0x313a
movq %rax, %rbx
pushq $0x1
popq %rdi
movl $0xa0, %esi
callq 0x2170
movq %rax, %r14
movq $0x40, 0x10(%rax)
andq $0x0, 0x90(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%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 0x6e3b
movsd %xmm0, (%r14)
cmpl $0x0, (%r15)
jne 0x3118
movabsq $0x6d5f6167656d6f, %rax # imm = 0x6D5F6167656D6F
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0x6e3b
movsd %xmm0, 0x8(%r14)
cmpl $0x0, (%r15)
jne 0x3118
leaq 0x20(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x6e69626e, (%rsi)     # imm = 0x6E69626E
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6ffb
movq %rax, 0x40(%r14)
cmpl $0x0, (%r12)
jne 0x3118
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 0x6e3b
movsd %xmm0, 0x68(%r14)
cmpl $0x0, (%r12)
jne 0x3118
leaq 0x20(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x78616d72, (%rsi)     # imm = 0x78616D72
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
movsd %xmm0, 0x10(%rsp)
callq 0x6e3b
movsd %xmm0, 0x70(%r14)
cmpl $0x0, (%r12)
jne 0x3118
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
callq 0x6104
movl %eax, 0x1c(%r14)
movq %rbx, %rdi
callq 0x619b
movl %eax, 0x18(%r14)
movq %rbx, %rdi
callq 0x6218
movl %eax, %ebp
movl %eax, 0x20(%r14)
movq %rbx, %rdi
callq 0x62af
movl %eax, %r12d
movl %eax, 0x2c(%r14)
movq %rbx, %rdi
callq 0x62e2
movl %eax, 0x24(%r14)
movq %rbx, %rdi
callq 0x635e
movl %eax, 0x48(%r14)
movq %rbx, %rdi
callq 0x63e1
movl %eax, 0x4c(%r14)
movq %rbx, %rdi
callq 0x647e
movl %eax, 0x28(%r14)
testl %r12d, %r12d
sete %al
cmpl $0x2, %ebp
sete %cl
orb %al, %cl
je 0x3183
cmpl $0x2, %ebp
jne 0x2fd4
xorl %eax, %eax
callq 0x7a37
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), %rbp
movq %rbx, %rdi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x6f36
movq %rax, 0x10(%r12)
cmpl $0x0, (%rbp)
jne 0x3118
movq (%r12), %rax
movq %rax, 0x30(%r14)
leaq 0x66f2(%rip), %rsi      # 0x96cd
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6e3b
cmpl $0x0, (%r12)
jne 0x2ffb
movsd %xmm0, 0x90(%r14)
leaq 0x66dc(%rip), %rsi      # 0x96de
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6e3b
cmpl $0x0, (%r12)
jne 0x3022
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 0x6ffb
cmpl $0x0, (%r12)
jne 0x305f
cltq
movq %rax, 0x10(%r14)
movabsq $0x78616d725f676f, %rax # imm = 0x78616D725F676F
leaq 0x20(%rsp), %rsi
movq %rax, 0x5(%rsi)
movabsq $0x5f676f6c72696170, %rbp # imm = 0x5F676F6C72696170
movq %rbp, (%rsi)
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6ffb
cmpl $0x0, (%r12)
jne 0x30a2
movq %r14, %rcx
addq $0x50, %rcx
cltq
movq %rax, (%rcx)
movabsq $0x6e696d725f676f, %rax # imm = 0x6E696D725F676F
leaq 0x20(%rsp), %rsi
movq %rax, 0x5(%rsi)
movq %rbp, (%rsi)
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x6ffb
cmpl $0x0, (%r12)
jne 0x30d5
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 0x3159
movq %rbx, %rdi
callq 0x65e2
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rbx
callq 0x65c9
leaq 0x64e4(%rip), %rsi      # 0x962e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x21a0
jmp 0x317b
movq (%r13), %rbx
callq 0x65c9
leaq 0x65a7(%rip), %rsi      # 0x9710
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x21a0
pushq $0x1
popq %rdi
callq 0x2280
movq (%r13), %rcx
leaq 0x64ba(%rip), %rdi      # 0x9648
pushq $0x26
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2290
movq (%r13), %rcx
leaq 0x64c8(%rip), %rdi      # 0x966f
pushq $0x28
popq %rsi
movq %rbx, %rdx
callq 0x2290
movq (%r13), %rcx
leaq 0x64db(%rip), %rdi      # 0x9698
pushq $0x2d
popq %rsi
movq %rbx, %rdx
callq 0x2290
jmp 0x317b