// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movq 0xb6f5(%rip), %r14      # 0xdff8
movq (%r14), %rcx
leaq 0x6b13(%rip), %rdi      # 0x9420
pushq $0x12
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rdi
leaq 0x6b0e(%rip), %rsi      # 0x9433
movq %r12, %rdx
movq %r15, 0x20(%rsp)
movq %r15, %rcx
xorl %eax, %eax
callq 0x21a0
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x2170
testq %rax, %rax
je 0x2af4
movq %rax, %rbx
movl $0x80, %esi
movq %r12, %rdi
callq 0x2170
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2b02
movq %rbx, 0x18(%rsp)
movq %r12, (%rbx)
testq %r12, %r12
je 0x2abc
movq %rax, %r13
addq $0x78, %r13
movq %r12, 0x28(%rsp)
movl 0xc(%rsp), %eax
movl %eax, -0x78(%r13)
movl 0x10(%rsp), %eax
movl %eax, -0x70(%r13)
movl 0x14(%rsp), %eax
movl %eax, -0x74(%r13)
orq $-0x1, -0x68(%r13)
movq 0x20(%rsp), %r12
movq %r12, -0x50(%r13)
movq %r12, %rdi
pushq $0x8
popq %rbx
movq %rbx, %rsi
callq 0x2170
movq %rax, 0x50(%rsp)
movq %rax, -0x48(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, 0x40(%rsp)
movq %rax, -0x40(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, 0x48(%rsp)
movq %rax, -0x38(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, 0x38(%rsp)
movq %rax, -0x30(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, 0x30(%rsp)
movq %rax, -0x28(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %r15
movq %rax, -0x20(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rbp
movq %rax, -0x18(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %r14
movq %rax, -0x10(%r13)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rbx
movq %rax, -0x8(%r13)
movq %r12, %rdi
pushq $0x8
popq %rsi
callq 0x2170
movq %rax, (%r13)
cmpq $0x0, 0x40(%rsp)
je 0x2ad0
cmpq $0x0, 0x50(%rsp)
je 0x2ad0
cmpq $0x0, 0x48(%rsp)
je 0x2ad0
cmpq $0x0, 0x38(%rsp)
je 0x2ad0
cmpq $0x0, 0x30(%rsp)
je 0x2ad0
testq %r15, %r15
je 0x2ad0
testq %rbp, %rbp
je 0x2ad0
testq %r14, %r14
je 0x2ad0
testq %rbx, %rbx
je 0x2ad0
testq %rax, %rax
je 0x2ad0
subq $-0x80, %r13
movq 0x28(%rsp), %r12
decq %r12
jne 0x2980
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb521(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x69b1(%rip), %rdi      # 0x9492
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
pushq $0x1
popq %rdi
callq 0x2280
movq (%r14), %rcx
leaq 0x6950(%rip), %rdi      # 0x944e
pushq $0x22
jmp 0x2ae3
movq 0xb4ef(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x695e(%rip), %rdi      # 0x9471
pushq $0x20
jmp 0x2ae3