#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);
int exp(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
double tanh(double);
int /*<<< orphan*/ write(int, double *, int);
int create_Result_file(void) {
  int i, nbVal;
  double tabR[20000], Inc;
  char *F_name;
  int fp;
  F_name = "rtanh";
  nbVal = 20000;
  Inc = exp(1) / 100;
  for (i = 0; i < nbVal; i++)
    tabR[i] = tanh(Inc * (i - nbVal / 2));
  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    $0x27130,%rsp
lea    0xe8e(%rip),%rax
mov    %rax,-0x27120(%rbp)
movl   $0x4e20,-0xc(%rbp)
mov    $0x1,%edi
call   1070 <exp@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x27118(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ff <create_Result_file+0x9f>
movsd  -0x27118(%rbp),%xmm0
ff
mov    -0x8(%rbp),%eax
mov    %eax,-0x27128(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x27128(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1040 <tanh@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    11a5 <create_Result_file+0x45>
mov    -0x27120(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    0x2de2(%rip),%rax
or     (%rax),%esi
mov    0x2dd1(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1080 <open@plt>
mov    %eax,-0x27124(%rbp)
cmpl   $0x0,-0x27124(%rbp)
jne    1261 <create_Result_file+0x101>
lea    0xdc1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x27124(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b6 <create_Result_file+0x156>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a4 <create_Result_file+0x144>
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    1268 <create_Result_file+0x108>
mov    -0x27124(%rbp),%edi
call   1060 <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    $0x27110,%rsp
mov    $0x1,%edi
call   1070 <exp@plt>
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    -0x2710(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
call   1040 <tanh@plt>
movsd  %xmm0,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x4e20,%rbx
jne    11a0 <create_Result_file+0x40>
mov    0x2e06(%rip),%rax
mov    0x2e1f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0c(%rip),%rax
or     (%rax),%esi
lea    0xe13(%rip),%rdi
mov    $0x1ff,%edx
call   1080 <open@plt>
test   %eax,%eax
je     1233 <create_Result_file+0xd3>
mov    %eax,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x8,%rbx
cmp    $0x27100,%rbx
jne    1210 <create_Result_file+0xb0>
jmp    1247 <create_Result_file+0xe7>
lea    0xdcc(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
xor    %ebp,%ebp
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x27110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"rtanh\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*
%3 = tail call i32 @exp(i32 1)
%4 = sdiv i32 %3, 100
%5 = sitofp i32 %4 to double
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %14, %6 ]
%8 = trunc i64 %7 to i32
%9 = add i32 %8, -10000
%10 = sitofp i32 %9 to double
%11 = fmul double %5, %10
%12 = tail call double @tanh(double %11)
%13 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %7
store double %12, double* %13
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, 20000
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21, i32 511)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %32
26: ; preds = %16, %26
%27 = phi i64 [ %30, %26 ], [ 0, %16 ]
%28 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %27
%29 = call i32 @write(i32 %22, double* %28, i32 8)
%30 = add nuw nsw i64 %27, 1
%31 = icmp eq i64 %30, 20000
br i1 %31, label %32, label %26
32: ; preds = %26, %24
%33 = phi i32 [ 0, %24 ], [ %22, %26 ]
%34 = phi i32 [ -1, %24 ], [ 0, %26 ]
%35 = tail call i32 @close(i32 %33)
ret i32 %34
}