#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*/ cos(int);
scalar_t__ fabs(double);
scalar_t__ fclose(int /*<<< orphan*/ *);
double floor(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, ...);
int /*<<< orphan*/ printf(char *);
int rand();
double sin(int);
int /*<<< orphan*/ srand(int);
int main() {
  srand(986459836);
  int height = 200;
  int width = 200;
  int col = 0;
  int i, j;
  FILE *fout;
  fout = fopen("ImageOutput4.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, rand() % 256, rand() % 256);
    }
  }
  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)
mov    $0x3acc2ebc,%edi
call   1050 <srand@plt>
movl   $0xc8,-0x8(%rbp)
movl   $0xc8,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe3b(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12f1 <main+0x151>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12de <main+0x13e>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xdd0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xdc0(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xda2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1090 <cos@plt>
mov    %eax,%edi
call   10b0 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <fabs@plt>
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%ecx
mov    $0x100,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    -0x24(%rbp),%edx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <main+0x77>
jmp    12e3 <main+0x143>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1204 <main+0x64>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1310 <main+0x170>
lea    0xd30(%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
mov    $0x3acc2ebc,%edi
call   1050 <srand@plt>
lea    0xe59(%rip),%rdi
lea    0xe63(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
lea    0xe56(%rip),%rsi
mov    %rax,%rdi
mov    $0xc8,%edx
mov    $0xc8,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
movsd  0xe0a(%rip),%xmm0
movsd  0xe0a(%rip),%xmm1
lea    0xe34(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,0x14(%rsp)
movsd  %xmm0,0x18(%rsp)
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r12d
mov    $0xc8,%r13d
movsd  0xdcf(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1080 <sin@plt>
mulsd  0xdc0(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  0xda4(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1090 <cos@plt>
mov    %eax,%edi
call   10b0 <floor@plt>
mulsd  0x20(%rsp),%xmm0
call   1060 <fabs@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <rand@plt>
mov    %eax,%ebp
lea    0xff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
and    $0xffffff00,%eax
sub    %eax,%ebp
xor    %eax,%eax
call   10c0 <rand@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
sub    %ecx,%eax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xd27(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xffffffff,%r13d
jne    1240 <main+0xa0>
movsd  0x18(%rsp),%xmm0
addsd  0xd09(%rip),%xmm0
mov    0x14(%rsp),%eax
add    $0x1,%eax
cmp    $0xc9,%eax
movsd  0xcfd(%rip),%xmm1
jne    1210 <main+0x70>
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     132a <main+0x18a>
lea    0xd1e(%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"ImageOutput4.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
%8 = call i32 @srand(i32 986459836)
store i32 200, i32* %2
store i32 200, i32* %3
store i32 0, i32* %4
%9 = 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* %9, i32** %7
%10 = load i32*, i32** %7
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %12)
store i32 1, i32* %5
br label %14
14: ; preds = %50, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %53
18: ; preds = %14
store i32 1, i32* %6
br label %19
19: ; preds = %46, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %2
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %49
23: ; preds = %19
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 1.000000e+01
%27 = fptosi double %26 to i32
%28 = call double @sin(i32 %27)
%29 = fmul double 2.550000e+02, %28
%30 = load i32, i32* %6
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, 1.000000e+01
%33 = fptosi double %32 to i32
%34 = call i32 @cos(i32 %33)
%35 = call double @floor(i32 %34)
%36 = fmul double %29, %35
%37 = call i64 @fabs(double %36)
%38 = trunc i64 %37 to i32
store i32 %38, i32* %4
%39 = load i32*, i32** %7
%40 = load i32, i32* %4
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 256
%43 = call i32 (...) @rand()
%44 = srem i32 %43, 256
%45 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %42, i32 %44)
br label %46
46: ; preds = %23
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %19
49: ; preds = %19
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %14
53: ; preds = %14
%54 = load i32*, i32** %7
%55 = call i64 @fclose(i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
ret i32 0
}

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