#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 cos(double);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file(void) {
  int i, nbVal;
  double tabRcos[20000], Inc;
  char *F_name;
  int fp;
  F_name = "rcos";
  nbVal = 20000;
  Inc = (2 * 3.1415926535897932384626433832795029L) / nbVal;
  for (i = 0; i < nbVal; i++)
    tabRcos[i] = cos(Inc * i);
  fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
  if (!fp) {
    printf("error opening file");
    close(fp);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      write(fp, &tabRcos[i], sizeof(double));
    }
    close(fp);
    return 0;
  }
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27130,%rsp
lea    0xeae(%rip),%rax
mov    %rax,-0x27120(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x27128(%rbp)
fildl  -0x27128(%rbp)
fldt   0xe7b(%rip)
fdivp  %st,%st(1)
fstpl  -0x27130(%rbp)
movsd  -0x27130(%rbp),%xmm0
ff
movsd  %xmm0,-0x27118(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e1 <create_Result_file+0x91>
movsd  -0x27118(%rbp),%xmm0
ff
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1060 <cos@plt>
movslq -0x8(%rbp),%rax
movsd  %xmm0,-0x27110(%rbp,%rax,8)
fd ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <create_Result_file+0x54>
mov    -0x27120(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    0x2e00(%rip),%rax
or     (%rax),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x27124(%rbp)
cmpl   $0x0,-0x27124(%rbp)
jne    1243 <create_Result_file+0xf3>
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
mov    -0x27124(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <create_Result_file+0x148>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1286 <create_Result_file+0x136>
mov    -0x27124(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x27110(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124a <create_Result_file+0xfa>
mov    -0x27124(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x27130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x27100,%rsp
xor    %ebx,%ebx
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe91(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1060 <cos@plt>
movsd  %xmm0,(%rsp,%rbx,8)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe71(%rip),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x8(%rsp,%rbx,8)
lea    0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe54(%rip),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x10(%rsp,%rbx,8)
lea    0x3(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe37(%rip),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x18(%rsp,%rbx,8)
add    $0x4,%rbx
cmp    $0x4e20,%rbx
jne    1160 <create_Result_file+0x10>
mov    0x2dec(%rip),%rax
mov    0x2e05(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df2(%rip),%rax
or     (%rax),%esi
lea    0xe01(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
test   %eax,%eax
je     123f <create_Result_file+0xef>
mov    %eax,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%rsp,%rbx,1),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x8,%rbx
cmp    $0x27100,%rbx
jne    1220 <create_Result_file+0xd0>
jmp    1253 <create_Result_file+0x103>
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
xor    %ebp,%ebp
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r14d,%eax
add    $0x27100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"rcos\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [19 x i8] c"error opening file\00"
define i32 @create_Result_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20000 x double]
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 20000, i32* %3
%8 = load i32, i32* %3
%9 = sitofp i32 %8 to x86_fp80
%10 = fdiv x86_fp80 0xK4001C90FDAA22168C235, %9
%11 = fptrunc x86_fp80 %10 to double
store double %11, double* %5
store i32 0, i32* %2
br label %12
12: ; preds = %25, %0
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load double, double* %5
%18 = load i32, i32* %2
%19 = sitofp i32 %18 to double
%20 = fmul double %17, %19
%21 = call double @cos(double %20)
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %23
store double %21, double* %24
br label %25
25: ; preds = %16
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %12
28: ; preds = %12
%29 = load i8*, i8** %6
%30 = load i32, i32* @O_RDWR
%31 = load i32, i32* @O_CREAT
%32 = or i32 %30, %31
%33 = load i32, i32* @O_TRUNC
%34 = or i32 %32, %33
%35 = call i32 @open(i8* %29, i32 %34, i32 511)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %28
%39 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
store i32 -1, i32* %1
br label %59
42: ; preds = %28
store i32 0, i32* %2
br label %43
43: ; preds = %53, %42
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i32, i32* %7
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [20000 x double], [20000 x double]* %4, i64 0, i64 %50
%52 = call i32 @write(i32 %48, double* %51, i32 8)
br label %53
53: ; preds = %47
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %43
56: ; preds = %43
%57 = load i32, i32* %7
%58 = call i32 @close(i32 %57)
store i32 0, i32* %1
br label %59
59: ; preds = %56, %38
%60 = load i32, i32* %1
ret i32 %60
}

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