#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 *);
long fread(short *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ nrerror(char *);
void fread_smatrix(char *filename, short **m, long nrl, long nrh, long ncl,
                   long nch) {
  long i, ncol = nch - ncl + 1, nread;
  FILE *f;
  f = fopen(filename, "rb");
  if (f == NULL)
    nrerror("Can't open file in fread_smatrix");
  for (i = nrl; i <= nrh; i++) {
    nread = fread(m[i] + nrl, sizeof(short), ncol, f);
    if (nread != ncol)
      nrerror("fread_smatrix : can't read data");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<fread_smatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    119b <fread_smatrix+0x5b>
lea    0xe6d(%rip),%rdi
call   1040 <nrerror@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jg     120e <fread_smatrix+0xce>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    %rax,%rdi
mov    -0x40(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    $0x2,%esi
call   1030 <fread@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     11f8 <fread_smatrix+0xb8>
lea    0xe31(%rip),%rdi
call   1040 <nrerror@plt>
jmp    11fd <fread_smatrix+0xbd>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11a3 <fread_smatrix+0x63>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_smatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%rbp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r12
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
je     1175 <fread_smatrix+0x35>
cmp    %r14,%rbx
jg     1186 <fread_smatrix+0x46>
jmp    119c <fread_smatrix+0x5c>
lea    0xe87(%rip),%rdi
call   1040 <nrerror@plt>
cmp    %r14,%rbx
jle    119c <fread_smatrix+0x5c>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
sub    %rbp,%r15
add    $0x1,%r15
add    $0x1,%r14
lea    (%rbx,%rbx,1),%rbp
jmp    11b9 <fread_smatrix+0x79>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1186 <fread_smatrix+0x46>
mov    (%r12,%rbx,8),%rdi
add    %rbp,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    %r13,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
je     11b0 <fread_smatrix+0x70>
lea    0xe48(%rip),%rdi
call   1040 <nrerror@plt>
jmp    11b0 <fread_smatrix+0x70>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [33 x i8] c"Can't open file in fread_smatrix\00"
@.str.2 = [32 x i8] c"fread_smatrix : can't read data\00"
define void @fread_smatrix(i8* %0, i16** %1, i64 %2, i64 %3, i64 %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i16**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32*
store i8* %0, i8** %7
store i16** %1, i16*** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i64 %5, i64* %12
%17 = load i64, i64* %12
%18 = load i64, i64* %11
%19 = sub nsw i64 %17, %18
%20 = add nsw i64 %19, 1
store i64 %20, i64* %14
%21 = load i8*, i8** %7
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %16
%23 = load i32*, i32** %16
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %6
%26 = call i32 @nrerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %6
%28 = load i64, i64* %9
store i64 %28, i64* %13
br label %29
29: ; preds = %49, %27
%30 = load i64, i64* %13
%31 = load i64, i64* %10
%32 = icmp sle i64 %30, %31
br i1 %32, label %33, label %52
33: ; preds = %29
%34 = load i16**, i16*** %8
%35 = load i64, i64* %13
%36 = getelementptr inbounds i16*, i16** %34, i64 %35
%37 = load i16*, i16** %36
%38 = load i64, i64* %9
%39 = getelementptr inbounds i16, i16* %37, i64 %38
%40 = load i64, i64* %14
%41 = load i32*, i32** %16
%42 = call i64 @fread(i16* %39, i32 2, i64 %40, i32* %41)
store i64 %42, i64* %15
%43 = load i64, i64* %15
%44 = load i64, i64* %14
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %33
%47 = call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %33
br label %49
49: ; preds = %48
%50 = load i64, i64* %13
%51 = add nsw i64 %50, 1
store i64 %51, i64* %13
br label %29
52: ; preds = %29
%53 = load i32*, i32** %16
%54 = call i32 @fclose(i32* %53)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [33 x i8] c"Can't open file in fread_smatrix\00"
@.str.2 = [32 x i8] c"fread_smatrix : can't read data\00"
define void @fread_smatrix(i8* nocapture %0, i16** nocapture %1, i64 %2, i64 %3, i64 %4, i64 %5) {
%7 = sub nsw i64 %5, %4
%8 = add nsw i64 %7, 1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @nrerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = icmp sgt i64 %2, %3
br i1 %14, label %27, label %15
15: ; preds = %13, %24
%16 = phi i64 [ %25, %24 ], [ %2, %13 ]
%17 = getelementptr inbounds i16*, i16** %1, i64 %16
%18 = load i16*, i16** %17
%19 = getelementptr inbounds i16, i16* %18, i64 %2
%20 = tail call i64 @fread(i16* %19, i32 2, i64 %8, i32* %9)
%21 = icmp eq i64 %20, %8
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = tail call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %15, %22
%25 = add i64 %16, 1
%26 = icmp eq i64 %16, %3
br i1 %26, label %27, label %15
27: ; preds = %24, %13
%28 = tail call i32 @fclose(i32* %9)
ret void
}