#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*/ ushort;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, long,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ nrerror(char *);
void fwrite_usmatrix(ushort **m, long nrl, long nrh, long ncl, long nch,
                     char *filename) {
  long i, ncol = nch - ncl + 1;
  FILE *f;
  f = fopen(filename, "wb");
  if (f == NULL)
    nrerror("Can't open file in fwrite_usmatrix");
  for (i = nrl; i <= nrh; i++) {
    fwrite(m[i] + nrl, sizeof(ushort), ncol, f);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<fwrite_usmatrix>:
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    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    119b <fwrite_usmatrix+0x5b>
lea    0xe6d(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     11eb <fwrite_usmatrix+0xab>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x4,%esi
call   1060 <fwrite@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11a3 <fwrite_usmatrix+0x63>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_usmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe9f(%rip),%rsi
mov    %r9,%rdi
call   1050 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
je     1178 <fwrite_usmatrix+0x38>
cmp    %r15,%rbx
jle    1189 <fwrite_usmatrix+0x49>
jmp    11c0 <fwrite_usmatrix+0x80>
lea    0xe84(%rip),%rdi
call   1030 <nrerror@plt>
cmp    %r15,%rbx
jg     11c0 <fwrite_usmatrix+0x80>
sub    %rbp,%r14
add    $0x1,%r14
add    $0x1,%r15
lea    0x0(,%rbx,4),%rbp
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rdi
add    %rbp,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
mov    %r13,%rcx
call   1060 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <fwrite_usmatrix+0x60>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [35 x i8] c"Can't open file in fwrite_usmatrix\00"
define void @fwrite_usmatrix(i32** nocapture %0, i64 %1, i64 %2, i64 %3, i64 %4, i8* nocapture %5) {
%7 = sub i64 1, %3
%8 = add i64 %7, %4
%9 = tail call i32* @fopen(i8* %5, 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 ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = icmp sgt i64 %1, %2
br i1 %14, label %23, label %15
15: ; preds = %13, %15
%16 = phi i64 [ %21, %15 ], [ %1, %13 ]
%17 = getelementptr inbounds i32*, i32** %0, i64 %16
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 %1
%20 = tail call i32 @fwrite(i32* %19, i32 4, i64 %8, i32* %9)
%21 = add i64 %16, 1
%22 = icmp eq i64 %16, %2
br i1 %22, label %23, label %15
23: ; preds = %15, %13
%24 = tail call i32 @fclose(i32* %9)
ret void
}