#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
void writeOutputData(char *file, int rows, int cols, int **image) {
  int row, col;
  FILE *fp;
  fp = fopen(file, "wb");
  if (fp == NULL) {
    return;
  }
  for (row = 0; row < rows; row++)
    fwrite(&image[row][0], sizeof(int) * cols, 1, fp);
  fflush(fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<writeOutputData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117a <writeOutputData+0x3a>
jmp    11d1 <writeOutputData+0x91>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <writeOutputData+0x7f>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <writeOutputData+0x41>
mov    -0x28(%rbp),%rdi
call   1040 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeOutputData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r15d
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11bb <writeOutputData+0x7b>
mov    %rax,%r13
test   %r15d,%r15d
jle    119d <writeOutputData+0x5d>
shl    $0x2,%r12d
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <writeOutputData+0x40>
mov    %r13,%rdi
call   1040 <fflush@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
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"
define void @writeOutputData(i8* %0, i32 %1, i32 %2, i32** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32** %3, i32*** %8
%12 = load i8*, i8** %5
%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 eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
br label %43
17: ; preds = %4
store i32 0, i32* %9
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load i32**, i32*** %8
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = mul i64 4, %30
%32 = trunc i64 %31 to i32
%33 = load i32*, i32** %11
%34 = call i32 @fwrite(i32* %28, i32 %32, i32 1, i32* %33)
br label %35
35: ; preds = %22
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %18
38: ; preds = %18
%39 = load i32*, i32** %11
%40 = call i32 @fflush(i32* %39)
%41 = load i32*, i32** %11
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %38, %16
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define void @writeOutputData(i8* nocapture %0, i32 %1, i32 %2, i32** nocapture %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %19
9: ; preds = %7
%10 = shl i32 %2, 2
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %17, %12 ]
%14 = getelementptr inbounds i32*, i32** %3, i64 %13
%15 = load i32*, i32** %14
%16 = tail call i32 @fwrite(i32* %15, i32 %10, i32 1, i32* %5)
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12, %7
%20 = tail call i32 @fflush(i32* %5)
%21 = tail call i32 @fclose(i32* %5)
br label %22
22: ; preds = %4, %19
ret void
}