#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(unsigned char *, int, int, int /*<<< orphan*/ *);
void outputPixels(unsigned char *pixel, int width, int height) {
  FILE *fp = fopen("/tmp/test.bin", "wb");
  for (int y = 0; y < height; y++)
    fwrite(pixel + y * width, sizeof(unsigned char), width, fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<outputPixels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119b <outputPixels+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <outputPixels+0x30>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outputPixels>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xeba(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    117c <outputPixels+0x4c>
movslq %r15d,%r15
mov    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
add    %r15,%rbx
add    $0xffffffffffffffff,%rbp
jne    1160 <outputPixels+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/test.bin\00"
@.str.1 = [3 x i8] c"wb\00"
define void @outputPixels(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %7
store i32 0, i32* %8
br label %10
10: ; preds = %24, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %8
%17 = load i32, i32* %5
%18 = mul nsw i32 %16, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = load i32, i32* %5
%22 = load i32*, i32** %7
%23 = call i32 @fwrite(i8* %20, i32 1, i32 %21, i32* %22)
br label %24
24: ; preds = %14
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %10
27: ; preds = %10
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
ret void
}

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