#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 *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void write_embedding_to_file(double **X, int m, int n, char *filename,
                             double *bias_terms) {
  FILE *fp = fopen(filename, "w");
  int i;
  int j;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      fprintf(fp, "%f", X[i][j]);
      if (j != n - 1)
        fputc(' ', fp);
      else if (j == n - 1 && i != m - 1)
        fputc('\n', fp);
    }
  }
  if (bias_terms != 0) {
    fprintf(fp, "\n## bias terms after this line\n");
    for (i = 0; i < m; i++) {
      fprintf(fp, "%f", bias_terms[i]);
      if (i < m - 1)
        fputc('\n', fp);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_embedding_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123a <write_embedding_to_file+0xfa>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1227 <write_embedding_to_file+0xe7>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4e(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11df <write_embedding_to_file+0x9f>
mov    -0x28(%rbp),%rsi
mov    $0x20,%edi
call   1040 <fputc@plt>
jmp    1214 <write_embedding_to_file+0xd4>
mov    -0x30(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    120f <write_embedding_to_file+0xcf>
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     120f <write_embedding_to_file+0xcf>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
jmp    1214 <write_embedding_to_file+0xd4>
jmp    1219 <write_embedding_to_file+0xd9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1188 <write_embedding_to_file+0x48>
jmp    122c <write_embedding_to_file+0xec>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1175 <write_embedding_to_file+0x35>
cmpq   $0x0,-0x20(%rbp)
je     12c0 <write_embedding_to_file+0x180>
mov    -0x28(%rbp),%rdi
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12bb <write_embedding_to_file+0x17b>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd80(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12a8 <write_embedding_to_file+0x168>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
jmp    12ad <write_embedding_to_file+0x16d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    125e <write_embedding_to_file+0x11e>
jmp    12c0 <write_embedding_to_file+0x180>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_embedding_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe90(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r13
test   %ebp,%ebp
jle    1282 <write_embedding_to_file+0x132>
mov    %r14,0x18(%rsp)
lea    -0x1(%r15),%r14d
lea    -0x1(%rbp),%eax
mov    %rax,0x8(%rsp)
mov    %rbp,0x10(%rsp)
mov    %ebp,%eax
mov    %rax,(%rsp)
mov    %r15,0x20(%rsp)
mov    %r15d,%r12d
xor    %r15d,%r15d
jmp    11ba <write_embedding_to_file+0x6a>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    (%rsp),%r15
je     1219 <write_embedding_to_file+0xc9>
cmpl   $0x0,0x20(%rsp)
jle    11b0 <write_embedding_to_file+0x60>
xor    %ebp,%ebp
jmp    11f1 <write_embedding_to_file+0xa1>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %rbp,%r14
mov    $0xa,%edi
mov    $0x20,%eax
cmovne %eax,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     11b0 <write_embedding_to_file+0x60>
mov    (%rbx,%r15,8),%rax
movsd  (%rax,%rbp,8),%xmm0
mov    %r13,%rdi
lea    0xdfe(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
cmp    %rbp,%r14
jne    11d0 <write_embedding_to_file+0x80>
cmp    0x8(%rsp),%r15
je     11e8 <write_embedding_to_file+0x98>
jmp    11d0 <write_embedding_to_file+0x80>
mov    0x18(%rsp),%rbx
test   %rbx,%rbx
je     12a0 <write_embedding_to_file+0x150>
lea    0xddb(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
cmpl   $0x0,0x10(%rsp)
jle    12a0 <write_embedding_to_file+0x150>
xor    %ebp,%ebp
lea    0xdb6(%rip),%r14
jmp    125a <write_embedding_to_file+0x10a>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,(%rsp)
je     12a0 <write_embedding_to_file+0x150>
movsd  (%rbx,%rbp,8),%xmm0
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
cmp    0x8(%rsp),%rbp
jae    1250 <write_embedding_to_file+0x100>
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
jmp    1250 <write_embedding_to_file+0x100>
test   %r14,%r14
je     12a0 <write_embedding_to_file+0x150>
lea    0xd77(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
mov    %r13,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [32 x i8] c"\0A## bias terms after this line\0A\00"
define void @write_embedding_to_file(double** %0, i32 %1, i32 %2, i8* %3, double* %4) {
%6 = alloca double**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca double*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store double** %0, double*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store double* %4, double** %10
%14 = load i8*, i8** %9
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %11
store i32 0, i32* %12
br label %16
16: ; preds = %63, %5
%17 = load i32, i32* %12
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %66
20: ; preds = %16
store i32 0, i32* %13
br label %21
21: ; preds = %59, %20
%22 = load i32, i32* %13
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %62
25: ; preds = %21
%26 = load i32*, i32** %11
%27 = load double**, double*** %6
%28 = load i32, i32* %12
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double*, double** %27, i64 %29
%31 = load double*, double** %30
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = load i32, i32* %13
%38 = load i32, i32* %8
%39 = sub nsw i32 %38, 1
%40 = icmp ne i32 %37, %39
br i1 %40, label %41, label %44
41: ; preds = %25
%42 = load i32*, i32** %11
%43 = call i32 @fputc(i8 signext 32, i32* %42)
br label %58
44: ; preds = %25
%45 = load i32, i32* %13
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = icmp eq i32 %45, %47
br i1 %48, label %49, label %57
49: ; preds = %44
%50 = load i32, i32* %12
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, 1
%53 = icmp ne i32 %50, %52
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32*, i32** %11
%56 = call i32 @fputc(i8 signext 10, i32* %55)
br label %57
57: ; preds = %54, %49, %44
br label %58
58: ; preds = %57, %41
br label %59
59: ; preds = %58
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
br label %21
62: ; preds = %21
br label %63
63: ; preds = %62
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %16
66: ; preds = %16
%67 = load double*, double** %10
%68 = icmp ne double* %67, null
br i1 %68, label %69, label %96
69: ; preds = %66
%70 = load i32*, i32** %11
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %12
br label %72
72: ; preds = %92, %69
%73 = load i32, i32* %12
%74 = load i32, i32* %7
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %95
76: ; preds = %72
%77 = load i32*, i32** %11
%78 = load double*, double** %10
%79 = load i32, i32* %12
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
%82 = load double, double* %81
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %82)
%84 = load i32, i32* %12
%85 = load i32, i32* %7
%86 = sub nsw i32 %85, 1
%87 = icmp slt i32 %84, %86
br i1 %87, label %88, label %91
88: ; preds = %76
%89 = load i32*, i32** %11
%90 = call i32 @fputc(i8 signext 10, i32* %89)
br label %91
91: ; preds = %88, %76
br label %92
92: ; preds = %91
%93 = load i32, i32* %12
%94 = add nsw i32 %93, 1
store i32 %94, i32* %12
br label %72
95: ; preds = %72
br label %96
96: ; preds = %95, %66
%97 = load i32*, i32** %11
%98 = call i32 @fclose(i32* %97)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [32 x i8] c"\0A## bias terms after this line\0A\00"
define void @write_embedding_to_file(double** nocapture %0, i32 %1, i32 %2, i8* nocapture %3, double* %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = icmp sgt i32 %2, 0
%10 = add nsw i32 %2, -1
%11 = add nsw i32 %1, -1
%12 = zext i32 %10 to i64
%13 = zext i32 %11 to i64
%14 = zext i32 %1 to i64
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %8, %35
%17 = phi i64 [ 0, %8 ], [ %36, %35 ]
br i1 %9, label %18, label %35
18: ; preds = %16
%19 = getelementptr inbounds double*, double** %0, i64 %17
%20 = icmp ne i64 %17, %13
br label %21
21: ; preds = %18, %32
%22 = phi i64 [ 0, %18 ], [ %33, %32 ]
%23 = load double*, double** %19
%24 = getelementptr inbounds double, double* %23, i64 %22
%25 = load double, double* %24
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %25)
%27 = icmp ne i64 %22, %12
%28 = select i1 %27, i1 true, i1 %20
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = select i1 %27, i8 32, i8 10
%31 = tail call i32 @fputc(i8 signext %30, i32* %6)
br label %32
32: ; preds = %21, %29
%33 = add nuw nsw i64 %22, 1
%34 = icmp eq i64 %33, %15
br i1 %34, label %35, label %21
35: ; preds = %32, %16
%36 = add nuw nsw i64 %17, 1
%37 = icmp eq i64 %36, %14
br i1 %37, label %38, label %16
38: ; preds = %35
%39 = icmp eq double* %4, null
br i1 %39, label %61, label %44
40: ; preds = %5
%41 = icmp eq double* %4, null
br i1 %41, label %61, label %42
42: ; preds = %40
%43 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 31, i64 1, i32* %6)
br label %61
44: ; preds = %38
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 31, i64 1, i32* %6)
br i1 %7, label %46, label %61
46: ; preds = %44
%47 = add nsw i32 %1, -1
%48 = zext i32 %47 to i64
%49 = zext i32 %1 to i64
br label %50
50: ; preds = %46, %58
%51 = phi i64 [ 0, %46 ], [ %59, %58 ]
%52 = getelementptr inbounds double, double* %4, i64 %51
%53 = load double, double* %52
%54 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %53)
%55 = icmp ult i64 %51, %48
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = tail call i32 @fputc(i8 signext 10, i32* %6)
br label %58
58: ; preds = %50, %56
%59 = add nuw nsw i64 %51, 1
%60 = icmp eq i64 %59, %49
br i1 %60, label %61, label %50
61: ; preds = %58, %42, %40, %44, %38
%62 = tail call i32 @fclose(i32* %6)
ret void
}