#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 */

/* Variables and functions */
float M_PI;
int cos(float);
int /*<<< orphan*/ mkimg();
int /*<<< orphan*/ printf(char *, int const, int const, int const);
int main() {
  mkimg();
  const int width = 300, height = 300, maxval = 255;
  printf("P3\n%d %d\n%d\n", width, height, maxval);
  float x, y;
  for (x = 0; x < width; x++) {
    for (y = 0; y < height; y++) {
      int r, g, b;
      r = maxval;
      g = (int)(maxval / 2 * (1 + cos(x / width * 2 * M_PI)));
      b = (int)(maxval / 3 * (2 + cos(y / height * 4 * M_PI)));
      printf("%d %d %d ", r, g, b);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <mkimg@plt>
movl   $0x12c,-0x8(%rbp)
movl   $0x12c,-0xc(%rbp)
movl   $0xff,-0x10(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x12c,%edx
mov    $0xff,%ecx
mov    %edx,%esi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe7d(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    1262 <main+0x132>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xe63(%rip),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1246 <main+0x116>
movl   $0xff,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe45(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe45(%rip),%xmm1
mulss  %xmm1,%xmm0
mov    0x2e16(%rip),%rax
mulss  (%rax),%xmm0
call   1040 <cos@plt>
add    $0x1,%eax
imul   $0x7f,%eax,%eax
mov    %eax,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xe0f(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe0b(%rip),%xmm1
mulss  %xmm1,%xmm0
mov    0x2de0(%rip),%rax
mulss  (%rax),%xmm0
call   1040 <cos@plt>
add    $0x2,%eax
imul   $0x55,%eax,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
movss  0xdcd(%rip),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1195 <main+0x65>
jmp    124b <main+0x11b>
movss  0xdb1(%rip),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    117b <main+0x4b>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <mkimg@plt>
lea    0xebb(%rip),%rdi
mov    $0x12c,%esi
mov    $0x12c,%edx
mov    $0xff,%ecx
call   1030 <printf@plt>
movss  0xe97(%rip),%xmm0
mov    0x2e78(%rip),%r12
lea    0xe9e(%rip),%r15
nopw   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %r14d,%xmm1
divss  %xmm0,%xmm1
addss  %xmm1,%xmm1
movss  %xmm1,0x8(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
movss  %xmm0,0xc(%rsp)
movss  (%r12),%xmm0
mulss  0x8(%rsp),%xmm0
call   1040 <cos@plt>
mov    %eax,%ebp
shl    $0x7,%ebp
sub    %eax,%ebp
add    $0x7f,%ebp
movss  0xc(%rsp),%xmm0
divss  0xe2a(%rip),%xmm0
mulss  0xe26(%rip),%xmm0
mulss  (%r12),%xmm0
call   1040 <cos@plt>
imul   $0x55,%eax,%ecx
add    $0xaa,%ecx
mov    %r15,%rdi
mov    $0xff,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x12c,%ebx
jne    11a0 <main+0x70>
add    $0x1,%r14d
cmp    $0x12c,%r14d
movss  0xde1(%rip),%xmm0
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"P3\0A%d %d\0A%d\0A\00"
@M_PI = global float 0.000000e+00
@.str.1 = [10 x i8] c"%d %d %d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (...) @mkimg()
store i32 300, i32* %2
store i32 300, i32* %3
store i32 255, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 300, i32 300, i32 255)
store float 0.000000e+00, float* %5
br label %12
12: ; preds = %44, %0
%13 = load float, float* %5
%14 = fcmp olt float %13, 3.000000e+02
br i1 %14, label %15, label %47
15: ; preds = %12
store float 0.000000e+00, float* %6
br label %16
16: ; preds = %40, %15
%17 = load float, float* %6
%18 = fcmp olt float %17, 3.000000e+02
br i1 %18, label %19, label %43
19: ; preds = %16
store i32 255, i32* %7
%20 = load float, float* %5
%21 = fdiv float %20, 3.000000e+02
%22 = fmul float %21, 2.000000e+00
%23 = load float, float* @M_PI
%24 = fmul float %22, %23
%25 = call i32 @cos(float %24)
%26 = add nsw i32 1, %25
%27 = mul nsw i32 127, %26
store i32 %27, i32* %8
%28 = load float, float* %6
%29 = fdiv float %28, 3.000000e+02
%30 = fmul float %29, 4.000000e+00
%31 = load float, float* @M_PI
%32 = fmul float %30, %31
%33 = call i32 @cos(float %32)
%34 = add nsw i32 2, %33
%35 = mul nsw i32 85, %34
store i32 %35, i32* %9
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
br label %40
40: ; preds = %19
%41 = load float, float* %6
%42 = fadd float %41, 1.000000e+00
store float %42, float* %6
br label %16
43: ; preds = %16
br label %44
44: ; preds = %43
%45 = load float, float* %5
%46 = fadd float %45, 1.000000e+00
store float %46, float* %5
br label %12
47: ; preds = %12
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [13 x i8] c"P3\0A%d %d\0A%d\0A\00"
@M_PI = global float 0.000000e+00
@.str.1 = [10 x i8] c"%d %d %d \00"
define i32 @main() {
%1 = tail call i32 (...) @mkimg()
%2 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 300, i32 300, i32 255)
br label %3
3: ; preds = %0, %26
%4 = phi i32 [ 0, %0 ], [ %27, %26 ]
%5 = sitofp i32 %4 to float
%6 = fdiv float %5, 3.000000e+02
%7 = fmul float %6, 2.000000e+00
br label %8
8: ; preds = %3, %8
%9 = phi i32 [ 0, %3 ], [ %24, %8 ]
%10 = sitofp i32 %9 to float
%11 = load float, float* @M_PI
%12 = fmul float %7, %11
%13 = tail call i32 @cos(float %12)
%14 = mul i32 %13, 127
%15 = add i32 %14, 127
%16 = fdiv float %10, 3.000000e+02
%17 = fmul float %16, 4.000000e+00
%18 = load float, float* @M_PI
%19 = fmul float %17, %18
%20 = tail call i32 @cos(float %19)
%21 = mul i32 %20, 85
%22 = add i32 %21, 170
%23 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 255, i32 %15, i32 %22)
%24 = add nuw nsw i32 %9, 1
%25 = icmp eq i32 %24, 300
br i1 %25, label %26, label %8
26: ; preds = %8
%27 = add nuw nsw i32 %4, 1
%28 = icmp eq i32 %27, 300
br i1 %28, label %29, label %3
29: ; preds = %26
ret i32 0
}