#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 write_paths_to_csv(char *fname, double **paths, int n_paths, int nt) {
  FILE *outfile;
  outfile = fopen(fname, "w");
  int i, j;
  if (outfile != NULL) {
    for (i = 0; i < n_paths; i++) {
      for (j = 0; j < nt; j++) {
        fprintf(outfile, "%f,", paths[i][j]);
      }
      fprintf(outfile, "\n");
    }
  }
  fclose(outfile);
  return 0;
}


x86 assembly (clang, -O0):
<write_paths_to_csv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e5 <write_paths_to_csv+0xb5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e0 <write_paths_to_csv+0xb0>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c0 <write_paths_to_csv+0x90>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe57(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117f <write_paths_to_csv+0x4f>
mov    -0x20(%rbp),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116c <write_paths_to_csv+0x3c>
jmp    11e5 <write_paths_to_csv+0xb5>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_paths_to_csv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %edx,%r15d
mov    %rsi,%r13
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11e3 <write_paths_to_csv+0xa3>
test   %r15d,%r15d
jle    11e3 <write_paths_to_csv+0xa3>
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%ebx
xor    %r14d,%r14d
lea    0xe7b(%rip),%r15
jmp    11a8 <write_paths_to_csv+0x68>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11e3 <write_paths_to_csv+0xa3>
cmpl   $0x0,0xc(%rsp)
jle    1190 <write_paths_to_csv+0x50>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%r14,8),%rax
movsd  (%rax,%r12,8),%xmm0
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    11c0 <write_paths_to_csv+0x80>
jmp    1190 <write_paths_to_csv+0x50>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%f,\00"
define i32 @write_paths_to_csv(i8* nocapture %0, double** nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i32* %5, null
%7 = icmp sgt i32 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %29
9: ; preds = %4
%10 = icmp sgt i32 %3, 0
%11 = zext i32 %2 to i64
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %9, %25
%14 = phi i64 [ 0, %9 ], [ %27, %25 ]
br i1 %10, label %15, label %25
15: ; preds = %13
%16 = getelementptr inbounds double*, double** %1, i64 %14
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %23, %17 ]
%19 = load double*, double** %16
%20 = getelementptr inbounds double, double* %19, i64 %18
%21 = load double, double* %20
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %25, label %17
25: ; preds = %17, %13
%26 = tail call i32 @fputc(i32 10, i32* %5)
%27 = add nuw nsw i64 %14, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %29, label %13
29: ; preds = %25, %4
%30 = tail call i32 @fclose(i32* %5)
ret i32 0
}