#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 */
int /*<<< orphan*/ assert(unsigned int *);
double erf(unsigned int);
scalar_t__ malloc(int);
unsigned int *generate_gauss_LUT(unsigned char Nbits, unsigned char L) {
  unsigned int *LUT_ptr, i;
  LUT_ptr = (unsigned int *)malloc((1 << (Nbits - 1)) * sizeof(int));
  assert(LUT_ptr);
  for (i = 0; i < (1 << (Nbits - 1)); i++) {
    LUT_ptr[i] = (unsigned int)((double)((unsigned int)(1 << 31)) *
                                erf(i * L / (double)(1 << (Nbits - 1))));
  }
  return (LUT_ptr);
}


x86 assembly (clang, -O0):
<generate_gauss_LUT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movzbl -0x1(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0x1(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jae    11e9 <generate_gauss_LUT+0xb9>
mov    -0x14(%rbp),%eax
movzbl -0x2(%rbp),%ecx
imul   %ecx,%eax
cvtsi2sd %rax,%xmm0
mov    -0x1(%rbp),%cl
add    $0xff,%cl
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%edi
call   1050 <erf@plt>
movsd  0xe3a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <generate_gauss_LUT+0x43>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_gauss_LUT>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
lea    -0x1(%rdi),%ecx
mov    $0x1,%r15d
shl    %cl,%r15d
lea    0x0(,%r15,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <assert@plt>
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <erf@plt>
mulsd  0xe5e(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
add    %r14d,%ebp
cmp    %rbx,%r15
jne    1180 <generate_gauss_LUT+0x50>
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @generate_gauss_LUT(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32*
%6 = alloca i32
store i8 %0, i8* %3
store i8 %1, i8* %4
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
%9 = sub nsw i32 %8, 1
%10 = shl i32 1, %9
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = call i32 @assert(i32* %16)
store i32 0, i32* %6
br label %18
18: ; preds = %45, %2
%19 = load i32, i32* %6
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = sub nsw i32 %21, 1
%23 = shl i32 1, %22
%24 = icmp ult i32 %19, %23
br i1 %24, label %25, label %48
25: ; preds = %18
%26 = load i32, i32* %6
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = mul i32 %26, %28
%30 = uitofp i32 %29 to double
%31 = load i8, i8* %3
%32 = zext i8 %31 to i32
%33 = sub nsw i32 %32, 1
%34 = shl i32 1, %33
%35 = sitofp i32 %34 to double
%36 = fdiv double %30, %35
%37 = fptoui double %36 to i32
%38 = call double @erf(i32 %37)
%39 = fmul double 0x41E0000000000000, %38
%40 = fptoui double %39 to i32
%41 = load i32*, i32** %5
%42 = load i32, i32* %6
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
br label %45
45: ; preds = %25
%46 = load i32, i32* %6
%47 = add i32 %46, 1
store i32 %47, i32* %6
br label %18
48: ; preds = %18
%49 = load i32*, i32** %5
ret i32* %49
}

LLVM IR (-O2):
define i32* @generate_gauss_LUT(i8 zeroext %0, i8 zeroext %1) {
%3 = zext i8 %0 to i32
%4 = add nsw i32 %3, -1
%5 = shl nuw i32 1, %4
%6 = shl i32 %5, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = tail call i32 @assert(i32* %8)
%10 = zext i8 %1 to i32
%11 = sitofp i32 %5 to double
%12 = zext i32 %5 to i64
br label %13
13: ; preds = %2, %13
%14 = phi i64 [ 0, %2 ], [ %24, %13 ]
%15 = trunc i64 %14 to i32
%16 = mul i32 %15, %10
%17 = uitofp i32 %16 to double
%18 = fdiv double %17, %11
%19 = fptoui double %18 to i32
%20 = tail call double @erf(i32 %19)
%21 = fmul double %20, 0x41E0000000000000
%22 = fptoui double %21 to i32
%23 = getelementptr inbounds i32, i32* %8, i64 %14
store i32 %22, i32* %23
%24 = add nuw nsw i64 %14, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %26, label %13
26: ; preds = %13
ret i32* %8
}