#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
void ppmWrite(FILE *fp, unsigned char *img, int ncols, int nrows) {
  fprintf(fp, "P6\n");
  fprintf(fp, "%d %d\n", ncols, nrows);
  fprintf(fp, "255\n");
  fwrite(img, ncols * nrows * 3, 1, fp);
}


x86 assembly (clang, -O0):
<ppmWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   $0x3,%eax,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppmWrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xec8(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
lea    0xeb3(%rip),%rsi
mov    %r15,%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xea5(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fwrite@plt>
imul   %ebp,%ebx
lea    (%rbx,%rbx,2),%esi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"P6\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [5 x i8] c"255\0A\00"
define void @ppmWrite(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32*, i32** %5
%10 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %5
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
%15 = load i32*, i32** %5
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = mul nsw i32 %18, %19
%21 = mul nsw i32 %20, 3
%22 = load i32*, i32** %5
%23 = call i32 @fwrite(i8* %17, i32 %21, i32 1, i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"P6\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [5 x i8] c"255\0A\00"
define void @ppmWrite(i32* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 3, i64 1, i32* %0)
%6 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %3)
%7 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %0)
%8 = mul i32 %2, 3
%9 = mul i32 %8, %3
%10 = tail call i32 @fwrite(i8* %1, i32 %9, i32 1, i32* %0)
ret void
}