#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
double lgamma(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
double sqrt(int);
int /*<<< orphan*/ write(int, ...);
int create_Result_file(void) {
  int signgam = 0;
  int i, nbVal, tabSign[20000];
  double tabR[20000], Inc;
  char *F_name, *F_namesign;
  int fp, fpsi;
  F_name = "gamma_out.ref";
  F_namesign = "gamma_sign.ref";
  nbVal = 20000;
  Inc = sqrt(3);
  for (i = 0; i < nbVal; i++) {
    tabR[i] = lgamma(1 + Inc * i);
    tabSign[i] = signgam;
  }
  fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
  fpsi = open(F_namesign, O_RDWR | O_CREAT | O_TRUNC, 0777);
  if (!fp || !fpsi) {
    printf("error opening file");
    close(fp);
    close(fpsi);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      write(fp, &tabR[i], sizeof(double));
      write(fpsi, &tabSign[i], sizeof(int));
    }
    close(fp);
    close(fpsi);
    return 0;
  }
  return (0);
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3a9b0,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xe8f(%rip),%rax
mov    %rax,-0x3a9a0(%rbp)
lea    0xe8f(%rip),%rax
mov    %rax,-0x3a9a8(%rbp)
movl   $0x4e20,-0x10(%rbp)
mov    $0x3,%edi
call   1080 <sqrt@plt>
movsd  %xmm0,-0x3a998(%rbp)
ff
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1209 <create_Result_file+0xa9>
movsd  -0x3a998(%rbp),%xmm0
ff
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <lgamma@plt>
movslq -0xc(%rbp),%rax
movsd  %xmm0,-0x3a990(%rbp,%rax,8)
fc ff
mov    -0x8(%rbp),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x13890(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ae <create_Result_file+0x4e>
mov    -0x3a9a0(%rbp),%rdi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
mov    0x2dd8(%rip),%rax
or     (%rax),%esi
mov    0x2dc7(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x3a9ac(%rbp)
mov    -0x3a9a8(%rbp),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    0x2da6(%rip),%rax
or     (%rax),%esi
mov    0x2d95(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x3a9b0(%rbp)
cmpl   $0x0,-0x3a9ac(%rbp)
je     1287 <create_Result_file+0x127>
cmpl   $0x0,-0x3a9b0(%rbp)
jne    12b5 <create_Result_file+0x155>
lea    0xd97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3a9ac(%rbp),%edi
call   1050 <close@plt>
mov    -0x3a9b0(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133b <create_Result_file+0x1db>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    131e <create_Result_file+0x1be>
mov    -0x3a9ac(%rbp),%edi
movslq -0xc(%rbp),%rax
lea    -0x3a990(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x3a9b0(%rbp),%edi
movslq -0xc(%rbp),%rax
lea    -0x13890(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12bc <create_Result_file+0x15c>
mov    -0x3a9ac(%rbp),%edi
call   1050 <close@plt>
mov    -0x3a9b0(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3a9b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3a998,%rsp
mov    $0x3,%edi
call   1080 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
nop
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0xe6b(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <lgamma@plt>
movsd  %xmm0,0x13890(%rsp,%rbx,8)
movl   $0x0,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x4e20,%rbx
jne    1180 <create_Result_file+0x20>
mov    0x2e15(%rip),%r15
mov    0x2e2e(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    0x2e19(%rip),%rbx
or     (%rbx),%esi
lea    0xe28(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x0(%rbp),%esi
or     (%r15),%esi
or     (%rbx),%esi
lea    0xe1a(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,%r15d
test   %r14d,%r14d
je     126e <create_Result_file+0x10e>
test   %r15d,%r15d
je     126e <create_Result_file+0x10e>
lea    0x13890(%rsp),%rbx
xor    %ebp,%ebp
nopl   (%rax)
mov    $0x8,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    (%rsp,%rbp,1),%rsi
add    $0x10,%rsi
mov    $0x4,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <write@plt>
add    $0x4,%rbp
add    $0x8,%rbx
cmp    $0x13880,%rbp
jne    1220 <create_Result_file+0xc0>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    128f <create_Result_file+0x12f>
lea    0xdb0(%rip),%rdi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x3a998,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"gamma_out.ref\00"
@.str.1 = [15 x i8] c"gamma_sign.ref\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [19 x i8] c"error opening file\00"
define i32 @create_Result_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20000 x i32]
%6 = alloca [20000 x double]
%7 = alloca double
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %9
store i32 20000, i32* %4
%12 = call double @sqrt(i32 3)
store double %12, double* %7
store i32 0, i32* %3
br label %13
13: ; preds = %31, %0
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = load double, double* %7
%19 = load i32, i32* %3
%20 = sitofp i32 %19 to double
%21 = call double @llvm.fmuladd.f64(double %18, double %20, double 1.000000e+00)
%22 = fptosi double %21 to i32
%23 = call double @lgamma(i32 %22)
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [20000 x double], [20000 x double]* %6, i64 0, i64 %25
store double %23, double* %26
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20000 x i32], [20000 x i32]* %5, i64 0, i64 %29
store i32 %27, i32* %30
br label %31
31: ; preds = %17
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %13
34: ; preds = %13
%35 = load i8*, i8** %8
%36 = load i32, i32* @O_RDWR
%37 = load i32, i32* @O_CREAT
%38 = or i32 %36, %37
%39 = load i32, i32* @O_TRUNC
%40 = or i32 %38, %39
%41 = call i32 @open(i8* %35, i32 %40, i32 511)
store i32 %41, i32* %10
%42 = load i8*, i8** %9
%43 = load i32, i32* @O_RDWR
%44 = load i32, i32* @O_CREAT
%45 = or i32 %43, %44
%46 = load i32, i32* @O_TRUNC
%47 = or i32 %45, %46
%48 = call i32 @open(i8* %42, i32 %47, i32 511)
store i32 %48, i32* %11
%49 = load i32, i32* %10
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %34
%52 = load i32, i32* %11
%53 = icmp ne i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %51, %34
%55 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32, i32* %10
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %11
%59 = call i32 @close(i32 %58)
store i32 -1, i32* %1
br label %84
60: ; preds = %51
store i32 0, i32* %3
br label %61
61: ; preds = %76, %60
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %79
65: ; preds = %61
%66 = load i32, i32* %10
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [20000 x double], [20000 x double]* %6, i64 0, i64 %68
%70 = call i32 (i32, ...) @write(i32 %66, double* %69, i64 8)
%71 = load i32, i32* %11
%72 = load i32, i32* %3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [20000 x i32], [20000 x i32]* %5, i64 0, i64 %73
%75 = call i32 (i32, ...) @write(i32 %71, i32* %74, i64 4)
br label %76
76: ; preds = %65
%77 = load i32, i32* %3
%78 = add nsw i32 %77, 1
store i32 %78, i32* %3
br label %61
79: ; preds = %61
%80 = load i32, i32* %10
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* %11
%83 = call i32 @close(i32 %82)
store i32 0, i32* %1
br label %84
84: ; preds = %79, %54
%85 = load i32, i32* %1
ret i32 %85
}

LLVM IR (-O2):
@.str = [14 x i8] c"gamma_out.ref\00"
@.str.1 = [15 x i8] c"gamma_sign.ref\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [19 x i8] c"error opening file\00"
define i32 @create_Result_file() {
%1 = alloca [20000 x i32]
%2 = alloca [20000 x double]
%3 = bitcast [20000 x i32]* %1 to i8*
%4 = bitcast [20000 x double]* %2 to i8*
%5 = tail call double @sqrt(i32 3)
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %15, %6 ]
%8 = trunc i64 %7 to i32
%9 = sitofp i32 %8 to double
%10 = tail call double @llvm.fmuladd.f64(double %5, double %9, double 1.000000e+00)
%11 = fptosi double %10 to i32
%12 = tail call double @lgamma(i32 %11)
%13 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %7
store double %12, double* %13
%14 = getelementptr inbounds [20000 x i32], [20000 x i32]* %1, i64 0, i64 %7
store i32 0, i32* %14
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, 20000
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = load i32, i32* @O_RDWR
%19 = load i32, i32* @O_CREAT
%20 = or i32 %19, %18
%21 = load i32, i32* @O_TRUNC
%22 = or i32 %20, %21
%23 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %22, i32 511)
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_CREAT
%26 = or i32 %25, %24
%27 = load i32, i32* @O_TRUNC
%28 = or i32 %26, %27
%29 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 511)
%30 = icmp ne i32 %23, 0
%31 = icmp ne i32 %29, 0
%32 = and i1 %30, %31
br i1 %32, label %37, label %33
33: ; preds = %17
%34 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @close(i32 %23)
%36 = tail call i32 @close(i32 %29)
br label %48
37: ; preds = %17, %37
%38 = phi i64 [ %43, %37 ], [ 0, %17 ]
%39 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %38
%40 = call i32 (i32, ...) @write(i32 %23, double* %39, i64 8)
%41 = getelementptr inbounds [20000 x i32], [20000 x i32]* %1, i64 0, i64 %38
%42 = call i32 (i32, ...) @write(i32 %29, i32* %41, i64 4)
%43 = add nuw nsw i64 %38, 1
%44 = icmp eq i64 %43, 20000
br i1 %44, label %45, label %37
45: ; preds = %37
%46 = call i32 @close(i32 %23)
%47 = call i32 @close(i32 %29)
br label %48
48: ; preds = %45, %33
%49 = phi i32 [ 0, %45 ], [ -1, %33 ]
ret i32 %49
}