// File: /workspace/github_c_makefile_star2_O0/esheldon[P]xshear/src/lens.c
// Function: lcat_read
LensCatalog* lcat_read(const ShearConfig* config, const char* lens_url) {

    int nread=0, expected=0;
    if (config->Dlens_input) {
        expected=6;
    } else {
        expected=5;
    }

    wlog("Reading lenses from %s\n", lens_url);
    FILE* stream=open_url(lens_url, "r");

    wlog("counting lines....");
    size_t nlens = count_lines_and_rewind(stream);

    wlog("%lu\n", nlens);

    wlog("    creating lcat...");

    LensCatalog* lcat=lcat_new(nlens);
    wlog("OK\n");

    wlog("    reading data...");
    double ra_rad,dec_rad;
    for (size_t i=0; i<nlens; i++) {

        Lens* lens = &lcat->data[i];

        if (config->Dlens_input) {
            nread=fscanf(stream,"%ld %lf %lf %lf %lf %ld",
                    &lens->index,&lens->ra,&lens->dec,&lens->z,&lens->da,&lens->maskflags);
        } else {
            nread=fscanf(stream,"%ld %lf %lf %lf %ld",
                    &lens->index,&lens->ra,&lens->dec,&lens->z,&lens->maskflags);
        }
        
        if (nread != expected) {
            wlog("Failed to read row %lu from %s\n", i, lens_url);
            wlog("nread=%d index=%d ra=%lf dec=%lf z=%lf maskflags=%d\n", nread, lens->index, lens->ra, lens->dec, lens->z, lens->maskflags);
            exit(EXIT_FAILURE);
        }

        ra_rad = lens->ra*D2R;
        dec_rad = lens->dec*D2R;

        lens->sinra = sin(ra_rad);
        lens->cosra = cos(ra_rad);
        lens->sindec = sin(dec_rad);
        lens->cosdec = cos(dec_rad);

        // add sin(lam),cos(lam),sin(eta),cos(eta)
        eq2sdss_sincos(lens->ra,lens->dec,
                       &lens->sinlam, &lens->coslam,
                       &lens->sineta, &lens->coseta);

    }
    fclose(stream);
    wlog("OK\n");

    return lcat;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x4c51
movl $0x6, -0x18(%rbp)
jmp 0x4c58
movl $0x5, -0x18(%rbp)
movq 0xd399(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x95c9(%rip), %rsi      # 0xe236
movb $0x0, %al
callq 0x2170
movq -0x10(%rbp), %rdi
leaq 0x9eed(%rip), %rsi      # 0xeb6c
callq 0xa0f0
movq %rax, -0x20(%rbp)
movq 0xd369(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x95b5(%rip), %rsi      # 0xe24e
movb $0x0, %al
callq 0x2170
movq -0x20(%rbp), %rdi
callq 0xa1b0
movq %rax, -0x28(%rbp)
movq 0xd344(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x977f(%rip), %rsi      # 0xe441
movb $0x0, %al
callq 0x2170
movq 0xd328(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x9587(%rip), %rsi      # 0xe261
movb $0x0, %al
callq 0x2170
movq -0x28(%rbp), %rdi
callq 0x4b40
movq %rax, -0x30(%rbp)
movq 0xd303(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x9577(%rip), %rsi      # 0xe276
movb $0x0, %al
callq 0x2170
movq 0xd2eb(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x9563(%rip), %rsi      # 0xe27a
movb $0x0, %al
callq 0x2170
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x4f15
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x4da1
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x50(%rbp), %rcx
addq $0x8, %rcx
movq -0x50(%rbp), %r8
addq $0x10, %r8
movq -0x50(%rbp), %r9
addq $0x18, %r9
movq -0x50(%rbp), %r10
addq $0x20, %r10
movq -0x50(%rbp), %rax
addq $0x48, %rax
leaq 0x9502(%rip), %rsi      # 0xe28e
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2070
movl %eax, -0x14(%rbp)
jmp 0x4dde
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x50(%rbp), %rcx
addq $0x8, %rcx
movq -0x50(%rbp), %r8
addq $0x10, %r8
movq -0x50(%rbp), %r9
addq $0x18, %r9
movq -0x50(%rbp), %rax
addq $0x48, %rax
leaq 0x94d6(%rip), %rsi      # 0xe2a6
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2070
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x4e55
movq 0xd20b(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x94bb(%rip), %rsi      # 0xe2ba
movb $0x0, %al
callq 0x2170
movq 0xd1eb(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x50(%rbp), %rax
movsd 0x18(%rax), %xmm2
movq -0x50(%rbp), %rax
movq 0x48(%rax), %r8
leaq 0x9496(%rip), %rsi      # 0xe2da
movb $0x3, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movq -0x50(%rbp), %rax
movsd 0x9247(%rip), %xmm0     # 0xe0a8
mulsd 0x8(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x50(%rbp), %rax
movsd 0x9231(%rip), %xmm0     # 0xe0a8
mulsd 0x10(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x2220
movq -0x50(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movsd -0x38(%rbp), %xmm0
callq 0x2120
movq -0x50(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movsd -0x40(%rbp), %xmm0
callq 0x2220
movq -0x50(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movsd -0x40(%rbp), %xmm0
callq 0x2120
movq -0x50(%rbp), %rax
movsd %xmm0, 0x40(%rax)
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
movq -0x50(%rbp), %rsi
addq $0x68, %rsi
movq -0x50(%rbp), %rdx
addq $0x70, %rdx
movq -0x50(%rbp), %rcx
addq $0x78, %rcx
callq 0xd250
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x4d26
movq -0x20(%rbp), %rdi
callq 0x20c0
movq 0xd0d3(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x9347(%rip), %rsi      # 0xe276
movb $0x0, %al
callq 0x2170
movq -0x30(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq