#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void inputimgraw(char *fname, unsigned char *img, int ny, int nx, int dim) {
  FILE *fimg;
  fimg = fopen(fname, "rb");
  if (!fimg) {
    printf("unable to read %s\n", fname);
    exit(-1);
  }
  fread(img, sizeof(unsigned char), ny * nx * dim, fimg);
  fclose(fimg);
}


x86 assembly (clang, -O0):
<inputimgraw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <inputimgraw+0x53>
mov    -0x8(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
imul   -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputimgraw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ad <inputimgraw+0x5d>
mov    %rax,%rbp
imul   %r12d,%ebx
imul   %r15d,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe4f(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [19 x i8] c"unable to read %s\0A\00"
define void @inputimgraw(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i8*, i8** %6
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %5
%17 = load i8*, i8** %6
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %5
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = mul nsw i32 %22, %23
%25 = load i32, i32* %10
%26 = mul nsw i32 %24, %25
%27 = load i32*, i32** %11
%28 = call i32 @fread(i8* %21, i32 1, i32 %26, i32* %27)
%29 = load i32*, i32** %11
%30 = call i32 @fclose(i32* %29)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [19 x i8] c"unable to read %s\0A\00"
define void @inputimgraw(i8* %0, i8* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %5
%12 = mul nsw i32 %3, %2
%13 = mul nsw i32 %12, %4
%14 = tail call i32 @fread(i8* %1, i32 1, i32 %13, i32* %6)
%15 = tail call i32 @fclose(i32* %6)
ret void
}