#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*/ approx(double *, double *, int, double *, double *, int, int,
                          int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
double *malloc(int);
void invertGamma(int n, double *gam, double *out) {
  double *x = malloc(sizeof(double) * (n));
  double *y = malloc(sizeof(double) * (n));
  int k;
  for (k = 0; k < n; k++)
    x[k] = (double)k / ((double)(n - 1));
  approx(gam, x, n, x, out, n, 1, 0, 1, 0);
  out[n] = 1;
  for (k = 0; k < n; k++)
    out[k] = out[k] / out[n];
  free(x);
  free(y);
  return;
}


x86 assembly (clang, -O0):
<invertGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11aa <invertGamma+0x7a>
cvtsi2sdl -0x2c(%rbp),%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1170 <invertGamma+0x40>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x4(%rbp),%r9d
xor    %eax,%eax
movl   $0x1,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x1,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1040 <approx@plt>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  0xe09(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1244 <invertGamma+0x114>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1203 <invertGamma+0xd3>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invertGamma>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %edi,%r13d
movslq %edi,%r14
lea    0x0(,%r14,8),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %r14d,%r14d
mov    %rax,(%rsp)
jle    1181 <invertGamma+0x51>
lea    -0x1(%r13),%eax
cvtsi2sd %eax,%xmm0
mov    %r13d,%ebp
cmp    $0x1,%r13d
jne    11b7 <invertGamma+0x87>
xor    %eax,%eax
jmp    1250 <invertGamma+0x120>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %rbx,%r8
mov    %r14d,%r9d
push   $0x0
push   $0x1
push   $0x0
push   $0x1
call   1040 <approx@plt>
add    $0x20,%rsp
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rbx,%r14,8)
jmp    131a <invertGamma+0x1ea>
mov    %ebp,%eax
and    $0xfffffffe,%eax
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rax),%rdx
mov    %rdx,%rcx
shr    %rcx
add    $0x1,%rcx
test   %rdx,%rdx
je     1339 <invertGamma+0x209>
mov    %rcx,%rsi
and    $0xfffffffffffffffe,%rsi
movdqa 0xe26(%rip),%xmm2
xor    %edx,%edx
movdqa 0xe2c(%rip),%xmm3
movdqa 0xe34(%rip),%xmm4
nopl   0x0(%rax)
cvtdq2pd %xmm2,%xmm5
divpd  %xmm1,%xmm5
movupd %xmm5,(%r15,%rdx,8)
movdqa %xmm2,%xmm5
paddd  %xmm3,%xmm5
cvtdq2pd %xmm5,%xmm5
divpd  %xmm1,%xmm5
movupd %xmm5,0x10(%r15,%rdx,8)
add    $0x4,%rdx
paddd  %xmm4,%xmm2
add    $0xfffffffffffffffe,%rsi
jne    1200 <invertGamma+0xd0>
cvtdq2pd %xmm2,%xmm2
test   $0x1,%cl
je     1246 <invertGamma+0x116>
divpd  %xmm1,%xmm2
movupd %xmm2,(%r15,%rdx,8)
cmp    %rbp,%rax
je     126a <invertGamma+0x13a>
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r15,%rax,8)
add    $0x1,%rax
cmp    %rax,%rbp
jne    1250 <invertGamma+0x120>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
mov    %r15,%rcx
mov    %rbx,%r8
mov    %r13d,%r9d
push   $0x0
push   $0x1
push   $0x0
push   $0x1
call   1040 <approx@plt>
add    $0x20,%rsp
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rbx,%r14,8)
test   %r13d,%r13d
jle    131a <invertGamma+0x1ea>
cmp    $0x1,%r13d
je     131a <invertGamma+0x1ea>
add    $0xffffffffffffffff,%rbp
mov    $0x1,%eax
cmp    $0x2,%r13d
je     1304 <invertGamma+0x1d4>
mov    %rbp,%rcx
and    $0xfffffffffffffffe,%rcx
neg    %rcx
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rbx,%rax,8),%xmm0
divsd  (%rbx,%r14,8),%xmm0
movsd  0x8(%rbx,%rax,8),%xmm1
movsd  %xmm0,(%rbx,%rax,8)
divsd  (%rbx,%r14,8),%xmm1
movsd  %xmm1,0x8(%rbx,%rax,8)
lea    (%rcx,%rax,1),%rdx
add    $0x2,%rdx
add    $0x2,%rax
cmp    $0x1,%rdx
jne    12d0 <invertGamma+0x1a0>
test   $0x1,%bpl
je     131a <invertGamma+0x1ea>
movsd  (%rbx,%rax,8),%xmm0
divsd  (%rbx,%r14,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
xorpd  %xmm2,%xmm2
movhpd 0xcbb(%rip),%xmm2
xor    %edx,%edx
test   $0x1,%cl
jne    123c <invertGamma+0x10c>
jmp    1246 <invertGamma+0x116>

LLVM IR (-O0):
define void @invertGamma(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call double* @malloc(i32 %13)
store double* %14, double** %7
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call double* @malloc(i32 %18)
store double* %19, double** %8
store i32 0, i32* %9
br label %20
20: ; preds = %35, %3
%21 = load i32, i32* %9
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i32, i32* %9
%26 = sitofp i32 %25 to double
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = sitofp i32 %28 to double
%30 = fdiv double %26, %29
%31 = load double*, double** %7
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
br label %35
35: ; preds = %24
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %20
38: ; preds = %20
%39 = load double*, double** %5
%40 = load double*, double** %7
%41 = load i32, i32* %4
%42 = load double*, double** %7
%43 = load double*, double** %6
%44 = load i32, i32* %4
%45 = call i32 @approx(double* %39, double* %40, i32 %41, double* %42, double* %43, i32 %44, i32 1, i32 0, i32 1, i32 0)
%46 = load double*, double** %6
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
store double 1.000000e+00, double* %49
store i32 0, i32* %9
br label %50
50: ; preds = %70, %38
%51 = load i32, i32* %9
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %73
54: ; preds = %50
%55 = load double*, double** %6
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double*, double** %6
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = fdiv double %59, %64
%66 = load double*, double** %6
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
store double %65, double* %69
br label %70
70: ; preds = %54
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
br label %50
73: ; preds = %50
%74 = load double*, double** %7
%75 = call i32 @free(double* %74)
%76 = load double*, double** %8
%77 = call i32 @free(double* %76)
ret void
}

LLVM IR (-O2):
define void @invertGamma(i32 %0, double* %1, double* %2) {
%4 = sext i32 %0 to i64
%5 = shl i32 %0, 3
%6 = tail call double* @malloc(i32 %5)
%7 = tail call double* @malloc(i32 %5)
%8 = icmp sgt i32 %0, 0
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = tail call i32 @approx(double* %1, double* %6, i32 %0, double* %6, double* %2, i32 %0, i32 1, i32 0, i32 1, i32 0)
%11 = getelementptr inbounds double, double* %2, i64 %4
store double 1.000000e+00, double* %11
br label %103
12: ; preds = %3
%13 = add nsw i32 %0, -1
%14 = sitofp i32 %13 to double
%15 = zext i32 %0 to i64
%16 = icmp eq i32 %0, 1
br i1 %16, label %58, label %17
17: ; preds = %12
%18 = and i64 %15, 4294967294
%19 = insertelement <2 x double> poison, double %14, i64 0
%20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
%21 = add nsw i64 %18, -2
%22 = lshr exact i64 %21, 1
%23 = add nuw i64 %22, 1
%24 = and i64 %23, 1
%25 = icmp eq i64 %21, 0
br i1 %25, label %48, label %26
26: ; preds = %17
%27 = and i64 %23, -2
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %42, %28 ]
%30 = phi <2 x i32> [ <i32 0, i32 1>, %26 ], [ %43, %28 ]
%31 = phi i64 [ 0, %26 ], [ %44, %28 ]
%32 = sitofp <2 x i32> %30 to <2 x double>
%33 = fdiv <2 x double> %32, %20
%34 = getelementptr inbounds double, double* %6, i64 %29
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> %33, <2 x double>* %35
%36 = or i64 %29, 2
%37 = add <2 x i32> %30, <i32 2, i32 2>
%38 = sitofp <2 x i32> %37 to <2 x double>
%39 = fdiv <2 x double> %38, %20
%40 = getelementptr inbounds double, double* %6, i64 %36
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> %39, <2 x double>* %41
%42 = add nuw i64 %29, 4
%43 = add <2 x i32> %30, <i32 4, i32 4>
%44 = add nuw i64 %31, 2
%45 = icmp eq i64 %44, %27
br i1 %45, label %46, label %28
46: ; preds = %28
%47 = sitofp <2 x i32> %43 to <2 x double>
br label %48
48: ; preds = %46, %17
%49 = phi i64 [ 0, %17 ], [ %42, %46 ]
%50 = phi <2 x double> [ <double 0.000000e+00, double 1.000000e+00>, %17 ], [ %47, %46 ]
%51 = icmp eq i64 %24, 0
br i1 %51, label %56, label %52
52: ; preds = %48
%53 = fdiv <2 x double> %50, %20
%54 = getelementptr inbounds double, double* %6, i64 %49
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %53, <2 x double>* %55
br label %56
56: ; preds = %48, %52
%57 = icmp eq i64 %18, %15
br i1 %57, label %68, label %58
58: ; preds = %12, %56
%59 = phi i64 [ 0, %12 ], [ %18, %56 ]
br label %60
60: ; preds = %58, %60
%61 = phi i64 [ %66, %60 ], [ %59, %58 ]
%62 = trunc i64 %61 to i32
%63 = sitofp i32 %62 to double
%64 = fdiv double %63, %14
%65 = getelementptr inbounds double, double* %6, i64 %61
store double %64, double* %65
%66 = add nuw nsw i64 %61, 1
%67 = icmp eq i64 %66, %15
br i1 %67, label %68, label %60
68: ; preds = %60, %56
%69 = tail call i32 @approx(double* %1, double* %6, i32 %0, double* %6, double* %2, i32 %0, i32 1, i32 0, i32 1, i32 0)
%70 = getelementptr inbounds double, double* %2, i64 %4
store double 1.000000e+00, double* %70
%71 = xor i1 %8, true
%72 = icmp eq i32 %0, 1
%73 = or i1 %71, %72
br i1 %73, label %103, label %74
74: ; preds = %68
%75 = add nsw i64 %15, -1
%76 = and i64 %75, 1
%77 = icmp eq i32 %0, 2
br i1 %77, label %95, label %78
78: ; preds = %74
%79 = and i64 %75, -2
br label %80
80: ; preds = %80, %78
%81 = phi i64 [ 1, %78 ], [ %92, %80 ]
%82 = phi i64 [ 0, %78 ], [ %93, %80 ]
%83 = load double, double* %70
%84 = getelementptr inbounds double, double* %2, i64 %81
%85 = load double, double* %84
%86 = fdiv double %85, %83
store double %86, double* %84
%87 = add nuw nsw i64 %81, 1
%88 = load double, double* %70
%89 = getelementptr inbounds double, double* %2, i64 %87
%90 = load double, double* %89
%91 = fdiv double %90, %88
store double %91, double* %89
%92 = add nuw nsw i64 %81, 2
%93 = add i64 %82, 2
%94 = icmp eq i64 %93, %79
br i1 %94, label %95, label %80
95: ; preds = %80, %74
%96 = phi i64 [ 1, %74 ], [ %92, %80 ]
%97 = icmp eq i64 %76, 0
br i1 %97, label %103, label %98
98: ; preds = %95
%99 = load double, double* %70
%100 = getelementptr inbounds double, double* %2, i64 %96
%101 = load double, double* %100
%102 = fdiv double %101, %99
store double %102, double* %100
br label %103
103: ; preds = %98, %95, %9, %68
%104 = tail call i32 @free(double* %6)
%105 = tail call i32 @free(double* %7)
ret void
}