#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ printf(char *);
void export_weights(double *weights, double *bias,
                    double *test_features_average) {
  FILE *fp;
  fp = fopen("weights.txt", "w");
  if (fp != NULL) {
    int i;
    for (i = 0; i < 8; i++) {
      fprintf(fp, "%lf,", weights[i]);
    }
    fprintf(fp, "\n bias: %lf \n", bias[0]);
    for (i = 0; i < 8; i++) {
      fprintf(fp, "%lf,", test_features_average[i]);
    }
    fclose(fp);
  } else {
    printf(" File can't be opened !");
  }
}


x86 assembly (clang, -O0):
<export_weights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xea5(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1214 <export_weights+0xd4>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    11b2 <export_weights+0x72>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <export_weights+0x3d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    1206 <export_weights+0xc6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe1b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <export_weights+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1220 <export_weights+0xe0>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_weights>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xea7(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12ad <export_weights+0x16d>
mov    %rax,%rbx
movsd  0x0(%r13),%xmm0
lea    0xe90(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x8(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x10(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x18(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x20(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x28(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x30(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x38(%r13),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  (%r12),%xmm0
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fprintf@plt>
movsd  (%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x8(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x10(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x18(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x20(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x28(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x30(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movsd  0x38(%r14),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
lea    0xd6d(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"weights.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%lf,\00"
@.str.3 = [14 x i8] c"\0A bias: %lf \0A\00"
@.str.4 = [24 x i8] c" File can't be opened !\00"
define void @export_weights(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %50
12: ; preds = %3
store i32 0, i32* %8
br label %13
13: ; preds = %24, %12
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 8
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i32*, i32** %7
%18 = load double*, double** %4
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %22)
br label %24
24: ; preds = %16
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %13
27: ; preds = %13
%28 = load i32*, i32** %7
%29 = load double*, double** %5
%30 = getelementptr inbounds double, double* %29, i64 0
%31 = load double, double* %30
%32 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %31)
store i32 0, i32* %8
br label %33
33: ; preds = %44, %27
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 8
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = load i32*, i32** %7
%38 = load double*, double** %6
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %42)
br label %44
44: ; preds = %36
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %33
47: ; preds = %33
%48 = load i32*, i32** %7
%49 = call i32 @fclose(i32* %48)
br label %52
50: ; preds = %3
%51 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"weights.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%lf,\00"
@.str.3 = [14 x i8] c"\0A bias: %lf \0A\00"
@.str.4 = [24 x i8] c" File can't be opened !\00"
define void @export_weights(double* nocapture %0, double* nocapture %1, double* nocapture %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %56, label %6
6: ; preds = %3
%7 = load double, double* %0
%8 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %7)
%9 = getelementptr inbounds double, double* %0, i64 1
%10 = load double, double* %9
%11 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %10)
%12 = getelementptr inbounds double, double* %0, i64 2
%13 = load double, double* %12
%14 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %13)
%15 = getelementptr inbounds double, double* %0, i64 3
%16 = load double, double* %15
%17 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %16)
%18 = getelementptr inbounds double, double* %0, i64 4
%19 = load double, double* %18
%20 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = getelementptr inbounds double, double* %0, i64 5
%22 = load double, double* %21
%23 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = getelementptr inbounds double, double* %0, i64 6
%25 = load double, double* %24
%26 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %25)
%27 = getelementptr inbounds double, double* %0, i64 7
%28 = load double, double* %27
%29 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %28)
%30 = load double, double* %1
%31 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %30)
%32 = load double, double* %2
%33 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %32)
%34 = getelementptr inbounds double, double* %2, i64 1
%35 = load double, double* %34
%36 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %35)
%37 = getelementptr inbounds double, double* %2, i64 2
%38 = load double, double* %37
%39 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %38)
%40 = getelementptr inbounds double, double* %2, i64 3
%41 = load double, double* %40
%42 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %41)
%43 = getelementptr inbounds double, double* %2, i64 4
%44 = load double, double* %43
%45 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %44)
%46 = getelementptr inbounds double, double* %2, i64 5
%47 = load double, double* %46
%48 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %47)
%49 = getelementptr inbounds double, double* %2, i64 6
%50 = load double, double* %49
%51 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %50)
%52 = getelementptr inbounds double, double* %2, i64 7
%53 = load double, double* %52
%54 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %53)
%55 = tail call i32 @fclose(i32* %4)
br label %58
56: ; preds = %3
%57 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %56, %6
ret void
}