#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 M_PI;
int /*<<< orphan*/ clearScreen(unsigned short *);
double cos(int);
int /*<<< orphan*/ drawLine(unsigned short *, int, int, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ line(unsigned short *, int, int, short, short, double,
                        unsigned short);
double sin(int);
int main() {
  static unsigned short v[(640) * (480)];
  static unsigned short color[] = {0x00f, 0x0f0, 0xf00, 0xf0f, 0x0ff,
                                   0xf0f, 0xfff, 0x008, 0x080, 0x800,
                                   0x808, 0x088, 0x808, 0x888};
  int i, j;
  int xh = (640) / 2;
  int yh = (480) / 2;
  FILE *f;
  clearScreen(&v[0]);
  for (i = 0, j = 0; i < 360; i = i + 30, j = j + 1) {
    double c = cos(i * M_PI / 180.0);
    double s = sin(i * M_PI / 180.0);
    int x = xh + (10.0) * c;
    int y = yh + (10.0) * s;
    line(&v[0], x, y, (short)(c * 10000.0), (short)(s * 10000.0), (100.0),
         color[j]);
  }
  drawLine(&v[0], 0, 0, 639, 20, 0xfff);
  drawLine(&v[0], 0, 20, 639, 0, 0xf00);
  drawLine(&v[0], 0, 0, 20, 479, 0x0f0);
  drawLine(&v[0], 20, 0, 0, 479, 0x00f);
  f = fopen("localram.ppm", "wb");
  fprintf(f, "P6\n640 480\n15\n");
  for (i = 0; i < (640) * (480); ++i) {
    fprintf(f, "%c", ((v[i] >> 8) & 0xf));
    fprintf(f, "%c", ((v[i] >> 4) & 0xf));
    fprintf(f, "%c", ((v[i] >> 0) & 0xf));
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x140,-0x10(%rbp)
movl   $0xf0,-0x14(%rbp)
lea    0x2efc(%rip),%rdi
call   1070 <clearScreen@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x168,-0x8(%rbp)
jge    12cc <main+0x14c>
mov    -0x8(%rbp),%eax
mov    0x2e1a(%rip),%rcx
mov    %rcx,-0x48(%rbp)
mov    (%rcx),%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe25(%rip),%xmm1
movsd  %xmm1,-0x40(%rbp)
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <cos@plt>
mov    -0x48(%rbp),%rcx
movsd  -0x40(%rbp),%xmm1
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    (%rcx),%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xddd(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
movsd  -0x28(%rbp),%xmm0
movsd  0xdaa(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%cx
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%r8w
movslq -0xc(%rbp),%r9
lea    0x2e0b(%rip),%rdi
movsd  0xd63(%rip),%xmm0
lea    0x2dcc(%rip),%rax
movswl %cx,%ecx
movswl %r8w,%r8d
movzwl (%rax,%r9,2),%r9d
call   10a0 <line@plt>
mov    -0x8(%rbp),%eax
add    $0x1e,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b7 <main+0x37>
lea    0x2dcd(%rip),%rdi
xor    %edx,%edx
mov    $0x27f,%ecx
mov    $0x14,%r8d
mov    $0xfff,%r9d
mov    %edx,%esi
call   1030 <drawLine@plt>
lea    0x2dac(%rip),%rdi
xor    %r8d,%r8d
mov    $0x14,%edx
mov    $0x27f,%ecx
mov    $0xf00,%r9d
mov    %r8d,%esi
call   1030 <drawLine@plt>
lea    0x2d8a(%rip),%rdi
xor    %edx,%edx
mov    $0x14,%ecx
mov    $0x1df,%r8d
mov    $0xf0,%r9d
mov    %edx,%esi
call   1030 <drawLine@plt>
lea    0x2d69(%rip),%rdi
mov    $0x14,%esi
xor    %ecx,%ecx
mov    $0x1df,%r8d
mov    $0xf,%r9d
mov    %ecx,%edx
call   1030 <drawLine@plt>
lea    0xcc8(%rip),%rdi
lea    0xcce(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4b000,-0x8(%rbp)
jge    1411 <main+0x291>
mov    -0x20(%rbp),%rdi
movslq -0x8(%rbp),%rcx
lea    0x2d03(%rip),%rax
movzwl (%rax,%rcx,2),%edx
sar    $0x8,%edx
and    $0xf,%edx
lea    0xc91(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
movslq -0x8(%rbp),%rcx
lea    0x2cdc(%rip),%rax
movzwl (%rax,%rcx,2),%edx
sar    $0x4,%edx
and    $0xf,%edx
lea    0xc6a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
movslq -0x8(%rbp),%rcx
lea    0x2cb5(%rip),%rax
movzwl (%rax,%rcx,2),%edx
sar    $0x0,%edx
and    $0xf,%edx
lea    0xc43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1381 <main+0x201>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0x2ee1(%rip),%r14
mov    %r14,%rdi
call   1070 <clearScreen@plt>
lea    0xe82(%rip),%r15
xor    %ebx,%ebx
mov    0x2e31(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    (%r12),%eax
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe2a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <cos@plt>
mov    (%r12),%eax
imul   %ebx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm0,(%rsp)
divsd  0xe02(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1060 <sin@plt>
movsd  (%rsp),%xmm3
movapd %xmm3,%xmm1
movsd  0xdf0(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  0xdec(%rip),%xmm1
cvttsd2si %xmm1,%esi
movapd %xmm0,%xmm1
mulsd  %xmm2,%xmm1
addsd  0xde0(%rip),%xmm1
cvttsd2si %xmm1,%edx
movsd  0xddc(%rip),%xmm1
movapd %xmm3,%xmm2
mulsd  %xmm1,%xmm2
cvttsd2si %xmm2,%eax
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movzwl (%r15),%r9d
movswl %ax,%ecx
movswl %di,%r8d
mov    %r14,%rdi
movsd  0xdba(%rip),%xmm0
call   10a0 <line@plt>
add    $0x2,%r15
add    $0x1e,%rbx
cmp    $0x168,%rbx
jne    11c0 <main+0x30>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x27f,%ecx
mov    $0x14,%r8d
mov    $0xfff,%r9d
call   1030 <drawLine@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
mov    $0x27f,%ecx
xor    %r8d,%r8d
mov    $0xf00,%r9d
call   1030 <drawLine@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x14,%ecx
mov    $0x1df,%r8d
mov    $0xf0,%r9d
call   1030 <drawLine@plt>
mov    %r14,%rdi
mov    $0x14,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x1df,%r8d
mov    $0xf,%r9d
call   1030 <drawLine@plt>
lea    0xd47(%rip),%rdi
lea    0xd4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xd41(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
nopl   (%rax)
movzbl 0x1(%rbx,%r14,1),%edi
and    $0xf,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
movzwl (%rbx,%r14,1),%edi
shr    $0x4,%edi
and    $0xf,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
movzwl (%rbx,%r14,1),%edi
and    $0xf,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0x2,%rbx
cmp    $0x96000,%rbx
jne    1330 <main+0x1a0>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.v = internal global [307200 x i16] zeroinitializer
@main.color = internal global [14 x i16] [i16 15, i16 240, i16 3840, i16 3855, i16 255, i16 3855, i16 4095, i16 8, i16 128, i16 2048, i16 2056, i16 136, i16 2056, i16 2184]
@M_PI = global i32 0
@.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
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 320, i32* %4
store i32 240, i32* %5
%11 = call i32 @clearScreen(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0))
store i32 0, i32* %2
store i32 0, i32* %3
br label %12
12: ; preds = %53, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 360
br i1 %14, label %15, label %58
15: ; preds = %12
%16 = load i32, i32* %2
%17 = load i32, i32* @M_PI
%18 = mul nsw i32 %16, %17
%19 = sitofp i32 %18 to double
%20 = fdiv double %19, 1.800000e+02
%21 = fptosi double %20 to i32
%22 = call double @cos(i32 %21)
store double %22, double* %7
%23 = load i32, i32* %2
%24 = load i32, i32* @M_PI
%25 = mul nsw i32 %23, %24
%26 = sitofp i32 %25 to double
%27 = fdiv double %26, 1.800000e+02
%28 = fptosi double %27 to i32
%29 = call double @sin(i32 %28)
store double %29, double* %8
%30 = load i32, i32* %4
%31 = sitofp i32 %30 to double
%32 = load double, double* %7
%33 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %32, double %31)
%34 = fptosi double %33 to i32
store i32 %34, i32* %9
%35 = load i32, i32* %5
%36 = sitofp i32 %35 to double
%37 = load double, double* %8
%38 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %37, double %36)
%39 = fptosi double %38 to i32
store i32 %39, i32* %10
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = load double, double* %7
%43 = fmul double %42, 1.000000e+04
%44 = fptosi double %43 to i16
%45 = load double, double* %8
%46 = fmul double %45, 1.000000e+04
%47 = fptosi double %46 to i16
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [14 x i16], [14 x i16]* @main.color, i64 0, i64 %49
%51 = load i16, i16* %50
%52 = call i32 @line(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 %40, i32 %41, i16 signext %44, i16 signext %47, double 1.000000e+02, i16 zeroext %51)
br label %53
53: ; preds = %15
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 30
store i32 %55, i32* %2
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %12
58: ; preds = %12
%59 = call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 0, i32 0, i32 639, i32 20, i32 4095)
%60 = call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 0, i32 20, i32 639, i32 0, i32 3840)
%61 = call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 0, i32 0, i32 20, i32 479, i32 240)
%62 = call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 20, i32 0, i32 0, i32 479, i32 15)
%63 = 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* %63, i32** %6
%64 = load i32*, i32** %6
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %66
66: ; preds = %97, %58
%67 = load i32, i32* %2
%68 = icmp slt i32 %67, 307200
br i1 %68, label %69, label %100
69: ; preds = %66
%70 = load i32*, i32** %6
%71 = load i32, i32* %2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.v, i64 0, i64 %72
%74 = load i16, i16* %73
%75 = zext i16 %74 to i32
%76 = ashr i32 %75, 8
%77 = and i32 %76, 15
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %77)
%79 = load i32*, i32** %6
%80 = load i32, i32* %2
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.v, i64 0, i64 %81
%83 = load i16, i16* %82
%84 = zext i16 %83 to i32
%85 = ashr i32 %84, 4
%86 = and i32 %85, 15
%87 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %86)
%88 = load i32*, i32** %6
%89 = load i32, i32* %2
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.v, i64 0, i64 %90
%92 = load i16, i16* %91
%93 = zext i16 %92 to i32
%94 = ashr i32 %93, 0
%95 = and i32 %94, 15
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %69
%98 = load i32, i32* %2
%99 = add nsw i32 %98, 1
store i32 %99, i32* %2
br label %66
100: ; preds = %66
%101 = load i32*, i32** %6
%102 = call i32 @fclose(i32* %101)
ret i32 0
}

LLVM IR (-O2):
@main.v = internal global [307200 x i16] zeroinitializer
@main.color = internal unnamed_addr constant [14 x i16] [i16 15, i16 240, i16 3840, i16 3855, i16 255, i16 3855, i16 4095, i16 8, i16 128, i16 2048, i16 2056, i16 136, i16 2056, i16 2184]
@M_PI = global i32 0
@.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 @clearScreen(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %29, %2 ]
%4 = phi i32 [ 0, %0 ], [ %28, %2 ]
%5 = load i32, i32* @M_PI
%6 = mul nsw i32 %5, %4
%7 = sitofp i32 %6 to double
%8 = fdiv double %7, 1.800000e+02
%9 = fptosi double %8 to i32
%10 = tail call double @cos(i32 %9)
%11 = load i32, i32* @M_PI
%12 = mul nsw i32 %11, %4
%13 = sitofp i32 %12 to double
%14 = fdiv double %13, 1.800000e+02
%15 = fptosi double %14 to i32
%16 = tail call double @sin(i32 %15)
%17 = tail call double @llvm.fmuladd.f64(double %10, double 1.000000e+01, double 3.200000e+02)
%18 = fptosi double %17 to i32
%19 = tail call double @llvm.fmuladd.f64(double %16, double 1.000000e+01, double 2.400000e+02)
%20 = fptosi double %19 to i32
%21 = fmul double %10, 1.000000e+04
%22 = fptosi double %21 to i16
%23 = fmul double %16, 1.000000e+04
%24 = fptosi double %23 to i16
%25 = getelementptr inbounds [14 x i16], [14 x i16]* @main.color, i64 0, i64 %3
%26 = load i16, i16* %25
%27 = tail call i32 @line(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 %18, i32 %20, i16 signext %22, i16 signext %24, double 1.000000e+02, i16 zeroext %26)
%28 = add nuw nsw i32 %4, 30
%29 = add nuw nsw i64 %3, 1
%30 = icmp eq i64 %29, 12
br i1 %30, label %31, label %2
31: ; preds = %2
%32 = tail call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 0, i32 0, i32 639, i32 20, i32 4095)
%33 = tail call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 0, i32 20, i32 639, i32 0, i32 3840)
%34 = tail call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 0, i32 0, i32 20, i32 479, i32 240)
%35 = tail call i32 @drawLine(i16* getelementptr inbounds ([307200 x i16], [307200 x i16]* @main.v, i64 0, i64 0), i32 20, i32 0, i32 0, i32 479, i32 15)
%36 = 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))
%37 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 14, i64 1, i32* %36)
br label %38
38: ; preds = %31, %38
%39 = phi i64 [ 0, %31 ], [ %55, %38 ]
%40 = getelementptr inbounds [307200 x i16], [307200 x i16]* @main.v, i64 0, i64 %39
%41 = load i16, i16* %40
%42 = lshr i16 %41, 8
%43 = and i16 %42, 15
%44 = zext i16 %43 to i32
%45 = tail call i32 @fputc(i32 %44, i32* %36)
%46 = load i16, i16* %40
%47 = lshr i16 %46, 4
%48 = and i16 %47, 15
%49 = zext i16 %48 to i32
%50 = tail call i32 @fputc(i32 %49, i32* %36)
%51 = load i16, i16* %40
%52 = and i16 %51, 15
%53 = zext i16 %52 to i32
%54 = tail call i32 @fputc(i32 %53, i32* %36)
%55 = add nuw nsw i64 %39, 1
%56 = icmp eq i64 %55, 307200
br i1 %56, label %57, label %38
57: ; preds = %38
%58 = tail call i32 @fclose(i32* %36)
ret i32 0
}