#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*/ exit(int);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stderr;
void write_square_matrix(int **m, int n, const char *file) {
  FILE *fp;
  fp = fopen(file, "w");
  if (fp == NULL) {
    fprintf(stderr, "Error while writing the matrix.\n");
    exit(1);
  }
  fprintf(fp, "%d\n", n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      fprintf(fp, "%d ", m[i][j]);
    }
    fprintf(fp, "\n");
  }
}


x86 assembly (clang, -O0):
<write_square_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1184 <write_square_matrix+0x54>
mov    0x2e77(%rip),%rax
mov    (%rax),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1212 <write_square_matrix+0xe2>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f2 <write_square_matrix+0xc2>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b3 <write_square_matrix+0x83>
mov    -0x20(%rbp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a0 <write_square_matrix+0x70>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_square_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe99(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11f2 <write_square_matrix+0xa2>
mov    %rax,%r12
lea    0xea5(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebp,%ebp
jle    11e3 <write_square_matrix+0x93>
mov    %ebp,%r13d
lea    0xe8f(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rax
mov    (%rax,%rbp,4),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11b0 <write_square_matrix+0x60>
mov    $0xa,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
jne    11a0 <write_square_matrix+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de7(%rip),%rax
mov    (%rax),%rcx
lea    0xdff(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.1 = [33 x i8] c"Error while writing the matrix.\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @write_square_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
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32*, i32** @stderr
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32*, i32** %7
%20 = load i32, i32* %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 0, i32* %8
br label %22
22: ; preds = %49, %18
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %52
26: ; preds = %22
store i32 0, i32* %9
br label %27
27: ; preds = %43, %26
%28 = load i32, i32* %9
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32*, i32** %7
%33 = load i32**, i32*** %4
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
%37 = load i32*, i32** %36
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %31
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %27
46: ; preds = %27
%47 = load i32*, i32** %7
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %46
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %22
52: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.1 = [33 x i8] c"Error while writing the matrix.\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define void @write_square_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 eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32*, i32** @stderr
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 32, i64 1, i32* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %19, %13
%16 = phi i64 [ 0, %13 ], [ %21, %19 ]
%17 = getelementptr inbounds i32*, i32** %0, i64 %16
br label %23
18: ; preds = %19, %10
ret void
19: ; preds = %23
%20 = tail call i32 @fputc(i32 10, i32* %4)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %14
br i1 %22, label %18, label %15
23: ; preds = %15, %23
%24 = phi i64 [ 0, %15 ], [ %29, %23 ]
%25 = load i32*, i32** %17
%26 = getelementptr inbounds i32, i32* %25, i64 %24
%27 = load i32, i32* %26
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %24, 1
%30 = icmp eq i64 %29, %14
br i1 %30, label %19, label %23
}