#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ ceil(int);
int log(int);
void calcLengths(unsigned *l, const double *p, const unsigned n) {
  unsigned i;
  for (i = 0; i < n; i++)
    l[i] = (unsigned)ceil(log(1.0 / p[i]) / log(2));
}


x86 assembly (clang, -O0):
<calcLengths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1199 <calcLengths+0x79>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsd  0xeab(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x2,%edi
call   1040 <log@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <calcLengths+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcLengths>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     117e <calcLengths+0x5e>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  0xeb8(%rip),%xmm0
divsd  (%r14,%rbx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1040 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <calcLengths+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @calcLengths(i32* %0, double* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %29, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %32
12: ; preds = %8
%13 = load double*, double** %5
%14 = load i32, i32* %7
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = fdiv double 1.000000e+00, %17
%19 = fptosi double %18 to i32
%20 = call i32 @log(i32 %19)
%21 = call i32 @log(i32 2)
%22 = sdiv i32 %20, %21
%23 = call i64 @ceil(i32 %22)
%24 = trunc i64 %23 to i32
%25 = load i32*, i32** %4
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %12
%30 = load i32, i32* %7
%31 = add i32 %30, 1
store i32 %31, i32* %7
br label %8
32: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @calcLengths(i32* nocapture writeonly %0, double* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %19, %7 ]
%9 = getelementptr inbounds double, double* %1, i64 %8
%10 = load double, double* %9
%11 = fdiv double 1.000000e+00, %10
%12 = fptosi double %11 to i32
%13 = tail call i32 @log(i32 %12)
%14 = tail call i32 @log(i32 2)
%15 = sdiv i32 %13, %14
%16 = tail call i64 @ceil(i32 %15)
%17 = trunc i64 %16 to i32
%18 = getelementptr inbounds i32, i32* %0, i64 %8
store i32 %17, i32* %18
%19 = add nuw nsw i64 %8, 1
%20 = icmp eq i64 %19, %6
br i1 %20, label %21, label %7
21: ; preds = %7, %3
ret void
}