#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int dump_ppm(const char *fname, int width, int depth, unsigned char *red_arry,
             unsigned char *green_arry, unsigned char *blue_arry) {
  FILE *fp;
  int i;
  const char *ext = ".ppm";
  fp = fopen(fname, "w+");
  if (!fp)
    return 0;
  fprintf(fp, "P3\n");
  fprintf(fp, "#  PPM File Name <%s>\n", fname);
  fprintf(fp, "%d # Image Width\n", width);
  fprintf(fp, "%d # Image Depth\n", depth);
  fprintf(fp, "255\n");
  fprintf(fp, "\n#  RGB Data\n");
  for (i = 0; i < (width * depth); i++) {
    fprintf(fp, "%3d %3d %3d", red_arry[i], green_arry[i], blue_arry[i]);
    if (i && !(i % width)) {
      fprintf(fp, "\n");
    } else {
      fprintf(fp, "  ");
    }
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<dump_ppm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1184 <dump_ppm+0x54>
movl   $0x0,-0x4(%rbp)
jmp    12b0 <dump_ppm+0x180>
mov    -0x38(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    12a0 <dump_ppm+0x170>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rsi
movzbl (%rax,%rsi,1),%r8d
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpl   $0x0,-0x3c(%rbp)
je     127b <dump_ppm+0x14b>
mov    -0x3c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    127b <dump_ppm+0x14b>
mov    -0x38(%rbp),%rdi
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    128d <dump_ppm+0x15d>
mov    -0x38(%rbp),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1292 <dump_ppm+0x162>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1201 <dump_ppm+0xd1>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ppm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,0x8(%rsp)
mov    %rcx,%r12
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1277 <dump_ppm+0x127>
mov    %rax,%rbx
lea    0xe70(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe46(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
imul   %r15d,%r14d
test   %r14d,%r14d
jle    1268 <dump_ppm+0x118>
movzbl (%r12),%edx
mov    0x8(%rsp),%rax
movzbl (%rax),%ecx
mov    0x10(%rsp),%rax
movzbl (%rax),%r8d
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe17(%rip),%rdi
mov    $0x1,%r13d
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%r14d
jne    1288 <dump_ppm+0x138>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1279 <dump_ppm+0x129>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%ebp
lea    0xdc3(%rip),%r14
jmp    12c2 <dump_ppm+0x172>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdb0(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0x1,%r13
cmp    %r13,%rbp
je     1268 <dump_ppm+0x118>
movzbl (%r12,%r13,1),%edx
mov    0x8(%rsp),%rax
movzbl (%rax,%r13,1),%ecx
mov    0x10(%rsp),%rax
movzbl (%rax,%r13,1),%r8d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13d,%eax
cltd
idiv   %r15d
test   %edx,%edx
jne    12a0 <dump_ppm+0x150>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    12b9 <dump_ppm+0x169>

LLVM IR (-O0):
@.str = [5 x i8] c".ppm\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"P3\0A\00"
@.str.3 = [23 x i8] c"# PPM File Name <%s>\0A\00"
@.str.4 = [18 x i8] c"%d # Image Width\0A\00"
@.str.5 = [18 x i8] c"%d # Image Depth\0A\00"
@.str.6 = [5 x i8] c"255\0A\00"
@.str.7 = [14 x i8] c"\0A# RGB Data\0A\00"
@.str.8 = [12 x i8] c"%3d %3d %3d\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [3 x i8] c" \00"
define i32 @dump_ppm(i8* %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %16
%17 = load i8*, i8** %8
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %14
%19 = load i32*, i32** %14
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %6
store i32 0, i32* %7
br label %85
22: ; preds = %6
%23 = load i32*, i32** %14
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32*, i32** %14
%26 = load i8*, i8** %8
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %14
%29 = load i32, i32* %9
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %14
%32 = load i32, i32* %10
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** %14
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32*, i32** %14
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %15
br label %38
38: ; preds = %79, %22
%39 = load i32, i32* %15
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = mul nsw i32 %40, %41
%43 = icmp slt i32 %39, %42
br i1 %43, label %44, label %82
44: ; preds = %38
%45 = load i32*, i32** %14
%46 = load i8*, i8** %11
%47 = load i32, i32* %15
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = load i8*, i8** %12
%53 = load i32, i32* %15
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = load i8*, i8** %13
%59 = load i32, i32* %15
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %51, i32 %57, i32 %63)
%65 = load i32, i32* %15
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %75
67: ; preds = %44
%68 = load i32, i32* %15
%69 = load i32, i32* %9
%70 = srem i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %75, label %72
72: ; preds = %67
%73 = load i32*, i32** %14
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %78
75: ; preds = %67, %44
%76 = load i32*, i32** %14
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
br label %78
78: ; preds = %75, %72
br label %79
79: ; preds = %78
%80 = load i32, i32* %15
%81 = add nsw i32 %80, 1
store i32 %81, i32* %15
br label %38
82: ; preds = %38
%83 = load i32*, i32** %14
%84 = call i32 @fclose(i32* %83)
store i32 1, i32* %7
br label %85
85: ; preds = %82, %21
%86 = load i32, i32* %7
ret i32 %86
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"P3\0A\00"
@.str.3 = [23 x i8] c"# PPM File Name <%s>\0A\00"
@.str.4 = [18 x i8] c"%d # Image Width\0A\00"
@.str.5 = [18 x i8] c"%d # Image Depth\0A\00"
@.str.6 = [5 x i8] c"255\0A\00"
@.str.7 = [14 x i8] c"\0A# RGB Data\0A\00"
@.str.8 = [12 x i8] c"%3d %3d %3d\00"
@.str.10 = [3 x i8] c" \00"
define i32 @dump_ppm(i8* %0, i32 %1, i32 %2, i8* nocapture %3, i8* nocapture %4, i8* nocapture %5) {
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %53, label %9
9: ; preds = %6
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %7)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i64 4, i64 1, i32* %7)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i64 13, i64 1, i32* %7)
%16 = mul i32 %2, %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %51
18: ; preds = %9
%19 = zext i32 %16 to i64
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %21, i32 %23, i32 %25)
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 2, i64 1, i32* %7)
%28 = icmp eq i32 %16, 1
br i1 %28, label %51, label %29
29: ; preds = %18, %48
%30 = phi i64 [ %49, %48 ], [ 1, %18 ]
%31 = getelementptr inbounds i8, i8* %3, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = getelementptr inbounds i8, i8* %4, i64 %30
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = getelementptr inbounds i8, i8* %5, i64 %30
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %33, i32 %36, i32 %39)
%41 = trunc i64 %30 to i32
%42 = srem i32 %41, %1
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %29
%45 = tail call i32 @fputc(i32 10, i32* %7)
br label %48
46: ; preds = %29
%47 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 2, i64 1, i32* %7)
br label %48
48: ; preds = %44, %46
%49 = add nuw nsw i64 %30, 1
%50 = icmp eq i64 %49, %19
br i1 %50, label %51, label %29
51: ; preds = %48, %18, %9
%52 = tail call i32 @fclose(i32* %7)
br label %53
53: ; preds = %6, %51
%54 = phi i32 [ 1, %51 ], [ 0, %6 ]
ret i32 %54
}