#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*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int main(void) {
  FILE *image_file;
  int x, y;
  unsigned char r, g, b;
  image_file = fopen("image-file-1.pnm", "wb");
  fputs("P6\n", image_file);
  fputs("500 500\n", image_file);
  fputs("255\n", image_file);
  for (y = 0; y < 500; y++)
    for (x = 0; x < 500; x++) {
      r = 0;
      g = y;
      b = x;
      fputc(r, image_file);
      fputc(g, image_file);
      fputc(b, image_file);
    }
  fclose(image_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x1f4,-0x18(%rbp)
jge    121c <main+0xdc>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1f4,-0x14(%rbp)
jge    1209 <main+0xc9>
movb   $0x0,-0x19(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x1a(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x1b(%rbp)
mov    -0x19(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
mov    -0x1a(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
mov    -0x1b(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b1 <main+0x71>
jmp    120e <main+0xce>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119d <main+0x5d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xeb3(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
lea    0xe9e(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
lea    0xe8e(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %r14b,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%ebp
cmp    $0x1f4,%ebp
jne    11c0 <main+0x80>
add    $0x1,%r14d
cmp    $0x1f4,%r14d
jne    11b0 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"image-file-1.pnm\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [4 x i8] c"P6\0A\00"
@.str.3 = [9 x i8] c"500 500\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
store i32 0, i32* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%11 = load i32*, i32** %2
%12 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %13)
store i32 0, i32* %4
br label %15
15: ; preds = %40, %0
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 500
br i1 %17, label %18, label %43
18: ; preds = %15
store i32 0, i32* %3
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 500
br i1 %21, label %22, label %39
22: ; preds = %19
store i8 0, i8* %5
%23 = load i32, i32* %4
%24 = trunc i32 %23 to i8
store i8 %24, i8* %6
%25 = load i32, i32* %3
%26 = trunc i32 %25 to i8
store i8 %26, i8* %7
%27 = load i8, i8* %5
%28 = load i32*, i32** %2
%29 = call i32 @fputc(i8 zeroext %27, i32* %28)
%30 = load i8, i8* %6
%31 = load i32*, i32** %2
%32 = call i32 @fputc(i8 zeroext %30, i32* %31)
%33 = load i8, i8* %7
%34 = load i32*, i32** %2
%35 = call i32 @fputc(i8 zeroext %33, i32* %34)
br label %36
36: ; preds = %22
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %19
39: ; preds = %19
br label %40
40: ; preds = %39
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %15
43: ; preds = %15
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"image-file-1.pnm\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [4 x i8] c"P6\0A\00"
@.str.3 = [9 x i8] c"500 500\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %1)
%3 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 8, i64 1, i32* %1)
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 4, i64 1, i32* %1)
br label %5
5: ; preds = %0, %16
%6 = phi i32 [ 0, %0 ], [ %17, %16 ]
%7 = trunc i32 %6 to i8
br label %8
8: ; preds = %5, %8
%9 = phi i32 [ 0, %5 ], [ %14, %8 ]
%10 = trunc i32 %9 to i8
%11 = tail call i32 @fputc(i8 zeroext 0, i32* %1)
%12 = tail call i32 @fputc(i8 zeroext %7, i32* %1)
%13 = tail call i32 @fputc(i8 zeroext %10, i32* %1)
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, 500
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = add nuw nsw i32 %6, 1
%18 = icmp eq i32 %17, 500
br i1 %18, label %19, label %5
19: ; preds = %16
%20 = tail call i32 @fclose(i32* %1)
ret i32 0
}