#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ ppm_write(char *, int, int, int **, int, int);
int main() {
  uint8_t rgb[255 * 255][3];
  int i, j;
  for (i = 0; i < 255; i++) {
    for (j = 0; j < 255; j++) {
      rgb[255 * i + j][0] = i;
      rgb[255 * i + j][1] = j;
      rgb[255 * i + j][2] = (i * j) % 256;
    }
  }
  ppm_write("raw.ppm", 255, 255, rgb, 255, false);
  ppm_write("plain.ppm", 255, 255, rgb, 255, true);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbe820,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xbe814(%rbp)
cmpl   $0xff,-0xbe814(%rbp)
jge    120f <main+0xff>
movl   $0x0,-0xbe818(%rbp)
cmpl   $0xff,-0xbe818(%rbp)
jge    11f6 <main+0xe6>
mov    -0xbe814(%rbp),%ecx
imul   $0xff,-0xbe814(%rbp),%eax
add    -0xbe818(%rbp),%eax
movslq %eax,%rdx
lea    -0xbe810(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
mov    -0xbe818(%rbp),%ecx
imul   $0xff,-0xbe814(%rbp),%eax
add    -0xbe818(%rbp),%eax
movslq %eax,%rdx
lea    -0xbe810(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0xbe814(%rbp),%eax
imul   -0xbe818(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
imul   $0xff,-0xbe814(%rbp),%eax
add    -0xbe818(%rbp),%eax
movslq %eax,%rcx
lea    -0xbe810(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    %edx,0x8(%rax)
mov    -0xbe818(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbe818(%rbp)
jmp    1146 <main+0x36>
jmp    11fb <main+0xeb>
mov    -0xbe814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbe814(%rbp)
jmp    112c <main+0x1c>
lea    -0xbe810(%rbp),%rcx
lea    0xde3(%rip),%rdi
mov    $0xff,%r8d
xor    %r9d,%r9d
mov    %r8d,%esi
mov    %r8d,%edx
call   1030 <ppm_write@plt>
lea    -0xbe810(%rbp),%rcx
lea    0xdc9(%rip),%rdi
mov    $0xff,%r8d
mov    $0x1,%r9d
mov    %r8d,%esi
mov    %r8d,%edx
call   1030 <ppm_write@plt>
xor    %eax,%eax
add    $0xbe820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xbe810,%rsp
lea    0x14(%rsp),%r8
xor    %ecx,%ecx
xor    %edx,%edx
jmp    1147 <main+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rdx
add    $0xbf4,%r8
add    $0x2,%ecx
cmp    $0xff,%rdx
je     118b <main+0x7b>
xor    %esi,%esi
mov    %r8,%rdi
xor    %eax,%eax
xchg   %ax,%ax
mov    %edx,-0x14(%rdi)
mov    %eax,-0x10(%rdi)
mov    %esi,%ebx
and    $0xfe,%ebx
mov    %ebx,-0xc(%rdi)
mov    %rax,%rbx
or     $0x1,%rbx
cmp    $0xff,%rbx
je     1130 <main+0x20>
mov    %edx,-0x8(%rdi)
mov    %ebx,-0x4(%rdi)
lea    (%rdx,%rsi,1),%ebx
movzbl %bl,%ebx
mov    %ebx,(%rdi)
add    $0x2,%rax
add    $0x18,%rdi
add    %ecx,%esi
jmp    1150 <main+0x40>
lea    0xe6e(%rip),%rdi
mov    %rsp,%rbx
mov    $0xff,%esi
mov    $0xff,%edx
mov    %rbx,%rcx
mov    $0xff,%r8d
xor    %r9d,%r9d
call   1030 <ppm_write@plt>
lea    0xe51(%rip),%rdi
mov    $0xff,%esi
mov    $0xff,%edx
mov    %rbx,%rcx
mov    $0xff,%r8d
mov    $0x1,%r9d
call   1030 <ppm_write@plt>
xor    %eax,%eax
add    $0xbe810,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"raw.ppm\00"
@.str.1 = [10 x i8] c"plain.ppm\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [65025 x [3 x i32]]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %44, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 255
br i1 %7, label %8, label %47
8: ; preds = %5
store i32 0, i32* %4
br label %9
9: ; preds = %40, %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 255
br i1 %11, label %12, label %43
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %3
%15 = mul nsw i32 255, %14
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %2, i64 0, i64 %18
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %19, i64 0, i64 0
store i32 %13, i32* %20
%21 = load i32, i32* %4
%22 = load i32, i32* %3
%23 = mul nsw i32 255, %22
%24 = load i32, i32* %4
%25 = add nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %2, i64 0, i64 %26
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %27, i64 0, i64 1
store i32 %21, i32* %28
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = mul nsw i32 %29, %30
%32 = srem i32 %31, 256
%33 = load i32, i32* %3
%34 = mul nsw i32 255, %33
%35 = load i32, i32* %4
%36 = add nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %2, i64 0, i64 %37
%39 = getelementptr inbounds [3 x i32], [3 x i32]* %38, i64 0, i64 2
store i32 %32, i32* %39
br label %40
40: ; preds = %12
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %9
43: ; preds = %9
br label %44
44: ; preds = %43
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %5
47: ; preds = %5
%48 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %2, i64 0, i64 0
%49 = bitcast [3 x i32]* %48 to i32**
%50 = call i32 @ppm_write(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 255, i32 255, i32** %49, i32 255, i32 0)
%51 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %2, i64 0, i64 0
%52 = bitcast [3 x i32]* %51 to i32**
%53 = call i32 @ppm_write(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 255, i32 255, i32** %52, i32 255, i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"raw.ppm\00"
@.str.1 = [10 x i8] c"plain.ppm\00"
define i32 @main() {
%1 = alloca [65025 x [3 x i32]]
%2 = bitcast [65025 x [3 x i32]]* %1 to i8*
br label %3
3: ; preds = %0, %29
%4 = phi i64 [ 0, %0 ], [ %30, %29 ]
%5 = mul nuw nsw i64 %4, 255
%6 = trunc i64 %4 to i32
br label %7
7: ; preds = %19, %3
%8 = phi i64 [ 0, %3 ], [ %28, %19 ]
%9 = add nuw nsw i64 %8, %5
%10 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %1, i64 0, i64 %9, i64 0
store i32 %6, i32* %10
%11 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %1, i64 0, i64 %9, i64 1
%12 = trunc i64 %8 to i32
store i32 %12, i32* %11
%13 = mul nuw nsw i64 %8, %4
%14 = trunc i64 %13 to i32
%15 = and i32 %14, 254
%16 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %1, i64 0, i64 %9, i64 2
store i32 %15, i32* %16
%17 = or i64 %8, 1
%18 = icmp eq i64 %17, 255
br i1 %18, label %29, label %19
19: ; preds = %7
%20 = add nuw nsw i64 %17, %5
%21 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %1, i64 0, i64 %20, i64 0
store i32 %6, i32* %21
%22 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %1, i64 0, i64 %20, i64 1
%23 = trunc i64 %17 to i32
store i32 %23, i32* %22
%24 = mul nuw nsw i64 %17, %4
%25 = trunc i64 %24 to i32
%26 = and i32 %25, 255
%27 = getelementptr inbounds [65025 x [3 x i32]], [65025 x [3 x i32]]* %1, i64 0, i64 %20, i64 2
store i32 %26, i32* %27
%28 = add nuw nsw i64 %8, 2
br label %7
29: ; preds = %7
%30 = add nuw nsw i64 %4, 1
%31 = icmp eq i64 %30, 255
br i1 %31, label %32, label %3
32: ; preds = %29
%33 = bitcast [65025 x [3 x i32]]* %1 to i32**
%34 = call i32 @ppm_write(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 255, i32 255, i32** %33, i32 255, i32 0)
%35 = call i32 @ppm_write(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 255, i32 255, i32** %33, i32 255, i32 1)
ret i32 0
}