#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 ppmWriteRGB(FILE *fp, unsigned char *redimg, unsigned char *greenimg,
                 unsigned char *blueimg, int ncols, int nrows) {
  int i, j;
  fprintf(fp, "P6\n");
  fprintf(fp, "%d %d\n", ncols, nrows);
  fprintf(fp, "255\n");
  for (j = 0; j < nrows; j++) {
    for (i = 0; i < ncols; i++) {
      fwrite(redimg, 1, 1, fp);
      fwrite(greenimg, 1, 1, fp);
      fwrite(blueimg, 1, 1, fp);
      redimg++;
      greenimg++;
      blueimg++;
    }
  }
}


x86 assembly (clang, -O0):
<ppmWriteRGB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1223 <ppmWriteRGB+0x103>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1210 <ppmWriteRGB+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1196 <ppmWriteRGB+0x76>
jmp    1215 <ppmWriteRGB+0xf5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1183 <ppmWriteRGB+0x63>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppmWriteRGB>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8d,(%rsp)
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xeab(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fwrite@plt>
lea    0xe96(%rip),%rsi
xor    %r14d,%r14d
mov    %r13,%rdi
mov    (%rsp),%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe83(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fwrite@plt>
mov    %r15d,0x4(%rsp)
test   %r15d,%r15d
jg     11cb <ppmWriteRGB+0x9b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
je     11a4 <ppmWriteRGB+0x74>
mov    (%rsp),%r15d
test   %r15d,%r15d
jle    11c0 <ppmWriteRGB+0x90>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rbx),%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
movsbl 0x0(%rbp),%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
movsbl (%r12),%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
add    $0x1,%rbp
add    $0x1,%r12
add    $0xffffffff,%r15d
jne    11e0 <ppmWriteRGB+0xb0>
jmp    11c0 <ppmWriteRGB+0x90>

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 @ppmWriteRGB(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%15 = load i32*, i32** %7
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = load i32*, i32** %7
%18 = load i32, i32* %11
%19 = load i32, i32* %12
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32*, i32** %7
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %14
br label %23
23: ; preds = %52, %6
%24 = load i32, i32* %14
%25 = load i32, i32* %12
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %55
27: ; preds = %23
store i32 0, i32* %13
br label %28
28: ; preds = %48, %27
%29 = load i32, i32* %13
%30 = load i32, i32* %11
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %51
32: ; preds = %28
%33 = load i8*, i8** %8
%34 = load i32*, i32** %7
%35 = call i32 @fwrite(i8* %33, i32 1, i32 1, i32* %34)
%36 = load i8*, i8** %9
%37 = load i32*, i32** %7
%38 = call i32 @fwrite(i8* %36, i32 1, i32 1, i32* %37)
%39 = load i8*, i8** %10
%40 = load i32*, i32** %7
%41 = call i32 @fwrite(i8* %39, i32 1, i32 1, i32* %40)
%42 = load i8*, i8** %8
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %8
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %9
%46 = load i8*, i8** %10
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %10
br label %48
48: ; preds = %32
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
br label %28
51: ; preds = %28
br label %52
52: ; preds = %51
%53 = load i32, i32* %14
%54 = add nsw i32 %53, 1
store i32 %54, i32* %14
br label %23
55: ; preds = %23
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 @ppmWriteRGB(i32* %0, i8* nocapture %1, i8* nocapture %2, i8* nocapture %3, i32 %4, i32 %5) {
%7 = 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)
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %5)
%9 = 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)
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %43
11: ; preds = %6
%12 = icmp sgt i32 %4, 0
br label %13
13: ; preds = %11, %37
%14 = phi i32 [ 0, %11 ], [ %41, %37 ]
%15 = phi i8* [ %1, %11 ], [ %40, %37 ]
%16 = phi i8* [ %2, %11 ], [ %39, %37 ]
%17 = phi i8* [ %3, %11 ], [ %38, %37 ]
br i1 %12, label %18, label %37
18: ; preds = %13, %18
%19 = phi i32 [ %35, %18 ], [ 0, %13 ]
%20 = phi i8* [ %32, %18 ], [ %15, %13 ]
%21 = phi i8* [ %33, %18 ], [ %16, %13 ]
%22 = phi i8* [ %34, %18 ], [ %17, %13 ]
%23 = load i8, i8* %20
%24 = sext i8 %23 to i32
%25 = tail call i32 @fputc(i32 %24, i32* %0)
%26 = load i8, i8* %21
%27 = sext i8 %26 to i32
%28 = tail call i32 @fputc(i32 %27, i32* %0)
%29 = load i8, i8* %22
%30 = sext i8 %29 to i32
%31 = tail call i32 @fputc(i32 %30, i32* %0)
%32 = getelementptr inbounds i8, i8* %20, i64 1
%33 = getelementptr inbounds i8, i8* %21, i64 1
%34 = getelementptr inbounds i8, i8* %22, i64 1
%35 = add nuw nsw i32 %19, 1
%36 = icmp eq i32 %35, %4
br i1 %36, label %37, label %18
37: ; preds = %18, %13
%38 = phi i8* [ %17, %13 ], [ %34, %18 ]
%39 = phi i8* [ %16, %13 ], [ %33, %18 ]
%40 = phi i8* [ %15, %13 ], [ %32, %18 ]
%41 = add nuw nsw i32 %14, 1
%42 = icmp eq i32 %41, %5
br i1 %42, label %43, label %13
43: ; preds = %37, %6
ret void
}