#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*/ drawFlatTriangle(unsigned short *, int, int, int, int, int,
                                    int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int main() {
  static unsigned short vram[(640) * (480)];
  FILE *f;
  int i;
  drawFlatTriangle(vram, 50, 50, 0, 0, 100, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 50, 50, 0, 100, 100, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 150, 50, 200, 0, 300, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 150, 50, 200, 200, 300, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, -10, 250, 50, 200, 100, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, -10, 250, 50, 300, 100, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 660, 250, 600, 200, 550, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 660, 250, 600, 300, 550, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 320, 600, 300, 690, 340, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 300, 200, 300, 280, 340, 0xf00, 0x0f0, 0x00f);
  drawFlatTriangle(vram, 300, 200, 300, 120, 340, 0xf00, 0x0f0, 0x00f);
  f = fopen("localram.ppm", "wb");
  fprintf(f, "P6\n640 480\n15\n");
  for (i = 0; i < (640) * (480); ++i) {
    fprintf(f, "%c", ((vram[i]) >> 8) & 0xf);
    fprintf(f, "%c", ((vram[i]) >> 4) & 0xf);
    fprintf(f, "%c", ((vram[i]) >> 0) & 0xf);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2efa(%rip),%rdi
mov    $0x32,%edx
xor    %r8d,%r8d
mov    $0x64,%r9d
mov    %edx,%esi
mov    %r8d,%ecx
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2ec4(%rip),%rdi
mov    $0x32,%edx
xor    %ecx,%ecx
mov    $0x64,%r9d
mov    %edx,%esi
mov    %r9d,%r8d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2e8f(%rip),%rdi
mov    $0x96,%esi
mov    $0x32,%edx
mov    $0xc8,%ecx
xor    %r8d,%r8d
mov    $0x12c,%r9d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2e54(%rip),%rdi
mov    $0x96,%esi
mov    $0x32,%edx
mov    $0xc8,%r8d
mov    $0x12c,%r9d
mov    %r8d,%ecx
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2e18(%rip),%rdi
mov    $0xfffffff6,%esi
mov    $0xfa,%edx
mov    $0x32,%ecx
mov    $0xc8,%r8d
mov    $0x64,%r9d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2dda(%rip),%rdi
mov    $0xfffffff6,%esi
mov    $0xfa,%edx
mov    $0x32,%ecx
mov    $0x12c,%r8d
mov    $0x64,%r9d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2d9c(%rip),%rdi
mov    $0x294,%esi
mov    $0xfa,%edx
mov    $0x258,%ecx
mov    $0xc8,%r8d
mov    $0x226,%r9d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2d5e(%rip),%rdi
mov    $0x294,%esi
mov    $0xfa,%edx
mov    $0x258,%ecx
mov    $0x12c,%r8d
mov    $0x226,%r9d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2d20(%rip),%rdi
mov    $0x140,%esi
mov    $0x258,%edx
mov    $0x12c,%ecx
mov    $0x2b2,%r8d
mov    $0x154,%r9d
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2ce2(%rip),%rdi
mov    $0x12c,%ecx
mov    $0xc8,%edx
mov    $0x118,%r8d
mov    $0x154,%r9d
mov    %ecx,%esi
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0x2ca7(%rip),%rdi
mov    $0x12c,%ecx
mov    $0xc8,%edx
mov    $0x78,%r8d
mov    $0x154,%r9d
mov    %ecx,%esi
movl   $0xf00,(%rsp)
movl   $0xf0,0x8(%rsp)
movl   $0xf,0x10(%rsp)
call   1030 <drawFlatTriangle@plt>
lea    0xc1c(%rip),%rdi
lea    0xc22(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xc11(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4b000,-0x14(%rbp)
jge    149d <main+0x35d>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2c27(%rip),%rax
movzwl (%rax,%rcx,2),%edx
sar    $0x8,%edx
and    $0xf,%edx
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2c00(%rip),%rax
movzwl (%rax,%rcx,2),%edx
sar    $0x4,%edx
and    $0xf,%edx
lea    0xbbe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2bd9(%rip),%rax
movzwl (%rax,%rcx,2),%edx
sar    $0x0,%edx
and    $0xf,%edx
lea    0xb97(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    140d <main+0x2cd>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x8,%rsp
lea    0x2f00(%rip),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
mov    $0x32,%esi
mov    $0x32,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x64,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x32,%esi
mov    $0x32,%edx
xor    %ecx,%ecx
mov    $0x64,%r8d
mov    $0x64,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x96,%esi
mov    $0x32,%edx
mov    $0xc8,%ecx
xor    %r8d,%r8d
mov    $0x12c,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x96,%esi
mov    $0x32,%edx
mov    $0xc8,%ecx
mov    $0xc8,%r8d
mov    $0x12c,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0xfffffff6,%esi
mov    $0xfa,%edx
mov    $0x32,%ecx
mov    $0xc8,%r8d
mov    $0x64,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0xfffffff6,%esi
mov    $0xfa,%edx
mov    $0x32,%ecx
mov    $0x12c,%r8d
mov    $0x64,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x294,%esi
mov    $0xfa,%edx
mov    $0x258,%ecx
mov    $0xc8,%r8d
mov    $0x226,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x294,%esi
mov    $0xfa,%edx
mov    $0x258,%ecx
mov    $0x12c,%r8d
mov    $0x226,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x140,%esi
mov    $0x258,%edx
mov    $0x12c,%ecx
mov    $0x2b2,%r8d
mov    $0x154,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x12c,%esi
mov    $0xc8,%edx
mov    $0x12c,%ecx
mov    $0x118,%r8d
mov    $0x154,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x18,%rsp
mov    %r14,%rdi
mov    $0x12c,%esi
mov    $0xc8,%edx
mov    $0x12c,%ecx
mov    $0x78,%r8d
mov    $0x154,%r9d
push   $0xf
push   $0xf0
push   $0xf00
call   1030 <drawFlatTriangle@plt>
add    $0x20,%rsp
lea    0xc71(%rip),%rdi
lea    0xc77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xc6b(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%r15,%r14,1),%edi
and    $0xf,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
movzwl (%r15,%r14,1),%edi
shr    $0x4,%edi
and    $0xf,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
movzwl (%r15,%r14,1),%edi
and    $0xf,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x2,%r15
cmp    $0x96000,%r15
jne    13c0 <main+0x270>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.vram = internal global [307200 x i16] zeroinitializer
@.str = [13 x i8] c"localram.ppm\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [15 x i8] c"P6\0A640 480\0A15\0A\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 50, i32 50, i32 0, i32 0, i32 100, i32 3840, i32 240, i32 15)
%5 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 50, i32 50, i32 0, i32 100, i32 100, i32 3840, i32 240, i32 15)
%6 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 150, i32 50, i32 200, i32 0, i32 300, i32 3840, i32 240, i32 15)
%7 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 150, i32 50, i32 200, i32 200, i32 300, i32 3840, i32 240, i32 15)
%8 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 -10, i32 250, i32 50, i32 200, i32 100, i32 3840, i32 240, i32 15)
%9 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 -10, i32 250, i32 50, i32 300, i32 100, i32 3840, i32 240, i32 15)
%10 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 660, i32 250, i32 600, i32 200, i32 550, i32 3840, i32 240, i32 15)
%11 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 660, i32 250, i32 600, i32 300, i32 550, i32 3840, i32 240, i32 15)
%12 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 320, i32 600, i32 300, i32 690, i32 340, i32 3840, i32 240, i32 15)
%13 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 300, i32 200, i32 300, i32 280, i32 340, i32 3840, i32 240, i32 15)
%14 = call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 300, i32 200, i32 300, i32 120, i32 340, i32 3840, i32 240, i32 15)
%15 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %18
18: ; preds = %49, %0
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 307200
br i1 %20, label %21, label %52
21: ; preds = %18
%22 = load i32*, i32** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 %24
%26 = load i16, i16* %25
%27 = zext i16 %26 to i32
%28 = ashr i32 %27, 8
%29 = and i32 %28, 15
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 %33
%35 = load i16, i16* %34
%36 = zext i16 %35 to i32
%37 = ashr i32 %36, 4
%38 = and i32 %37, 15
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %2
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 %42
%44 = load i16, i16* %43
%45 = zext i16 %44 to i32
%46 = ashr i32 %45, 0
%47 = and i32 %46, 15
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %21
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %18
52: ; preds = %18
%53 = load i32*, i32** %2
%54 = call i32 @fclose(i32* %53)
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@main.vram = internal global [307200 x i16] zeroinitializer
@.str = [13 x i8] c"localram.ppm\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [15 x i8] c"P6\0A640 480\0A15\0A\00"
define i32 @main() {
%1 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 50, i32 50, i32 0, i32 0, i32 100, i32 3840, i32 240, i32 15)
%2 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 50, i32 50, i32 0, i32 100, i32 100, i32 3840, i32 240, i32 15)
%3 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 150, i32 50, i32 200, i32 0, i32 300, i32 3840, i32 240, i32 15)
%4 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 150, i32 50, i32 200, i32 200, i32 300, i32 3840, i32 240, i32 15)
%5 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 -10, i32 250, i32 50, i32 200, i32 100, i32 3840, i32 240, i32 15)
%6 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 -10, i32 250, i32 50, i32 300, i32 100, i32 3840, i32 240, i32 15)
%7 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 660, i32 250, i32 600, i32 200, i32 550, i32 3840, i32 240, i32 15)
%8 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 660, i32 250, i32 600, i32 300, i32 550, i32 3840, i32 240, i32 15)
%9 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 320, i32 600, i32 300, i32 690, i32 340, i32 3840, i32 240, i32 15)
%10 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 300, i32 200, i32 300, i32 280, i32 340, i32 3840, i32 240, i32 15)
%11 = tail call i32 @drawFlatTriangle(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 0), i32 300, i32 200, i32 300, i32 120, i32 340, i32 3840, i32 240, i32 15)
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 14, i64 1, i32* %12)
br label %14
14: ; preds = %0, %14
%15 = phi i64 [ 0, %0 ], [ %31, %14 ]
%16 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.vram, i64 0, i64 %15
%17 = load i16, i16* %16
%18 = lshr i16 %17, 8
%19 = and i16 %18, 15
%20 = zext i16 %19 to i32
%21 = tail call i32 @fputc(i32 %20, i32* %12)
%22 = load i16, i16* %16
%23 = lshr i16 %22, 4
%24 = and i16 %23, 15
%25 = zext i16 %24 to i32
%26 = tail call i32 @fputc(i32 %25, i32* %12)
%27 = load i16, i16* %16
%28 = and i16 %27, 15
%29 = zext i16 %28 to i32
%30 = tail call i32 @fputc(i32 %29, i32* %12)
%31 = add nuw nsw i64 %15, 1
%32 = icmp eq i64 %31, 307200
br i1 %32, label %33, label %14
33: ; preds = %14
%34 = tail call i32 @fclose(i32* %12)
ret i32 0
}