#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 *, ...);
void fprint_confusion_matrix(int *confusion_matrix, int n, char *filename) {
  int i, j;
  int *p = confusion_matrix;
  FILE *fd = fopen(filename, "w");
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      fprintf(fd, "%d ", *p);
      p++;
    }
    fprintf(fd, "\n");
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<fprint_confusion_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d7 <fprint_confusion_matrix+0xa7>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b7 <fprint_confusion_matrix+0x87>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1179 <fprint_confusion_matrix+0x49>
mov    -0x30(%rbp),%rdi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <fprint_confusion_matrix+0x36>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_confusion_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xea8(%rip),%rsi
mov    %rdx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r13
test   %r14d,%r14d
jle    11be <fprint_confusion_matrix+0x7e>
lea    0xe93(%rip),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x4,%rbx
add    $0xffffffff,%ebp
jne    1190 <fprint_confusion_matrix+0x50>
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
add    $0x1,%r12d
cmp    %r14d,%r12d
jne    1180 <fprint_confusion_matrix+0x40>
mov    %r13,%rdi
add    $0x8,%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 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @fprint_confusion_matrix(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i32*, i32** %4
store i32* %11, i32** %9
%12 = load i8*, i8** %6
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %10
store i32 0, i32* %7
br label %14
14: ; preds = %36, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
store i32 0, i32* %8
br label %19
19: ; preds = %30, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32*, i32** %10
%25 = load i32*, i32** %9
%26 = load i32, i32* %25
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %9
%29 = getelementptr inbounds i32, i32* %28, i32 1
store i32* %29, i32** %9
br label %30
30: ; preds = %23
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %19
33: ; preds = %19
%34 = load i32*, i32** %10
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %33
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %14
39: ; preds = %14
%40 = load i32*, i32** %10
%41 = call i32 @fclose(i32* %40)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d \00"
define void @fprint_confusion_matrix(i32* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %21
6: ; preds = %3, %17
%7 = phi i32 [ %19, %17 ], [ 0, %3 ]
%8 = phi i32* [ %14, %17 ], [ %0, %3 ]
br label %9
9: ; preds = %6, %9
%10 = phi i32* [ %14, %9 ], [ %8, %6 ]
%11 = phi i32 [ %15, %9 ], [ 0, %6 ]
%12 = load i32, i32* %10
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds i32, i32* %10, i64 1
%15 = add nuw nsw i32 %11, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %9
17: ; preds = %9
%18 = tail call i32 @fputc(i32 10, i32* %4)
%19 = add nuw nsw i32 %7, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %6
21: ; preds = %17, %3
%22 = tail call i32 @fclose(i32* %4)
ret void
}