#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*/ s;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ chomp(char *);
int /*<<< orphan*/ clear_mazes();
int /*<<< orphan*/ edit_game(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ message(char *);
scalar_t__ read_in_mazes(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
void start_edit(char *fn) {
  char s[20];
  FILE *fp;
  if ((fp = fopen(fn, "r+t")) == NULL) {
    message("Creating new map");
    clear_mazes();
  } else {
    fgets(s, sizeof(s), fp);
    chomp(s);
    if (strcmp(s, "TMAZE")) {
      message("Invalid map file (doesn't have signature)");
      return;
    }
    if (read_in_mazes(fp)) {
      fclose(fp);
      return;
    }
    fclose(fp);
  }
  if ((fp = fopen(fn, "wt")) == NULL) {
    message("Can't make file");
    return;
  }
  edit_game(fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<start_edit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11d2 <start_edit+0x42>
lea    0xe43(%rip),%rdi
call   1030 <message@plt>
mov    $0x0,%al
call   1040 <clear_mazes@plt>
jmp    1242 <start_edit+0xb2>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   10a0 <chomp@plt>
lea    -0x20(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1218 <start_edit+0x88>
lea    0xe0d(%rip),%rdi
call   1030 <message@plt>
jmp    1283 <start_edit+0xf3>
mov    -0x28(%rbp),%rdi
call   1080 <read_in_mazes@plt>
cmp    $0x0,%rax
je     1239 <start_edit+0xa9>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1283 <start_edit+0xf3>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1271 <start_edit+0xe1>
lea    0xde1(%rip),%rdi
call   1030 <message@plt>
jmp    1283 <start_edit+0xf3>
mov    -0x28(%rbp),%rdi
call   1090 <edit_game@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_edit>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
lea    0xe5d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     11e8 <start_edit+0x58>
mov    %rax,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x14,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %r15,%rdi
call   10a0 <chomp@plt>
lea    0xe43(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1224 <start_edit+0x94>
lea    0xe35(%rip),%rdi
jmp    1245 <start_edit+0xb5>
lea    0xe15(%rip),%rdi
call   1030 <message@plt>
xor    %eax,%eax
call   1040 <clear_mazes@plt>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     123e <start_edit+0xae>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <edit_game@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    124a <start_edit+0xba>
mov    %rbx,%rdi
call   1080 <read_in_mazes@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r15,%r15
jne    124a <start_edit+0xba>
jmp    11fb <start_edit+0x6b>
lea    0xe03(%rip),%rdi
call   1030 <message@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"r+t\00"
@.str.1 = [17 x i8] c"Creating new map\00"
@.str.2 = [6 x i8] c"TMAZE\00"
@.str.3 = [42 x i8] c"Invalid map file (doesn't have signature)\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [16 x i8] c"Can't make file\00"
define void @start_edit(i8* %0) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @message(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @clear_mazes()
br label %32
11: ; preds = %1
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32 @fgets(i8* %12, i32 20, i32* %13)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%16 = call i32 @chomp(i8* %15)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @message(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %43
22: ; preds = %11
%23 = load i32*, i32** %4
%24 = call i64 @read_in_mazes(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32*, i32** %4
%28 = call i32 @fclose(i32* %27)
br label %43
29: ; preds = %22
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %29, %8
%33 = load i8*, i8** %2
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %4
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @message(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %43
38: ; preds = %32
%39 = load i32*, i32** %4
%40 = call i32 @edit_game(i32* %39)
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %38, %36, %26, %20
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+t\00"
@.str.1 = [17 x i8] c"Creating new map\00"
@.str.2 = [6 x i8] c"TMAZE\00"
@.str.3 = [42 x i8] c"Invalid map file (doesn't have signature)\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [16 x i8] c"Can't make file\00"
define void @start_edit(i8* nocapture %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @message(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @clear_mazes()
br label %20
9: ; preds = %1
%10 = call i32 @fgets(i8* %3, i32 20, i32* %4)
%11 = call i32 @chomp(i8* %3)
%12 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @message(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %28
16: ; preds = %9
%17 = call i64 @read_in_mazes(i32* %4)
%18 = icmp eq i64 %17, 0
%19 = call i32 @fclose(i32* %4)
br i1 %18, label %20, label %28
20: ; preds = %16, %6
%21 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @message(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %28
25: ; preds = %20
%26 = call i32 @edit_game(i32* %21)
%27 = call i32 @fclose(i32* %21)
br label %28
28: ; preds = %16, %25, %23, %14
ret void
}