#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*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void write_ascii_matrix(float *M, int ncol, int nrow, char *name) {
  FILE *f;
  int x, y, n;
  f = fopen(name, "w");
  if (f == NULL)
    error("Can't open output file.");
  for (y = 0; y < nrow; y++) {
    for (x = 0; x < ncol; x++, n++)
      fprintf(f, "%f ", M[y + x * nrow]);
    fprintf(f, "\n");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<write_ascii_matrix>:
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    -0x18(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1181 <write_ascii_matrix+0x41>
lea    0xe86(%rip),%rdi
call   1050 <error@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    120c <write_ascii_matrix+0xcc>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <write_ascii_matrix+0xac>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%edx
imul   -0x10(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe4c(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119b <write_ascii_matrix+0x5b>
mov    -0x20(%rbp),%rdi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1188 <write_ascii_matrix+0x48>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ascii_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %esi,0xc(%rsp)
mov    %rdi,0x10(%rsp)
lea    0xe90(%rip),%rsi
mov    %rcx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1189 <write_ascii_matrix+0x39>
test   %ebx,%ebx
jg     1199 <write_ascii_matrix+0x49>
jmp    1211 <write_ascii_matrix+0xc1>
lea    0xe72(%rip),%rdi
call   1060 <error@plt>
test   %ebx,%ebx
jle    1211 <write_ascii_matrix+0xc1>
mov    %ebx,%eax
mov    0xc(%rsp),%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,4),%r13
xor    %r14d,%r14d
lea    0xe5f(%rip),%rbx
jmp    11de <write_ascii_matrix+0x8e>
nopl   (%rax)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
addq   $0x4,0x10(%rsp)
cmp    0x20(%rsp),%r14
je     1211 <write_ascii_matrix+0xc1>
cmpl   $0x0,0xc(%rsp)
jle    11c0 <write_ascii_matrix+0x70>
mov    0x18(%rsp),%r12
mov    0x10(%rsp),%r15
nop
movss  (%r15),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    %r13,%r15
add    $0xffffffffffffffff,%r12
jne    11f0 <write_ascii_matrix+0xa0>
jmp    11c0 <write_ascii_matrix+0x70>
mov    %rbp,%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 = [24 x i8] c"Can't open output file.\00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @write_ascii_matrix(float* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store float* %0, float** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = load i8*, i8** %8
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %4
store i32 0, i32* %11
br label %20
20: ; preds = %50, %19
%21 = load i32, i32* %11
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %53
24: ; preds = %20
store i32 0, i32* %10
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %10
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %47
29: ; preds = %25
%30 = load i32*, i32** %9
%31 = load float*, float** %5
%32 = load i32, i32* %11
%33 = load i32, i32* %10
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = add nsw i32 %32, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %31, i64 %37
%39 = load float, float* %38
%40 = fpext float %39 to double
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %29
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
br label %25
47: ; preds = %25
%48 = load i32*, i32** %9
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %47
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %20
53: ; preds = %20
%54 = load i32*, i32** %9
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Can't open output file.\00"
@.str.2 = [4 x i8] c"%f \00"
define void @write_ascii_matrix(float* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32* @fopen(i8* %3, 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 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %32
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
%13 = zext i32 %2 to i64
%14 = zext i32 %2 to i64
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %11, %28
%17 = phi i64 [ 0, %11 ], [ %30, %28 ]
br i1 %12, label %18, label %28
18: ; preds = %16, %18
%19 = phi i64 [ %26, %18 ], [ 0, %16 ]
%20 = mul nsw i64 %19, %13
%21 = add nuw nsw i64 %20, %17
%22 = getelementptr inbounds float, float* %0, i64 %21
%23 = load float, float* %22
%24 = fpext float %23 to double
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %24)
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %28, label %18
28: ; preds = %18, %16
%29 = tail call i32 @fputc(i32 10, i32* %5)
%30 = add nuw nsw i64 %17, 1
%31 = icmp eq i64 %30, %14
br i1 %31, label %32, label %16
32: ; preds = %28, %9
%33 = tail call i32 @fclose(i32* %5)
ret void
}