#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*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, float);
int /*<<< orphan*/ yap_sysquit(char *, char *, ...);
void write_fmat(char *dfile, int N, int C, float **f) {
  int i, j;
  FILE *fp = fopen(dfile, "w");
  if (!fp)
    yap_sysquit("Cannot open file '%s' for write\n", dfile);
  for (i = 0; i < N; i++) {
    for (j = 0; j < C; j++) {
      if (!fprintf(fp, "%d %d %g\n", i, j, f[i][j])) {
        yap_sysquit("Cannot write to '%s' position %d,\n", dfile, i, j);
      }
    }
  }
  if (ferror(fp))
    yap_sysquit("Error on writing file '%s' ", dfile);
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_fmat>:
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    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <write_fmat+0x47>
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1070 <yap_sysquit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122f <write_fmat+0xdf>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    121c <write_fmat+0xcc>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rsi
mov    (%rax,%rsi,8),%rax
movslq -0x20(%rbp),%rsi
movss  (%rax,%rsi,4),%xmm0
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x0,%eax
jne    1209 <write_fmat+0xb9>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1070 <yap_sysquit@plt>
jmp    120e <write_fmat+0xbe>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b1 <write_fmat+0x61>
jmp    1221 <write_fmat+0xd1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119e <write_fmat+0x4e>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1254 <write_fmat+0x104>
mov    -0x8(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1070 <yap_sysquit@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_fmat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,0x4(%rsp)
mov    %esi,%ebp
lea    0xe92(%rip),%rsi
mov    %rdi,0x8(%rsp)
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1189 <write_fmat+0x39>
test   %ebp,%ebp
jg     11a4 <write_fmat+0x54>
jmp    1223 <write_fmat+0xd3>
lea    0xe72(%rip),%rdi
mov    0x8(%rsp),%rsi
xor    %eax,%eax
call   1070 <yap_sysquit@plt>
test   %ebp,%ebp
jle    1223 <write_fmat+0xd3>
mov    %ebp,%eax
mov    %rax,0x10(%rsp)
mov    0x4(%rsp),%r14d
lea    0xe6c(%rip),%rbp
xor    %r12d,%r12d
jmp    11cb <write_fmat+0x7b>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    0x10(%rsp),%r12
je     1223 <write_fmat+0xd3>
cmpl   $0x0,0x4(%rsp)
jle    11c0 <write_fmat+0x70>
xor    %r13d,%r13d
jmp    11e9 <write_fmat+0x99>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,%r14
je     11c0 <write_fmat+0x70>
mov    (%rbx,%r12,8),%rax
movss  (%rax,%r13,4),%xmm0
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1050 <fprintf@plt>
test   %eax,%eax
jne    11e0 <write_fmat+0x90>
lea    0xe1e(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1070 <yap_sysquit@plt>
jmp    11e0 <write_fmat+0x90>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1243 <write_fmat+0xf3>
lea    0xe19(%rip),%rdi
mov    0x8(%rsp),%rsi
xor    %eax,%eax
call   1070 <yap_sysquit@plt>
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"Cannot open file '%s' for write\0A\00"
@.str.2 = [10 x i8] c"%d %d %g\0A\00"
@.str.3 = [35 x i8] c"Cannot write to '%s' position %d,\0A\00"
@.str.4 = [28 x i8] c"Error on writing file '%s' \00"
define void @write_fmat(i8* %0, i32 %1, i32 %2, float** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store float** %3, float*** %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** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %4
store i32 0, i32* %9
br label %20
20: ; preds = %54, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %57
24: ; preds = %20
store i32 0, i32* %10
br label %25
25: ; preds = %50, %24
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %53
29: ; preds = %25
%30 = load i32*, i32** %11
%31 = load i32, i32* %9
%32 = load i32, i32* %10
%33 = load float**, float*** %8
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds float*, float** %33, i64 %35
%37 = load float*, float** %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds float, float* %37, i64 %39
%41 = load float, float* %40
%42 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32, float %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %29
%45 = load i8*, i8** %5
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %45, i32 %46, i32 %47)
br label %49
49: ; preds = %44, %29
br label %50
50: ; preds = %49
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %25
53: ; preds = %25
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %20
57: ; preds = %20
%58 = load i32*, i32** %11
%59 = call i64 @ferror(i32* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i8*, i8** %5
%63 = call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %57
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"Cannot open file '%s' for write\0A\00"
@.str.2 = [10 x i8] c"%d %d %g\0A\00"
@.str.3 = [35 x i8] c"Cannot write to '%s' position %d,\0A\00"
@.str.4 = [28 x i8] c"Error on writing file '%s' \00"
define void @write_fmat(i8* %0, i32 %1, i32 %2, float** nocapture %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %4
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %36
11: ; preds = %9
%12 = icmp sgt i32 %2, 0
%13 = zext i32 %1 to i64
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %11, %33
%16 = phi i64 [ 0, %11 ], [ %34, %33 ]
br i1 %12, label %17, label %33
17: ; preds = %15
%18 = getelementptr inbounds float*, float** %3, i64 %16
%19 = trunc i64 %16 to i32
br label %20
20: ; preds = %17, %30
%21 = phi i64 [ 0, %17 ], [ %31, %30 ]
%22 = load float*, float** %18
%23 = getelementptr inbounds float, float* %22, i64 %21
%24 = load float, float* %23
%25 = trunc i64 %21 to i32
%26 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %25, float %24)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = tail call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %19, i32 %25)
br label %30
30: ; preds = %20, %28
%31 = add nuw nsw i64 %21, 1
%32 = icmp eq i64 %31, %14
br i1 %32, label %33, label %20
33: ; preds = %30, %15
%34 = add nuw nsw i64 %16, 1
%35 = icmp eq i64 %34, %13
br i1 %35, label %36, label %15
36: ; preds = %33, %9
%37 = tail call i64 @ferror(i32* %5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = tail call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %41
41: ; preds = %39, %36
%42 = tail call i32 @fclose(i32* %5)
ret void
}