#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ printf(char *);
int ma() {
  int height = 200;
  int width = 200;
  int col = 0;
  int i, j, k;
  FILE *fout;
  fout = fopen("Terrain.ppm", "w");
  fprintf(fout, "P3\n%d %d\n255\n", width, height);
  if (fclose(fout) != 0) {
    printf("There was an error in closing the file.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<ma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xc8,-0x4(%rbp)
movl   $0xc8,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe9c(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11a9 <ma+0x69>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ma>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
mov    $0xc8,%edx
mov    $0xc8,%ecx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1189 <ma+0x49>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Terrain.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 = [41 x i8] c"There was an error in closing the file.\0A\00"
define i32 @ma() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 200, i32* %1
store i32 200, i32* %2
store i32 0, i32* %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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* %2
%11 = load i32, i32* %1
%12 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %11)
%13 = load i32*, i32** %7
%14 = call i64 @fclose(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Terrain.ppm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"P3\0A%d %d\0A255\0A\00"
@str = [40 x i8] c"There was an error in closing the file.\00"
define i32 @ma() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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 @fprintf(i32* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 200, i32 200)
%3 = tail call i64 @fclose(i32* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
ret i32 0
}