#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 ldexp(double, int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file() {
  int i, nbVal, tabInpi[20000];
  double tabR[20000], tabInpd[20000];
  char *F_name;
  char *F_namini;
  char *F_namind;
  int fp, fpi, fpd;
  F_name = "ldexp_out.ref";
  F_namini = "ildexp_inp.ref";
  F_namind = "ldexp_inp.ref";
  nbVal = 20000;
  fpi = open(F_namini, O_RDONLY, 0777);
  fpd = open(F_namind, O_RDONLY, 0777);
  if (!fpi || !fpd) {
    printf("error opening file");
    close(fpi);
    close(fpd);
    return -1;
  } else {
    for (i = 0; i < nbVal; i++) {
      read(fpi, &(tabInpi[i]), sizeof(int));
      read(fpd, &(tabInpd[i]), sizeof(double));
      tabR[i] = ldexp(tabInpd[i], tabInpi[i]);
    }
    close(fpi);
    close(fpd);
    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    $0x61ac0,%rsp
lea    0xe8e(%rip),%rax
mov    %rax,-0x61a98(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x61aa0(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x61aa8(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    -0x61aa0(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x61ab0(%rbp)
mov    -0x61aa8(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x61ab4(%rbp)
cmpl   $0x0,-0x61ab0(%rbp)
je     11f6 <create_Result_file+0x96>
cmpl   $0x0,-0x61ab4(%rbp)
jne    1224 <create_Result_file+0xc4>
lea    0xe20(%rip),%rdi
call   1050 <printf@plt>
mov    -0x61ab0(%rbp),%edi
call   1060 <close@plt>
mov    -0x61ab4(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <create_Result_file+0x224>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12b7 <create_Result_file+0x157>
mov    -0x61ab0(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x13890(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    -0x61ab4(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x61a90(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1070 <read@plt>
movslq -0x8(%rbp),%rax
movsd  -0x61a90(%rbp,%rax,8),%xmm0
f9 ff
movslq -0x8(%rbp),%rax
mov    -0x13890(%rbp,%rax,4),%edi
call   1030 <ldexp@plt>
movslq -0x8(%rbp),%rax
movsd  %xmm0,-0x3a990(%rbp,%rax,8)
fc ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    122b <create_Result_file+0xcb>
mov    -0x61ab0(%rbp),%edi
call   1060 <close@plt>
mov    -0x61ab4(%rbp),%edi
call   1060 <close@plt>
mov    -0x61a98(%rbp),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
mov    0x2d14(%rip),%rax
or     (%rax),%esi
mov    0x2d03(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x61aac(%rbp)
cmpl   $0x0,-0x61aac(%rbp)
jne    132f <create_Result_file+0x1cf>
lea    0xd0a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x61aac(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <create_Result_file+0x224>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1372 <create_Result_file+0x212>
mov    -0x61aac(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x3a990(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1336 <create_Result_file+0x1d6>
mov    -0x61aac(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x61ac0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_Result_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x61a88,%rsp
mov    0x2e5c(%rip),%rbx
mov    (%rbx),%esi
lea    0xe91(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
lea    0xe7c(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,%r15d
test   %r14d,%r14d
je     127f <create_Result_file+0x11f>
test   %r15d,%r15d
je     127f <create_Result_file+0x11f>
lea    0x4e200(%rsp),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    $0x4,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <read@plt>
lea    (%rsp,%rbp,1),%rsi
mov    $0x8,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1070 <read@plt>
movsd  (%rsp,%rbp,1),%xmm0
mov    (%rbx),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,0x27100(%rsp,%rbp,1)
add    $0x8,%rbp
add    $0x4,%rbx
cmp    $0x27100,%rbp
jne    11c0 <create_Result_file+0x60>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    0x2db6(%rip),%rax
mov    0x2dcf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dbc(%rip),%rax
or     (%rax),%esi
lea    0xdc3(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
test   %eax,%eax
je     1298 <create_Result_file+0x138>
mov    %eax,%ebx
xor    %ebp,%ebp
nop
lea    (%rsp,%rbp,1),%rsi
add    $0x27100,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1040 <write@plt>
add    $0x8,%rbp
cmp    $0x27100,%rbp
jne    1250 <create_Result_file+0xf0>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    12b0 <create_Result_file+0x150>
lea    0xd97(%rip),%rdi
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r15d,%edi
jmp    12a6 <create_Result_file+0x146>
lea    0xd7e(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <close@plt>
mov    $0xffffffff,%eax
add    $0x61a88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"ldexp_out.ref\00"
@.str.1 = [15 x i8] c"ildexp_inp.ref\00"
@.str.2 = [14 x i8] c"ldexp_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 i32]
%2 = alloca [20000 x double]
%3 = alloca [20000 x double]
%4 = bitcast [20000 x i32]* %1 to i8*
%5 = bitcast [20000 x double]* %2 to i8*
%6 = bitcast [20000 x double]* %3 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 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 %18, 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)
%17 = tail call i32 @close(i32 %10)
br label %51
18: ; preds = %0, %18
%19 = phi i64 [ %28, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds [20000 x i32], [20000 x i32]* %1, i64 0, i64 %19
%21 = call i32 (i32, ...) @read(i32 %8, i32* %20, i64 4)
%22 = getelementptr inbounds [20000 x double], [20000 x double]* %3, i64 0, i64 %19
%23 = call i32 (i32, ...) @read(i32 %10, double* %22, i64 8)
%24 = load double, double* %22
%25 = load i32, i32* %20
%26 = call double @ldexp(double %24, i32 %25)
%27 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %19
store double %26, double* %27
%28 = add nuw nsw i64 %19, 1
%29 = icmp eq i64 %28, 20000
br i1 %29, label %30, label %18
30: ; preds = %18
%31 = call i32 @close(i32 %8)
%32 = call i32 @close(i32 %10)
%33 = load i32, i32* @O_RDWR
%34 = load i32, i32* @O_CREAT
%35 = or i32 %34, %33
%36 = load i32, i32* @O_TRUNC
%37 = or i32 %35, %36
%38 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %37, i32 511)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %30
%41 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @close(i32 0)
br label %51
43: ; preds = %30, %43
%44 = phi i64 [ %47, %43 ], [ 0, %30 ]
%45 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %44
%46 = call i32 @write(i32 %38, double* %45, i32 8)
%47 = add nuw nsw i64 %44, 1
%48 = icmp eq i64 %47, 20000
br i1 %48, label %49, label %43
49: ; preds = %43
%50 = call i32 @close(i32 %38)
br label %51
51: ; preds = %49, %40, %14
%52 = phi i32 [ 0, %49 ], [ -1, %40 ], [ -1, %14 ]
ret i32 %52
}