#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 cos(int);
scalar_t__ fabs(double);
scalar_t__ fclose(int /*<<< orphan*/ *);
double floor(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, ...);
int /*<<< orphan*/ printf(char *);
double sin(int);
int main() {
  int height = 200;
  int width = 200;
  int col = 0;
  int i, j;
  FILE *fout;
  fout = fopen("ImageOutput3.ppm", "w");
  fprintf(fout, "P3\n%d %d\n255\n", width, height);
  for (i = 1; i <= width; i++) {
    for (j = 1; j <= height; j++) {
      col = (int)fabs(255.0 * sin(i / 10.0) * floor(cos(j / 10.0)));
      fprintf(fout, "%d\n%d\n%d\n", col, col * cos(i / 10.0),
              col * cos(i / 10.0));
    }
  }
  if (fclose(fout) != 0) {
    printf("There was an error in closing the file.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc8,-0x8(%rbp)
movl   $0xc8,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe65(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12f6 <main+0x176>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12e3 <main+0x163>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xdfa(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xdea(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xdcc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <cos@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <fabs@plt>
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xd83(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <cos@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xd58(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <cos@plt>
mov    -0x34(%rbp),%r8d
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
imul   %eax,%r8d
lea    0xd63(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ed <main+0x6d>
jmp    12e8 <main+0x168>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <main+0x5a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1315 <main+0x195>
lea    0xd2b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe83(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe80(%rip),%rsi
mov    %rax,%rdi
mov    $0xc8,%edx
mov    $0xc8,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
movsd  0xe34(%rip),%xmm0
movsd  0xe34(%rip),%xmm1
lea    0xe5e(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %eax,0x14(%rsp)
movsd  %xmm0,0x18(%rsp)
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r12d
mov    $0xc8,%r13d
movsd  0xdff(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1070 <sin@plt>
mulsd  0xdf0(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  0xdd4(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1080 <cos@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
mulsd  0x20(%rsp),%xmm0
call   1050 <fabs@plt>
mov    %rax,%rbx
mov    %r12d,%edi
call   1080 <cos@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
mov    %r12d,%edi
call   1080 <cos@plt>
imul   %ebx,%eax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xd74(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xffffffff,%r13d
jne    1210 <main+0x90>
movsd  0x18(%rsp),%xmm0
addsd  0xd56(%rip),%xmm0
mov    0x14(%rsp),%eax
add    $0x1,%eax
cmp    $0xc9,%eax
movsd  0xd4a(%rip),%xmm1
jne    11e0 <main+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     12dd <main+0x15d>
lea    0xd6b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"ImageOutput3.ppm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"P3\0A%d %d\0A255\0A\00"
@.str.3 = [10 x i8] c"%d\0A%d\0A%d\0A\00"
@.str.4 = [41 x i8] c"There was an error in closing the file.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
store i32 200, i32* %2
store i32 200, i32* %3
store i32 0, i32* %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %11)
store i32 1, i32* %5
br label %13
13: ; preds = %59, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %62
17: ; preds = %13
store i32 1, i32* %6
br label %18
18: ; preds = %55, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %2
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %58
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 1.000000e+01
%26 = fptosi double %25 to i32
%27 = call double @sin(i32 %26)
%28 = fmul double 2.550000e+02, %27
%29 = load i32, i32* %6
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 1.000000e+01
%32 = fptosi double %31 to i32
%33 = call i32 @cos(i32 %32)
%34 = call double @floor(i32 %33)
%35 = fmul double %28, %34
%36 = call i64 @fabs(double %35)
%37 = trunc i64 %36 to i32
store i32 %37, i32* %4
%38 = load i32*, i32** %7
%39 = load i32, i32* %4
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = sitofp i32 %41 to double
%43 = fdiv double %42, 1.000000e+01
%44 = fptosi double %43 to i32
%45 = call i32 @cos(i32 %44)
%46 = mul nsw i32 %40, %45
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = sitofp i32 %48 to double
%50 = fdiv double %49, 1.000000e+01
%51 = fptosi double %50 to i32
%52 = call i32 @cos(i32 %51)
%53 = mul nsw i32 %47, %52
%54 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %46, i32 %53)
br label %55
55: ; preds = %22
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %18
58: ; preds = %18
br label %59
59: ; preds = %58
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %13
62: ; preds = %13
%63 = load i32*, i32** %7
%64 = call i64 @fclose(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66, %62
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"ImageOutput3.ppm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"P3\0A%d %d\0A255\0A\00"
@.str.3 = [10 x i8] c"%d\0A%d\0A%d\0A\00"
@str = [40 x i8] c"There was an error in closing the file.\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 ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 200, i32 200)
br label %3
3: ; preds = %0, %27
%4 = phi i32 [ 1, %0 ], [ %28, %27 ]
%5 = sitofp i32 %4 to double
%6 = fdiv double %5, 1.000000e+01
%7 = fptosi double %6 to i32
br label %8
8: ; preds = %3, %8
%9 = phi i32 [ 1, %3 ], [ %25, %8 ]
%10 = tail call double @sin(i32 %7)
%11 = fmul double %10, 2.550000e+02
%12 = sitofp i32 %9 to double
%13 = fdiv double %12, 1.000000e+01
%14 = fptosi double %13 to i32
%15 = tail call i32 @cos(i32 %14)
%16 = tail call double @floor(i32 %15)
%17 = fmul double %11, %16
%18 = tail call i64 @fabs(double %17)
%19 = trunc i64 %18 to i32
%20 = tail call i32 @cos(i32 %7)
%21 = mul nsw i32 %20, %19
%22 = tail call i32 @cos(i32 %7)
%23 = mul nsw i32 %22, %19
%24 = tail call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %21, i32 %23)
%25 = add nuw nsw i32 %9, 1
%26 = icmp eq i32 %25, 201
br i1 %26, label %27, label %8
27: ; preds = %8
%28 = add nuw nsw i32 %4, 1
%29 = icmp eq i32 %28, 201
br i1 %29, label %30, label %3
30: ; preds = %27
%31 = tail call i64 @fclose(i32* %1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
ret i32 0
}