#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_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
double fmod(double, double);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, double *, int);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file(void) {
  int i, nbVal;
  double tabR[20000], Val, Val1;
  char *F_name, *F_namei1, *F_namei;
  int fp, fpi1, fpi;
  F_name = "fmod_out.ref";
  F_namei = "fmod_inp.ref";
  F_namei1 = "1fmod_inp.ref";
  nbVal = 20000;
  fpi = open(F_namei, O_RDONLY, 0777);
  fpi1 = open(F_namei1, O_RDONLY, 0777);
  if (!fpi || !fpi1) {
    printf("error opening file");
    close(fpi);
    close(fpi1);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      read(fpi, &Val, sizeof(double));
      read(fpi1, &Val1, sizeof(double));
      tabR[i] = fmod(Val, Val1);
    }
    close(fpi);
    close(fpi1);
    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, &tabR[i], sizeof(double));
      }
      close(fp);
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<create_Result_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27150,%rsp
lea    0xe8e(%rip),%rax
mov    %rax,-0x27128(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x27138(%rbp)
lea    0xe7f(%rip),%rax
mov    %rax,-0x27130(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    -0x27138(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x27144(%rbp)
mov    -0x27130(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x27140(%rbp)
cmpl   $0x0,-0x27144(%rbp)
je     11f6 <create_Result_file+0x96>
cmpl   $0x0,-0x27140(%rbp)
jne    1224 <create_Result_file+0xc4>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x27144(%rbp),%edi
call   1060 <close@plt>
mov    -0x27140(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1362 <create_Result_file+0x202>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1295 <create_Result_file+0x135>
mov    -0x27144(%rbp),%edi
lea    -0x27118(%rbp),%rsi
mov    $0x8,%edx
call   1070 <read@plt>
mov    -0x27140(%rbp),%edi
lea    -0x27120(%rbp),%rsi
mov    $0x8,%edx
call   1070 <read@plt>
movsd  -0x27118(%rbp),%xmm0
ff
movsd  -0x27120(%rbp),%xmm1
ff
call   1050 <fmod@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    122b <create_Result_file+0xcb>
mov    -0x27144(%rbp),%edi
call   1060 <close@plt>
mov    -0x27140(%rbp),%edi
call   1060 <close@plt>
mov    -0x27128(%rbp),%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
mov    0x2d36(%rip),%rax
or     (%rax),%esi
mov    0x2d25(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x2713c(%rbp)
cmpl   $0x0,-0x2713c(%rbp)
jne    130d <create_Result_file+0x1ad>
lea    0xd2a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2713c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1362 <create_Result_file+0x202>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1350 <create_Result_file+0x1f0>
mov    -0x2713c(%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    1314 <create_Result_file+0x1b4>
mov    -0x2713c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x27150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x27110,%rsp
mov    0x2e5a(%rip),%rbx
mov    (%rbx),%esi
lea    0xe8f(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%r12d
mov    (%rbx),%esi
lea    0xe78(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%ebx
test   %r12d,%r12d
je     1273 <create_Result_file+0x113>
test   %ebx,%ebx
je     1273 <create_Result_file+0x113>
xor    %ebp,%ebp
lea    0x8(%rsp),%r14
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <read@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1070 <read@plt>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1050 <fmod@plt>
movsd  %xmm0,0x10(%rsp,%rbp,8)
add    $0x1,%rbp
cmp    $0x4e20,%rbp
jne    11c0 <create_Result_file+0x60>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2dc0(%rip),%rax
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
lea    0xdcd(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
test   %eax,%eax
je     128f <create_Result_file+0x12f>
mov    %eax,%ebx
xor    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    (%rsp,%rbp,1),%rsi
add    $0x10,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x8,%rbp
cmp    $0x27100,%rbp
jne    1250 <create_Result_file+0xf0>
jmp    12a3 <create_Result_file+0x143>
lea    0xda1(%rip),%rdi
call   1040 <printf@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r14d
jmp    12a3 <create_Result_file+0x143>
lea    0xd85(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
xor    %ebx,%ebx
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x27110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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