#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 /*<<< orphan*/ fwrite(float *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int __p3dWriteRaw32(float *in_im, char *filename, const int dimx,
                    const int dimy, const int dimz) {
  FILE *fvol;
  if ((fvol = fopen(filename, "wb")) == NULL) {
    printf("Cannot open output file %s.", filename);
    in_im = NULL;
    return -1;
  }
  fwrite(in_im, sizeof(float), dimx * dimy * dimz, fvol);
  fclose(fvol);
  return 0;
}


x86 assembly (clang, -O0):
<__p3dWriteRaw32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    119c <__p3dWriteRaw32+0x5c>
mov    -0x18(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <__p3dWriteRaw32+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
imul   -0x20(%rbp),%edx
imul   -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x4,%esi
call   1060 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__p3dWriteRaw32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %edx,%r13d
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xea0(%rip),%rsi
mov    %r12,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1196 <__p3dWriteRaw32+0x56>
mov    %rax,%rbp
imul   %r13d,%ebx
imul   %r14d,%ebx
mov    %r15,%rdi
mov    $0x4,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11aa <__p3dWriteRaw32+0x6a>
lea    0xe66(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [28 x i8] c"Cannot open output file %s.\00"
define i32 @__p3dWriteRaw32(float* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca float*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store float* %0, float** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i8*, i8** %8
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = load i8*, i8** %8
%18 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store float* null, float** %7
store i32 -1, i32* %6
br label %30
19: ; preds = %5
%20 = load float*, float** %7
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = mul nsw i32 %21, %22
%24 = load i32, i32* %11
%25 = mul nsw i32 %23, %24
%26 = load i32*, i32** %12
%27 = call i32 @fwrite(float* %20, i32 4, i32 %25, i32* %26)
%28 = load i32*, i32** %12
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %6
br label %30
30: ; preds = %19, %16
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [28 x i8] c"Cannot open output file %s.\00"
define i32 @__p3dWriteRaw32(float* nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32* @fopen(i8* %1, 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 %10
8: ; preds = %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %15
10: ; preds = %5
%11 = mul nsw i32 %3, %2
%12 = mul nsw i32 %11, %4
%13 = tail call i32 @fwrite(float* %0, i32 4, i32 %12, i32* %6)
%14 = tail call i32 @fclose(i32* %6)
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %16
}