// File: /workspace/github_c_makefile_star2_O3/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 0xb6ea(%rip), %r14      # 0xdff8
movq (%r14), %rcx
leaq 0x6b18(%rip), %rdi      # 0x9430
pushq $0x12
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rdi
leaq 0x6b13(%rip), %rsi      # 0x9443
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x21a0
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x2170
testq %rax, %rax
je 0x2b4e
movq %rax, %rbx
movl $0x80, %esi
movq %r12, %rdi
callq 0x2170
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2b5c
movq %rbx, 0x18(%rsp)
movq %r12, (%rbx)
testq %r12, %r12
je 0x2b16
movq %rax, %r13
addq $0x78, %r13
movq %r12, 0x20(%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 %r15, -0x50(%r13)
movq %r15, %rdi
pushq $0x8
popq %r12
movq %r12, %rsi
callq 0x2170
movq %rax, 0x50(%rsp)
movq %rax, -0x48(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, 0x48(%rsp)
movq %rax, -0x40(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, 0x38(%rsp)
movq %rax, -0x38(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, 0x40(%rsp)
movq %rax, -0x30(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, 0x30(%rsp)
movq %rax, -0x28(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, 0x28(%rsp)
movq %rax, -0x20(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, %rbp
movq %rax, -0x18(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, %r14
movq %rax, -0x10(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, %rbx
movq %rax, -0x8(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2170
movq %rax, (%r13)
movq %rbp, %xmm0
movq %r14, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq 0x48(%rsp), %xmm1
movq 0x38(%rsp), %xmm2
punpcklqdq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0]
movq 0x30(%rsp), %xmm2
movq 0x28(%rsp), %xmm3
punpcklqdq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0]
movq 0x50(%rsp), %xmm3
movq 0x40(%rsp), %xmm4
punpcklqdq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0]
pxor %xmm5, %xmm5
pcmpeqd %xmm5, %xmm3
pshufd $0xb1, %xmm3, %xmm4     # xmm4 = xmm3[1,0,3,2]
pand %xmm3, %xmm4
pcmpeqd %xmm5, %xmm2
pshufd $0xb1, %xmm2, %xmm3     # xmm3 = xmm2[1,0,3,2]
pand %xmm2, %xmm3
packssdw %xmm3, %xmm4
pcmpeqd %xmm5, %xmm1
pshufd $0xb1, %xmm1, %xmm2     # xmm2 = xmm1[1,0,3,2]
pand %xmm1, %xmm2
pcmpeqd %xmm5, %xmm0
pshufd $0xb1, %xmm0, %xmm1     # xmm1 = xmm0[1,0,3,2]
pand %xmm0, %xmm1
packssdw %xmm1, %xmm2
packssdw %xmm2, %xmm4
pmovmskb %xmm4, %ecx
testw $0xaaaa, %cx            # imm = 0xAAAA
jne 0x2b2a
testq %rbx, %rbx
je 0x2b2a
testq %rax, %rax
je 0x2b2a
subq $-0x80, %r13
movq 0x20(%rsp), %r12
decq %r12
jne 0x2986
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb4c7(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x6967(%rip), %rdi      # 0x94a2
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
pushq $0x1
popq %rdi
callq 0x2280
movq (%r14), %rcx
leaq 0x6906(%rip), %rdi      # 0x945e
pushq $0x22
jmp 0x2b3d
movq 0xb495(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x6914(%rip), %rdi      # 0x9481
pushq $0x20
jmp 0x2b3d