#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 const *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int read_matrix(const char *filename, int size, int matrix[][size]) {
  FILE *fp1;
  fp1 = fopen(filename, "r");
  if (fp1 == NULL) {
    printf("Cannot open %s for reading\n", filename);
    return (1);
  } else {
    for (int x = 0; x < size; x++) {
      for (int y = 0; y < size; y++) {
        matrix[x][y] = getc(fp1);
      }
    }
  }
  fclose(fp1);
  return (0);
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1195 <read_matrix+0x55>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121a <read_matrix+0xda>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1205 <read_matrix+0xc5>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f2 <read_matrix+0xb2>
mov    -0x28(%rbp),%rdi
call   1060 <getc@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   %rsi,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11af <read_matrix+0x6f>
jmp    11f7 <read_matrix+0xb7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119c <read_matrix+0x5c>
jmp    120a <read_matrix+0xca>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11be <read_matrix+0x7e>
mov    %rax,%r14
test   %r15d,%r15d
jle    11b2 <read_matrix+0x72>
mov    %r15d,%ebp
lea    0x0(,%rbp,4),%r15
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <read_matrix+0x50>
add    $0x1,%r12
add    %r15,%r13
cmp    %rbp,%r12
jne    1180 <read_matrix+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11d2 <read_matrix+0x92>
lea    0xe3d(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    $0x1,%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"r\00"
@.str.1 = [28 x i8] c"Cannot open %s for reading\0A\00"
define i32 @read_matrix(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %8
%15 = load i32*, i32** %8
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 1, i32* %4
br label %52
20: ; preds = %3
store i32 0, i32* %9
br label %21
21: ; preds = %45, %20
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
store i32 0, i32* %10
br label %26
26: ; preds = %41, %25
%27 = load i32, i32* %10
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %44
30: ; preds = %26
%31 = load i32*, i32** %8
%32 = call i32 @getc(i32* %31)
%33 = load i32*, i32** %7
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = mul nsw i64 %35, %12
%37 = getelementptr inbounds i32, i32* %33, i64 %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %32, i32* %40
br label %41
41: ; preds = %30
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %26
44: ; preds = %26
br label %45
45: ; preds = %44
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %21
48: ; preds = %21
br label %49
49: ; preds = %48
%50 = load i32*, i32** %8
%51 = call i32 @fclose(i32* %50)
store i32 0, i32* %4
br label %52
52: ; preds = %49, %17
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Cannot open %s for reading\0A\00"
define i32 @read_matrix(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = zext i32 %1 to i64
%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 %9, label %7
7: ; preds = %3
%8 = icmp sgt i32 %1, 0
br i1 %8, label %11, label %15
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
11: ; preds = %7, %17
%12 = phi i64 [ %18, %17 ], [ 0, %7 ]
%13 = mul nuw nsw i64 %12, %4
%14 = getelementptr inbounds i32, i32* %2, i64 %13
br label %20
15: ; preds = %17, %7
%16 = tail call i32 @fclose(i32* %5)
br label %26
17: ; preds = %20
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %4
br i1 %19, label %15, label %11
20: ; preds = %11, %20
%21 = phi i64 [ 0, %11 ], [ %24, %20 ]
%22 = tail call i32 @getc(i32* %5)
%23 = getelementptr inbounds i32, i32* %14, i64 %21
store i32 %22, i32* %23
%24 = add nuw nsw i64 %21, 1
%25 = icmp eq i64 %24, %4
br i1 %25, label %17, label %20
26: ; preds = %15, %9
%27 = phi i32 [ 1, %9 ], [ 0, %15 ]
ret i32 %27
}