#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
void *malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strtok(char *, char *);
int *read_file(char *filename, int *psize, int hor_vert) {
  FILE *fp;
  int i, j, size, *matrix;
  char size_buffer[16], *buffer;
  if ((fp = fopen(filename, "r")) < 0) {
    printf("\nfile error\n");
    exit(-1);
  }
  fgets(size_buffer, 100, fp);
  size = atoi(size_buffer);
  matrix = malloc(size * size * sizeof(int));
  buffer = malloc((size * 5 + 2) * sizeof(char));
  if (hor_vert == 0) {
    for (i = 0; i < size; i++) {
      fgets(buffer, size * 8, fp);
      *(matrix + (i * size)) = atoi((char *)strtok(buffer, " "));
      for (j = 1; j < size; j++) {
        *(matrix + (j + i * size)) = atoi((char *)strtok(NULL, " "));
      }
    }
  } else {
    for (i = 0; i < size; i++) {
      fgets(buffer, size * 8, fp);
      *(matrix + i) = atoi((char *)strtok(buffer, " "));
      for (j = 1; j < size; j++) {
        *(matrix + (j * size + i)) = atoi((char *)strtok(NULL, " "));
      }
    }
  }
  *psize = size;
  free(buffer);
  fclose(fp);
  return matrix;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jae    11d7 <read_file+0x47>
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x50(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
imul   $0x5,-0x2c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12e9 <read_file+0x159>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12e4 <read_file+0x154>
mov    -0x58(%rbp),%rdi
mov    -0x2c(%rbp),%esi
shl    $0x3,%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x58(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   10a0 <atoi@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12d1 <read_file+0x141>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd71(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   10a0 <atoi@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%esi
imul   -0x2c(%rbp),%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1287 <read_file+0xf7>
jmp    12d6 <read_file+0x146>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1236 <read_file+0xa6>
jmp    139b <read_file+0x20b>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1396 <read_file+0x206>
mov    -0x58(%rbp),%rdi
mov    -0x2c(%rbp),%esi
shl    $0x3,%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x58(%rbp),%rdi
lea    0xcf5(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   10a0 <atoi@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1383 <read_file+0x1f3>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcbd(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   10a0 <atoi@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    133b <read_file+0x1ab>
jmp    1388 <read_file+0x1f8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12f0 <read_file+0x160>
jmp    139b <read_file+0x20b>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,0x20(%rsp)
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    %eax,%edi
imul   %eax,%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    (%rbx,%rbx,4),%edi
add    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %ebp,%ebp
mov    %r14,0x28(%rsp)
mov    %rbx,0x10(%rsp)
je     12b4 <read_file+0x144>
test   %ebx,%ebx
jle    1361 <read_file+0x1f1>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0x4(%rsp)
mov    %eax,%ecx
lea    0x0(,%rcx,4),%r12
mov    0x8(%rsp),%rax
lea    (%rax,%rcx,4),%r15
mov    %rcx,0x38(%rsp)
lea    -0x1(%rcx),%rax
mov    %rax,0x30(%rsp)
xor    %ebp,%ebp
lea    0xdd9(%rip),%r14
jmp    1243 <read_file+0xd3>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
add    $0x4,%r15
cmp    0x38(%rsp),%rbp
je     1361 <read_file+0x1f1>
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    0x4(%rsp),%esi
mov    0x20(%rsp),%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx,%rbp,4)
cmpl   $0x1,0x10(%rsp)
je     1230 <read_file+0xc0>
mov    0x30(%rsp),%rbx
mov    %r15,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %r14,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,0x0(%r13)
add    %r12,%r13
add    $0xffffffffffffffff,%rbx
jne    1290 <read_file+0x120>
jmp    1230 <read_file+0xc0>
test   %ebx,%ebx
jle    1361 <read_file+0x1f1>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0x4(%rsp)
mov    %eax,%ebx
lea    0x0(,%rbx,4),%r12
xor    %r13d,%r13d
lea    0xd22(%rip),%r15
mov    0x8(%rsp),%r14
jmp    12fc <read_file+0x18c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
add    %r12,%r14
cmp    %rbx,%r13
je     1361 <read_file+0x1f1>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    0x4(%rsp),%esi
mov    0x20(%rsp),%rdx
call   1050 <fgets@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %r13,%rcx
imul   %rbx,%rcx
mov    0x8(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
cmpl   $0x1,0x10(%rsp)
je     12f0 <read_file+0x180>
mov    $0x1,%ebp
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r14,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1340 <read_file+0x1d0>
jmp    12f0 <read_file+0x180>
mov    0x28(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    %ecx,(%rax)
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x58,%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 = [13 x i8] c"\0Afile error\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32* @read_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
%10 = alloca i32
%11 = alloca i32*
%12 = alloca [16 x i8]
%13 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = icmp ult i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %3
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%22 = load i32*, i32** %7
%23 = call i32 @fgets(i8* %21, i32 100, i32* %22)
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = load i32, i32* %10
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i8* @malloc(i32 %31)
%33 = bitcast i8* %32 to i32*
store i32* %33, i32** %11
%34 = load i32, i32* %10
%35 = mul nsw i32 %34, 5
%36 = add nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %13
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %88
43: ; preds = %20
store i32 0, i32* %8
br label %44
44: ; preds = %84, %43
%45 = load i32, i32* %8
%46 = load i32, i32* %10
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %87
48: ; preds = %44
%49 = load i8*, i8** %13
%50 = load i32, i32* %10
%51 = mul nsw i32 %50, 8
%52 = load i32*, i32** %7
%53 = call i32 @fgets(i8* %49, i32 %51, i32* %52)
%54 = load i8*, i8** %13
%55 = call i64 @strtok(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%56 = inttoptr i64 %55 to i8*
%57 = call i32 @atoi(i8* %56)
%58 = load i32*, i32** %11
%59 = load i32, i32* %8
%60 = load i32, i32* %10
%61 = mul nsw i32 %59, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %58, i64 %62
store i32 %57, i32* %63
store i32 1, i32* %9
br label %64
64: ; preds = %80, %48
%65 = load i32, i32* %9
%66 = load i32, i32* %10
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %83
68: ; preds = %64
%69 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%70 = inttoptr i64 %69 to i8*
%71 = call i32 @atoi(i8* %70)
%72 = load i32*, i32** %11
%73 = load i32, i32* %9
%74 = load i32, i32* %8
%75 = load i32, i32* %10
%76 = mul nsw i32 %74, %75
%77 = add nsw i32 %73, %76
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32, i32* %72, i64 %78
store i32 %71, i32* %79
br label %80
80: ; preds = %68
%81 = load i32, i32* %9
%82 = add nsw i32 %81, 1
store i32 %82, i32* %9
br label %64
83: ; preds = %64
br label %84
84: ; preds = %83
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 1
store i32 %86, i32* %8
br label %44
87: ; preds = %44
br label %131
88: ; preds = %20
store i32 0, i32* %8
br label %89
89: ; preds = %127, %88
%90 = load i32, i32* %8
%91 = load i32, i32* %10
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %130
93: ; preds = %89
%94 = load i8*, i8** %13
%95 = load i32, i32* %10
%96 = mul nsw i32 %95, 8
%97 = load i32*, i32** %7
%98 = call i32 @fgets(i8* %94, i32 %96, i32* %97)
%99 = load i8*, i8** %13
%100 = call i64 @strtok(i8* %99, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%101 = inttoptr i64 %100 to i8*
%102 = call i32 @atoi(i8* %101)
%103 = load i32*, i32** %11
%104 = load i32, i32* %8
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %103, i64 %105
store i32 %102, i32* %106
store i32 1, i32* %9
br label %107
107: ; preds = %123, %93
%108 = load i32, i32* %9
%109 = load i32, i32* %10
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %126
111: ; preds = %107
%112 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%113 = inttoptr i64 %112 to i8*
%114 = call i32 @atoi(i8* %113)
%115 = load i32*, i32** %11
%116 = load i32, i32* %9
%117 = load i32, i32* %10
%118 = mul nsw i32 %116, %117
%119 = load i32, i32* %8
%120 = add nsw i32 %118, %119
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i32, i32* %115, i64 %121
store i32 %114, i32* %122
br label %123
123: ; preds = %111
%124 = load i32, i32* %9
%125 = add nsw i32 %124, 1
store i32 %125, i32* %9
br label %107
126: ; preds = %107
br label %127
127: ; preds = %126
%128 = load i32, i32* %8
%129 = add nsw i32 %128, 1
store i32 %129, i32* %8
br label %89
130: ; preds = %89
br label %131
131: ; preds = %130, %87
%132 = load i32, i32* %10
%133 = load i32*, i32** %5
store i32 %132, i32* %133
%134 = load i8*, i8** %13
%135 = call i32 @free(i8* %134)
%136 = load i32*, i32** %7
%137 = call i32 @fclose(i32* %136)
%138 = load i32*, i32** %11
ret i32* %138
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
define noalias i32* @read_file(i8* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @fgets(i8* %5, i32 100, i32* %6)
%8 = call i32 @atoi(i8* %5)
%9 = shl i32 %8, 2
%10 = mul i32 %9, %8
%11 = call i8* @malloc(i32 %10)
%12 = bitcast i8* %11 to i32*
%13 = mul nsw i32 %8, 5
%14 = add nsw i32 %13, 2
%15 = call i8* @malloc(i32 %14)
%16 = icmp eq i32 %2, 0
%17 = icmp sgt i32 %8, 0
br i1 %16, label %24, label %18
18: ; preds = %3
br i1 %17, label %19, label %70
19: ; preds = %18
%20 = shl nsw i32 %8, 3
%21 = icmp eq i32 %8, 1
%22 = zext i32 %8 to i64
%23 = zext i32 %8 to i64
br label %50
24: ; preds = %3
br i1 %17, label %25, label %70
25: ; preds = %24
%26 = shl nsw i32 %8, 3
%27 = icmp eq i32 %8, 1
%28 = zext i32 %8 to i64
%29 = zext i32 %8 to i64
br label %30
30: ; preds = %25, %47
%31 = phi i64 [ 0, %25 ], [ %48, %47 ]
%32 = call i32 @fgets(i8* %15, i32 %26, i32* %6)
%33 = call i64 @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = inttoptr i64 %33 to i8*
%35 = call i32 @atoi(i8* %34)
%36 = mul nsw i64 %31, %28
%37 = getelementptr inbounds i32, i32* %12, i64 %36
store i32 %35, i32* %37
br i1 %27, label %47, label %38
38: ; preds = %30, %38
%39 = phi i64 [ %45, %38 ], [ 1, %30 ]
%40 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = inttoptr i64 %40 to i8*
%42 = call i32 @atoi(i8* %41)
%43 = add nuw nsw i64 %39, %36
%44 = getelementptr inbounds i32, i32* %12, i64 %43
store i32 %42, i32* %44
%45 = add nuw nsw i64 %39, 1
%46 = icmp eq i64 %45, %29
br i1 %46, label %47, label %38
47: ; preds = %38, %30
%48 = add nuw nsw i64 %31, 1
%49 = icmp eq i64 %48, %29
br i1 %49, label %70, label %30
50: ; preds = %19, %67
%51 = phi i64 [ 0, %19 ], [ %68, %67 ]
%52 = call i32 @fgets(i8* %15, i32 %20, i32* %6)
%53 = call i64 @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = inttoptr i64 %53 to i8*
%55 = call i32 @atoi(i8* %54)
%56 = getelementptr inbounds i32, i32* %12, i64 %51
store i32 %55, i32* %56
br i1 %21, label %67, label %57
57: ; preds = %50, %57
%58 = phi i64 [ %65, %57 ], [ 1, %50 ]
%59 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%60 = inttoptr i64 %59 to i8*
%61 = call i32 @atoi(i8* %60)
%62 = mul nsw i64 %58, %22
%63 = add nuw nsw i64 %62, %51
%64 = getelementptr inbounds i32, i32* %12, i64 %63
store i32 %61, i32* %64
%65 = add nuw nsw i64 %58, 1
%66 = icmp eq i64 %65, %23
br i1 %66, label %67, label %57
67: ; preds = %57, %50
%68 = add nuw nsw i64 %51, 1
%69 = icmp eq i64 %68, %23
br i1 %69, label %70, label %50
70: ; preds = %67, %47, %18, %24
store i32 %8, i32* %1
%71 = call i32 @free(i8* %15)
%72 = call i32 @fclose(i32* %6)
ret i32* %12
}