#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_file(char *filename, int *matrix, int size) {
  FILE *fp;
  int i, j;
  fp = fopen(filename, "w");
  fprintf(fp, "%d\n", size);
  for (i = 0; i < size; i++) {
    for (j = 0; j < size; j++)
      fprintf(fp, "%d ", *(matrix + j + size * i));
    fprintf(fp, "\n");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ee <write_file+0xbe>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ce <write_file+0x9e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    -0x14(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1186 <write_file+0x56>
mov    -0x20(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1173 <write_file+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %ebp,%ebp
jle    11d4 <write_file+0x94>
mov    %ebp,%ebp
lea    0x0(,%rbp,4),%rax
mov    %rax,(%rsp)
lea    0xe7b(%rip),%r15
xor    %r13d,%r13d
xchg   %ax,%ax
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%r12,4),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    11a0 <write_file+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
add    (%rsp),%rbx
cmp    %rbp,%r13
jne    1190 <write_file+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%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"%d\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @write_file(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%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 = load i32, i32* %6
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 0, i32* %8
br label %15
15: ; preds = %43, %3
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %46
19: ; preds = %15
store i32 0, i32* %9
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32*, i32** %7
%26 = load i32*, i32** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %6
%31 = load i32, i32* %8
%32 = mul nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %29, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %24
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %20
40: ; preds = %20
%41 = load i32*, i32** %7
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %40
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %15
46: ; preds = %15
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
ret i32 0
}

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