#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int ntohl(int);
int read_matrix(int *target, char *source_file, int matrix_size) {
  FILE *mf = fopen(source_file, "r");
  assert(target != NULL);
  assert(source_file != NULL);
  size_t read_items = fread(target, sizeof(int), matrix_size * matrix_size, mf);
  fclose(mf);
  unsigned long i;
  for (i = 0; i < matrix_size * matrix_size; i++) {
    target[i] = ntohl(target[i]);
  }
  return (read_items == (matrix_size * matrix_size));
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    120e <read_matrix+0xbe>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1070 <ntohl@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11c9 <read_matrix+0x79>
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe97(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1050 <assert@plt>
imul   %r14d,%r14d
mov    %r13,%rdi
mov    $0x4,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %r14d,%r14d
je     11d8 <read_matrix+0x88>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%edi
call   1070 <ntohl@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <read_matrix+0x70>
xor    %eax,%eax
cmp    %r14,%r12
sete   %al
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @read_matrix(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%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** %4
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32*, i32** %4
%21 = load i32, i32* %6
%22 = load i32, i32* %6
%23 = mul nsw i32 %21, %22
%24 = load i32*, i32** %7
%25 = call i64 @fread(i32* %20, i32 4, i32 %23, i32* %24)
store i64 %25, i64* %8
%26 = load i32*, i32** %7
%27 = call i32 @fclose(i32* %26)
store i64 0, i64* %9
br label %28
28: ; preds = %44, %3
%29 = load i64, i64* %9
%30 = load i32, i32* %6
%31 = load i32, i32* %6
%32 = mul nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = icmp ult i64 %29, %33
br i1 %34, label %35, label %47
35: ; preds = %28
%36 = load i32*, i32** %4
%37 = load i64, i64* %9
%38 = getelementptr inbounds i32, i32* %36, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @ntohl(i32 %39)
%41 = load i32*, i32** %4
%42 = load i64, i64* %9
%43 = getelementptr inbounds i32, i32* %41, i64 %42
store i32 %40, i32* %43
br label %44
44: ; preds = %35
%45 = load i64, i64* %9
%46 = add i64 %45, 1
store i64 %46, i64* %9
br label %28
47: ; preds = %28
%48 = load i64, i64* %8
%49 = load i32, i32* %6
%50 = load i32, i32* %6
%51 = mul nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = icmp eq i64 %48, %52
%54 = zext i1 %53 to i32
ret i32 %54
}

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