#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
double gammln(float);
double log(float);
int /*<<< orphan*/ nrerror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int main(void) {
  char txt[80];
  int i, nval;
  float actual, calc, x;
  FILE *fp;
  if ((fp = fopen("fncval.dat", "r")) == NULL)
    nrerror("Data file fncval.dat not found\n");
  fgets(txt, 80, fp);
  while (strncmp(txt, "Gamma Function", 14)) {
    fgets(txt, 80, fp);
    if (feof(fp))
      nrerror("Data not found in fncval.dat\n");
  }
  fscanf(fp, "%d %*s", &nval);
  printf("\n%s\n", txt);
  printf("%10s %21s %21s\n", "x", "actual", "gammln(x)");
  for (i = 1; i <= nval; i++) {
    fscanf(fp, "%f %f", &x, &actual);
    if (x > 0.0) {
      calc = (x < 1.0 ? gammln(x + 1.0) - log(x) : gammln(x));
      printf("%12.2f %20.6f %20.6f\n", x, log(actual), calc);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4f(%rip),%rdi
lea    0xe53(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
jne    11df <main+0x3f>
lea    0xe3b(%rip),%rdi
call   1040 <nrerror@plt>
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x50,%esi
call   1080 <fgets@plt>
lea    -0x60(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0xe,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1246 <main+0xa6>
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x50,%esi
call   1080 <fgets@plt>
mov    -0x80(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     1241 <main+0xa1>
lea    0xe08(%rip),%rdi
call   1040 <nrerror@plt>
jmp    11f1 <main+0x51>
mov    -0x80(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    -0x68(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdf9(%rip),%rdi
lea    0xe02(%rip),%rsi
lea    0xdfd(%rip),%rdx
lea    0xdfd(%rip),%rcx
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jg     13ae <main+0x20e>
mov    -0x80(%rbp),%rdi
lea    0xde2(%rip),%rsi
lea    -0x74(%rbp),%rdx
lea    -0x6c(%rbp),%rcx
mov    $0x0,%al
call   1070 <fscanf@plt>
movss  -0x74(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    139b <main+0x1fb>
movss  -0x74(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd1b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    133b <main+0x19b>
movss  -0x74(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd00(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   10c0 <gammln@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movss  -0x74(%rbp),%xmm0
call   10a0 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
jmp    134d <main+0x1ad>
movss  -0x74(%rbp),%xmm0
call   10c0 <gammln@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x70(%rbp)
movss  -0x74(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movss  -0x6c(%rbp),%xmm0
call   10a0 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
movss  -0x70(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xd03(%rip),%rdi
mov    $0x3,%al
call   1060 <printf@plt>
jmp    13a0 <main+0x200>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1298 <main+0xf8>
mov    -0x80(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xe53(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11d5 <main+0x35>
lea    0xe45(%rip),%rdi
call   1040 <nrerror@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rbp,%rdx
call   1080 <fgets@plt>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
mov    $0xe,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     125c <main+0xbc>
lea    0x20(%rsp),%rbx
lea    0xe26(%rip),%r14
lea    0xe2e(%rip),%r15
jmp    1235 <main+0x95>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xe,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     125c <main+0xbc>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rbp,%rdx
call   1080 <fgets@plt>
mov    %rbp,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1220 <main+0x80>
mov    %r15,%rdi
call   1040 <nrerror@plt>
jmp    1220 <main+0x80>
lea    0xdff(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <fscanf@plt>
lea    0xdf0(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde2(%rip),%rdi
lea    0xdeb(%rip),%rsi
lea    0xde6(%rip),%rdx
lea    0xde6(%rip),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1383 <main+0x1e3>
lea    0xdd7(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x1c(%rsp),%r12
lea    0xdcc(%rip),%r13
xor    %ebx,%ebx
jmp    1323 <main+0x183>
nop
call   10c0 <gammln@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x18(%rsp)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movss  0x1c(%rsp),%xmm0
call   10a0 <log@plt>
movaps %xmm0,%xmm1
movss  0x18(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
mov    %r13,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x3,%al
call   1060 <printf@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jge    1383 <main+0x1e3>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <fscanf@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0xcc1(%rip),%xmm0
jbe    131a <main+0x17a>
movss  0xcb3(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    12d0 <main+0x130>
addss  %xmm1,%xmm0
call   10c0 <gammln@plt>
movsd  %xmm0,0x10(%rsp)
movss  0x8(%rsp),%xmm0
call   10a0 <log@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    12d5 <main+0x135>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"fncval.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Data file fncval.dat not found\0A\00"
@.str.3 = [15 x i8] c"Gamma Function\00"
@.str.4 = [30 x i8] c"Data not found in fncval.dat\0A\00"
@.str.5 = [7 x i8] c"%d %*s\00"
@.str.6 = [5 x i8] c"\0A%s\0A\00"
@.str.7 = [16 x i8] c"%10s %21s %21s\0A\00"
@.str.8 = [2 x i8] c"x\00"
@.str.9 = [7 x i8] c"actual\00"
@.str.10 = [10 x i8] c"gammln(x)\00"
@.str.11 = [6 x i8] c"%f %f\00"
@.str.12 = [22 x i8] c"%12.2f %20.6f %20.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32*
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%15 = load i32*, i32** %8
%16 = call i32 @fgets(i8* %14, i32 80, i32* %15)
br label %17
17: ; preds = %30, %13
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 14)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%23 = load i32*, i32** %8
%24 = call i32 @fgets(i8* %22, i32 80, i32* %23)
%25 = load i32*, i32** %8
%26 = call i64 @feof(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @nrerror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
br label %17
31: ; preds = %17
%32 = load i32*, i32** %8
%33 = call i32 (i32*, i8*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %37
37: ; preds = %74, %31
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = icmp sle i32 %38, %39
br i1 %40, label %41, label %77
41: ; preds = %37
%42 = load i32*, i32** %8
%43 = call i32 (i32*, i8*, ...) @fscanf(i32* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), float* %7, float* %5)
%44 = load float, float* %7
%45 = fpext float %44 to double
%46 = fcmp ogt double %45, 0.000000e+00
br i1 %46, label %47, label %73
47: ; preds = %41
%48 = load float, float* %7
%49 = fpext float %48 to double
%50 = fcmp olt double %49, 1.000000e+00
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = load float, float* %7
%53 = fpext float %52 to double
%54 = fadd double %53, 1.000000e+00
%55 = fptrunc double %54 to float
%56 = call double @gammln(float %55)
%57 = load float, float* %7
%58 = call double @log(float %57)
%59 = fsub double %56, %58
br label %63
60: ; preds = %47
%61 = load float, float* %7
%62 = call double @gammln(float %61)
br label %63
63: ; preds = %60, %51
%64 = phi double [ %59, %51 ], [ %62, %60 ]
%65 = fptrunc double %64 to float
store float %65, float* %6
%66 = load float, float* %7
%67 = fpext float %66 to double
%68 = load float, float* %5
%69 = call double @log(float %68)
%70 = load float, float* %6
%71 = fpext float %70 to double
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), double %67, double %69, double %71)
br label %73
73: ; preds = %63, %41
br label %74
74: ; preds = %73
%75 = load i32, i32* %3
%76 = add nsw i32 %75, 1
store i32 %76, i32* %3
br label %37
77: ; preds = %37
%78 = load i32*, i32** %8
%79 = call i32 @fclose(i32* %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"fncval.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Data file fncval.dat not found\0A\00"
@.str.3 = [15 x i8] c"Gamma Function\00"
@.str.4 = [30 x i8] c"Data not found in fncval.dat\0A\00"
@.str.5 = [7 x i8] c"%d %*s\00"
@.str.6 = [5 x i8] c"\0A%s\0A\00"
@.str.7 = [16 x i8] c"%10s %21s %21s\0A\00"
@.str.8 = [2 x i8] c"x\00"
@.str.9 = [7 x i8] c"actual\00"
@.str.10 = [10 x i8] c"gammln(x)\00"
@.str.11 = [6 x i8] c"%f %f\00"
@.str.12 = [22 x i8] c"%12.2f %20.6f %20.6f\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = call i32 @fgets(i8* %5, i32 80, i32* %9)
%15 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13, %23
%18 = call i32 @fgets(i8* %5, i32 80, i32* %9)
%19 = call i64 @feof(i32* %9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @nrerror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 14)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %17
26: ; preds = %23, %13
%27 = call i32 (i32*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%30 = load i32, i32* %2
%31 = icmp slt i32 %30, 1
br i1 %31, label %60, label %32
32: ; preds = %26, %56
%33 = phi i32 [ %57, %56 ], [ 1, %26 ]
%34 = call i32 (i32*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), float* %4, float* %3)
%35 = load float, float* %4
%36 = fcmp ogt float %35, 0.000000e+00
br i1 %36, label %37, label %56
37: ; preds = %32
%38 = fcmp olt float %35, 1.000000e+00
br i1 %38, label %39, label %45
39: ; preds = %37
%40 = fadd float %35, 1.000000e+00
%41 = call double @gammln(float %40)
%42 = load float, float* %4
%43 = call double @log(float %42)
%44 = fsub double %41, %43
br label %47
45: ; preds = %37
%46 = call double @gammln(float %35)
br label %47
47: ; preds = %45, %39
%48 = phi double [ %44, %39 ], [ %46, %45 ]
%49 = fptrunc double %48 to float
%50 = load float, float* %4
%51 = fpext float %50 to double
%52 = load float, float* %3
%53 = call double @log(float %52)
%54 = fpext float %49 to double
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), double %51, double %53, double %54)
br label %56
56: ; preds = %32, %47
%57 = add nuw nsw i32 %33, 1
%58 = load i32, i32* %2
%59 = icmp slt i32 %33, %58
br i1 %59, label %32, label %60
60: ; preds = %56, %26
%61 = call i32 @fclose(i32* %9)
ret i32 0
}