// File: /workspace/github_c_makefile_star2_O2/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, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rsi, %r15
movq %rdi, %rbp
movq 0xa08c(%rip), %r14      # 0xdff8
movq (%r14), %rcx
leaq 0x54aa(%rip), %rdi      # 0x9420
pushq $0x12
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rdi
leaq 0x54a5(%rip), %rsi      # 0x9433
movq %rbp, %rdx
movq %r15, 0x18(%rsp)
movq %r15, %rcx
xorl %eax, %eax
callq 0x21a0
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x2170
testq %rax, %rax
je 0x41b4
movq %rax, %rbx
movl $0x80, %esi
movq %rbp, %rdi
callq 0x2170
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x41c2
movq %rax, %r13
movq %rbx, 0x10(%rsp)
movq %rbp, (%rbx)
incq %rbp
addq $0x78, %r13
movq 0x18(%rsp), %r12
pushq $0x8
popq %r15
decq %rbp
je 0x41a0
movl 0x4(%rsp), %eax
movl %eax, -0x78(%r13)
movl 0x8(%rsp), %eax
movl %eax, -0x70(%r13)
movl 0xc(%rsp), %eax
movl %eax, -0x74(%r13)
orq $-0x1, -0x68(%r13)
movq %r12, -0x50(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, 0x48(%rsp)
movq %rax, -0x48(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, 0x40(%rsp)
movq %rax, -0x40(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, 0x30(%rsp)
movq %rax, -0x38(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, 0x38(%rsp)
movq %rax, -0x30(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, 0x28(%rsp)
movq %rax, -0x28(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rbp, 0x50(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, -0x20(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, %rbp
movq %rax, -0x18(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, %r14
movq %rax, -0x10(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, %rbx
movq %rax, -0x8(%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, (%r13)
movq %rbp, %xmm0
movq %r14, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq 0x40(%rsp), %xmm1
movq 0x30(%rsp), %xmm2
punpcklqdq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0]
movq 0x28(%rsp), %xmm2
movq 0x20(%rsp), %xmm3
movq 0x50(%rsp), %rbp
punpcklqdq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0]
movq 0x48(%rsp), %xmm3
movq 0x38(%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 0x417c
testq %rbx, %rbx
je 0x417c
subq $-0x80, %r13
testq %rax, %rax
jne 0x3fec
movq 0x9e75(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x5305(%rip), %rdi      # 0x9492
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
pushq $0x1
popq %rdi
callq 0x2280
movq 0x10(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rcx
leaq 0x5290(%rip), %rdi      # 0x944e
pushq $0x22
jmp 0x418f
movq 0x9e2f(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x529e(%rip), %rdi      # 0x9471
pushq $0x20
jmp 0x418f