#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 /*<<< orphan*/ printf(char *);
double sin(int);
int system(char *);
int main() {
  int height = 200;
  int width = 200;
  int col = 0;
  int i, j, s;
  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", (int)col, (int)col * cos(i / 10.0),
              (int)col * cos(i / 10.0));
    }
  }
  if (fclose(fout) != 0) {
    printf("There was an error in closing the file.\n");
  }
  fout = fopen("startGimp.bat", "w");
  fprintf(fout, "set DefaultGimp = C:\\Program Files\\GIMP 2\\bin\\");
  fprintf(fout, "\nif not exist %%DefaultGimp%%\gimp goto ERROR");
  fprintf(fout, "\nset PATH =;%%PATH%%;%%DefaultGimp%%;");
  fprintf(fout, "\ngimp ImageOutput3.ppm");
  fprintf(fout, "\n:ERROR \necho Something happened, exiting!\npause\ncd");
  s = system("startGimp.bat");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc8,-0x8(%rbp)
movl   $0xc8,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xf2e(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1306 <main+0x176>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12f3 <main+0x163>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xdda(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xdbc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1090 <cos@plt>
mov    %eax,%edi
call   10b0 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <fabs@plt>
mov    %eax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x40(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xd73(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1090 <cos@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xd48(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1090 <cos@plt>
mov    -0x3c(%rbp),%r8d
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
imul   %eax,%r8d
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fd <main+0x6d>
jmp    12f8 <main+0x168>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <main+0x5a>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1325 <main+0x195>
lea    0xd0a(%rip),%rdi
call   1050 <printf@plt>
lea    0xd27(%rip),%rdi
lea    0xcdd(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xcb6(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
add    $0x50,%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    0xf13(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
lea    0xe4f(%rip),%rsi
mov    %rax,%rdi
mov    $0xc8,%edx
mov    $0xc8,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
movsd  0xe14(%rip),%xmm0
movsd  0xe14(%rip),%xmm1
lea    0xe2d(%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  0xddf(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1080 <sin@plt>
mulsd  0xdd0(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  0xdb4(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1090 <cos@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mulsd  0x20(%rsp),%xmm0
call   1060 <fabs@plt>
mov    %rax,%rbx
mov    %r12d,%edi
call   1090 <cos@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
mov    %r12d,%edi
call   1090 <cos@plt>
imul   %ebx,%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  0xd54(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xffffffff,%r13d
jne    1230 <main+0x90>
movsd  0x18(%rsp),%xmm0
addsd  0xd36(%rip),%xmm0
mov    0x14(%rsp),%eax
add    $0x1,%eax
cmp    $0xc9,%eax
movsd  0xd2a(%rip),%xmm1
jne    1200 <main+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     12fd <main+0x15d>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
lea    0xd2e(%rip),%rbx
lea    0xd0d(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
lea    0xd23(%rip),%rdi
mov    $0x2e,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
lea    0xd39(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd55(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd6a(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
lea    0xd68(%rip),%rdi
mov    $0x33,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <system@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"
@.str.5 = [14 x i8] c"startGimp.bat\00"
@.str.6 = [47 x i8] c"set DefaultGimp = C:\\Program Files\\GIMP 2\\bin\\\00"
@.str.7 = [45 x i8] c"\0Aif not exist %%DefaultGimp%%gimp goto ERROR\00"
@.str.8 = [38 x i8] c"\0Aset PATH =;%%PATH%%;%%DefaultGimp%%;\00"
@.str.9 = [23 x i8] c"\0Agimp ImageOutput3.ppm\00"
@.str.10 = [52 x i8] c"\0A:ERROR \0Aecho Something happened, exiting!\0Apause\0Acd\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
%8 = alloca i32*
store i32 0, i32* %1
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** %8
%10 = load i32*, i32** %8
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = call i32 (i32*, i8*, ...) @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 = %60, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %63
18: ; preds = %14
store i32 1, i32* %6
br label %19
19: ; preds = %56, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %2
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %59
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** %8
%40 = load i32, i32* %4
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = sitofp i32 %42 to double
%44 = fdiv double %43, 1.000000e+01
%45 = fptosi double %44 to i32
%46 = call i32 @cos(i32 %45)
%47 = mul nsw i32 %41, %46
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = sitofp i32 %49 to double
%51 = fdiv double %50, 1.000000e+01
%52 = fptosi double %51 to i32
%53 = call i32 @cos(i32 %52)
%54 = mul nsw i32 %48, %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %47, i32 %54)
br label %56
56: ; preds = %23
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %19
59: ; preds = %19
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %14
63: ; preds = %14
%64 = load i32*, i32** %8
%65 = call i64 @fclose(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %67, %63
%70 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %70, i32** %8
%71 = load i32*, i32** %8
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32*, i32** %8
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
%75 = load i32*, i32** %8
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%77 = load i32*, i32** %8
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%79 = load i32*, i32** %8
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0))
%81 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 %81, i32* %7
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.5 = [14 x i8] c"startGimp.bat\00"
@.str.6 = [47 x i8] c"set DefaultGimp = C:\\Program Files\\GIMP 2\\bin\\\00"
@.str.7 = [45 x i8] c"\0Aif not exist %%DefaultGimp%%gimp goto ERROR\00"
@.str.8 = [38 x i8] c"\0Aset PATH =;%%PATH%%;%%DefaultGimp%%;\00"
@.str.9 = [23 x i8] c"\0Agimp ImageOutput3.ppm\00"
@.str.10 = [52 x i8] c"\0A:ERROR \0Aecho Something happened, exiting!\0Apause\0Acd\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*, ...) @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*, ...) @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
%36 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = tail call i64 @fwrite(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i64 46, i64 1, i32* %36)
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
%39 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%40 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 22, i64 1, i32* %36)
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0), i64 51, i64 1, i32* %36)
%42 = tail call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}