#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 *);
int const fread(unsigned char *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ p3dGetElapsedTime_min();
int /*<<< orphan*/ p3dGetElapsedTime_sec();
int /*<<< orphan*/ p3dResetStartTime();
int /*<<< orphan*/ printf(char *, char *);
int p3dReadRaw8(char *filename, unsigned char *out_im, const int dimx,
                const int dimy, const int dimz,
                int (*wr_log)(const char *, ...),
                int (*wr_progress)(const int, ...)) {
  FILE *fvol;
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Reading RAW file %s ...", filename);
  }
  if ((fvol = fopen(filename, "rb")) == NULL) {
    printf("Cannot open input file %s.", filename);
    out_im = NULL;
    return 1;
  }
  if (fread(out_im, sizeof(unsigned char), dimx * dimy * dimz, fvol) <
      (dimx * dimy * dimz)) {
    wr_log("Pore3D - IO error: error on reading file %s. Program will exit.",
           filename);
    return 1;
  }
  fclose(fvol);
  if (wr_log != NULL) {
    wr_log("Pore3D - RAW file read successfully in %dm%0.3fs.",
           p3dGetElapsedTime_min(), p3dGetElapsedTime_sec());
  }
  return 2;
}


x86 assembly (clang, -O0):
<p3dReadRaw8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b7 <p3dReadRaw8+0x47>
mov    $0x0,%al
call   1080 <p3dResetStartTime@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   *%rcx
mov    -0x10(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11f9 <p3dReadRaw8+0x89>
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x4(%rbp)
jmp    1290 <p3dReadRaw8+0x120>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
imul   -0x20(%rbp),%edx
imul   -0x24(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1248 <p3dReadRaw8+0xd8>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rsi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   *%rcx
movl   $0x1,-0x4(%rbp)
jmp    1290 <p3dReadRaw8+0x120>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     1289 <p3dReadRaw8+0x119>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1070 <p3dGetElapsedTime_min@plt>
mov    %eax,-0x44(%rbp)
mov    $0x0,%al
call   1050 <p3dGetElapsedTime_sec@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rcx
mov    %eax,%edx
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   *%rcx
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dReadRaw8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r15d
mov    %ecx,%ebp
mov    %edx,%r13d
mov    %rsi,(%rsp)
mov    %rdi,%rbx
test   %r9,%r9
je     11a8 <p3dReadRaw8+0x38>
xor    %eax,%eax
call   1080 <p3dResetStartTime@plt>
lea    0xe60(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   *%r14
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f5 <p3dReadRaw8+0x85>
mov    %rax,%r12
imul   %r13d,%ebp
imul   %r15d,%ebp
mov    $0x1,%r15d
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    %ebp,%eax
jge    120c <p3dReadRaw8+0x9c>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   *%r14
jmp    123f <p3dReadRaw8+0xcf>
lea    0xe28(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    $0x1,%r15d
jmp    123f <p3dReadRaw8+0xcf>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    $0x2,%r15d
test   %r14,%r14
je     123f <p3dReadRaw8+0xcf>
xor    %eax,%eax
call   1070 <p3dGetElapsedTime_min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <p3dGetElapsedTime_sec@plt>
lea    0xe49(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *%r14
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Pore3D - Reading RAW file %s ...\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [27 x i8] c"Cannot open input file %s.\00"
@.str.3 = [64 x i8] c"Pore3D - IO error: error on reading file %s. Program will exit.\00"
@.str.4 = [50 x i8] c"Pore3D - RAW file read successfully in %dm%0.3fs.\00"
define i32 @p3dReadRaw8(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 (i8*, ...)* %5, i32 (i32, ...)* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32 (i8*, ...)*
%15 = alloca i32 (i32, ...)*
%16 = alloca i32*
store i8* %0, i8** %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 (i8*, ...)* %5, i32 (i8*, ...)** %14
store i32 (i32, ...)* %6, i32 (i32, ...)** %15
%17 = load i32 (i8*, ...)*, i32 (i8*, ...)** %14
%18 = icmp ne i32 (i8*, ...)* %17, null
br i1 %18, label %19, label %24
19: ; preds = %7
%20 = call i32 (...) @p3dResetStartTime()
%21 = load i32 (i8*, ...)*, i32 (i8*, ...)** %14
%22 = load i8*, i8** %9
%23 = call i32 (i8*, ...) %21(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %7
%25 = load i8*, i8** %9
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %16
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** %9
%30 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i8* null, i8** %10
store i32 1, i32* %8
br label %61
31: ; preds = %24
%32 = load i8*, i8** %10
%33 = load i32, i32* %11
%34 = load i32, i32* %12
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %13
%37 = mul nsw i32 %35, %36
%38 = load i32*, i32** %16
%39 = call i32 @fread(i8* %32, i32 1, i32 %37, i32* %38)
%40 = load i32, i32* %11
%41 = load i32, i32* %12
%42 = mul nsw i32 %40, %41
%43 = load i32, i32* %13
%44 = mul nsw i32 %42, %43
%45 = icmp slt i32 %39, %44
br i1 %45, label %46, label %50
46: ; preds = %31
%47 = load i32 (i8*, ...)*, i32 (i8*, ...)** %14
%48 = load i8*, i8** %9
%49 = call i32 (i8*, ...) %47(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %48)
store i32 1, i32* %8
br label %61
50: ; preds = %31
%51 = load i32*, i32** %16
%52 = call i32 @fclose(i32* %51)
%53 = load i32 (i8*, ...)*, i32 (i8*, ...)** %14
%54 = icmp ne i32 (i8*, ...)* %53, null
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = load i32 (i8*, ...)*, i32 (i8*, ...)** %14
%57 = call i32 (...) @p3dGetElapsedTime_min()
%58 = call i32 (...) @p3dGetElapsedTime_sec()
%59 = call i32 (i8*, ...) %56(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %57, i32 %58)
br label %60
60: ; preds = %55, %50
store i32 2, i32* %8
br label %61
61: ; preds = %60, %46, %28
%62 = load i32, i32* %8
ret i32 %62
}

LLVM IR (-O2):
@.str = [33 x i8] c"Pore3D - Reading RAW file %s ...\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [27 x i8] c"Cannot open input file %s.\00"
@.str.3 = [64 x i8] c"Pore3D - IO error: error on reading file %s. Program will exit.\00"
@.str.4 = [50 x i8] c"Pore3D - RAW file read successfully in %dm%0.3fs.\00"
define i32 @p3dReadRaw8(i8* %0, i8* nocapture %1, i32 %2, i32 %3, i32 %4, i32 (i8*, ...)* %5, i32 (i32, ...)* nocapture readnone %6) {
%8 = icmp eq i32 (i8*, ...)* %5, null
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = tail call i32 (...) @p3dResetStartTime()
%11 = tail call i32 (i8*, ...) %5(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %9, %7
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %30
17: ; preds = %12
%18 = mul nsw i32 %3, %2
%19 = mul nsw i32 %18, %4
%20 = tail call i32 @fread(i8* %1, i32 1, i32 %19, i32* %13)
%21 = icmp slt i32 %20, %19
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 (i8*, ...) %5(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %30
24: ; preds = %17
%25 = tail call i32 @fclose(i32* %13)
br i1 %8, label %30, label %26
26: ; preds = %24
%27 = tail call i32 (...) @p3dGetElapsedTime_min()
%28 = tail call i32 (...) @p3dGetElapsedTime_sec()
%29 = tail call i32 (i8*, ...) %5(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %28)
br label %30
30: ; preds = %24, %26, %22, %15
%31 = phi i32 [ 1, %15 ], [ 1, %22 ], [ 2, %26 ], [ 2, %24 ]
ret i32 %31
}