// File: /workspace/github_c_makefile_star2_O0/esheldon[P]xshear/src/lensum.c
// Function: lensums_new
Lensums* lensums_new(size_t nlens, size_t nbin, int shear_style, int scstyle, int shear_units) {

    wlog("Creating lensums:\n");
    wlog("    nlens: %lu  nbin: %lu\n", nlens, nbin);

    Lensums* self=calloc(1,sizeof(Lensums));
    if (self == NULL) {
        wlog("failed to allocate lensums struct\n");
        exit(EXIT_FAILURE);
    }

    self->data = calloc(nlens, sizeof(Lensum));
    if (self->data == NULL) {
        wlog("failed to allocate lensum array\n");
        exit(EXIT_FAILURE);
    }

    self->size = nlens;


    for (size_t i=0; i<nlens; i++) {
        Lensum* lensum = &self->data[i];

        lensum->shear_style=shear_style;
        lensum->scstyle=scstyle;
        lensum->shear_units=shear_units;

        lensum->index = -1;
        lensum->nbin  = nbin;
        lensum->npair = calloc(nbin, sizeof(int64));
        lensum->rsum  = calloc(nbin, sizeof(double));
        lensum->wsum  = calloc(nbin, sizeof(double));
        lensum->ssum  = calloc(nbin, sizeof(double));
        lensum->dsum  = calloc(nbin, sizeof(double));
        lensum->osum  = calloc(nbin, sizeof(double));

        lensum->dsensum_w  = calloc(nbin, sizeof(double));
        lensum->osensum_w  = calloc(nbin, sizeof(double));
        lensum->dsensum_s  = calloc(nbin, sizeof(double));
        lensum->osensum_s  = calloc(nbin, sizeof(double));

        if (lensum->npair==NULL
                || lensum->wsum==NULL
                || lensum->ssum==NULL
                || lensum->dsum==NULL
                || lensum->osum==NULL
                || lensum->rsum==NULL
                || lensum->dsensum_w==NULL
                || lensum->osensum_w==NULL
                || lensum->dsensum_s==NULL
                || lensum->osensum_s==NULL
                ) {

            wlog("failed to allocate lensum\n");
            exit(EXIT_FAILURE);
        }

    }
    return self;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq 0xcb17(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x8f2d(%rip), %rsi      # 0xe418
movb $0x0, %al
callq 0x2170
movq 0xcaff(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x8f20(%rip), %rsi      # 0xe42b
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
movl $0x10, %esi
callq 0x2140
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x554e
movq 0xcac5(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x8f09(%rip), %rsi      # 0xe446
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movq -0x8(%rbp), %rdi
movl $0x80, %esi
callq 0x2140
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x5594
movq 0xca7f(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x8ee6(%rip), %rsi      # 0xe469
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
movq -0x8(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x8(%rbp), %rax
jae 0x579e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl -0x18(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movq $-0x1, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x5769
movq -0x38(%rbp), %rax
cmpq $0x0, 0x78(%rax)
jne 0x578b
movq 0xc888(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x8d10(%rip), %rsi      # 0xe48a
movb $0x0, %al
callq 0x2170
movl $0x1, %edi
callq 0x2250
jmp 0x578d
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x55a7
movq -0x28(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)