#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*/ bail(char *);
int /*<<< orphan*/ curs_set(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ msgbox(char *);
int save_map(int /*<<< orphan*/ *);
void editor_save(char *file) {
  curs_set(0);
  FILE *fp = fopen(file, "wb");
  if (fp != NULL) {
    if (save_map(fp) == 1) {
      bail("editor_save() -> save_map()");
    }
  } else {
    msgbox("Unable to open map for saving!");
    msgbox("Please use Save As to set valid filename.");
  }
  fclose(fp);
  curs_set(1);
}


x86 assembly (clang, -O0):
<editor_save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
call   1080 <curs_set@plt>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b5 <editor_save+0x55>
mov    -0x10(%rbp),%rdi
call   1060 <save_map@plt>
cmp    $0x1,%eax
jne    11b0 <editor_save+0x50>
lea    0xe58(%rip),%rdi
call   1040 <bail@plt>
jmp    11cd <editor_save+0x6d>
lea    0xe63(%rip),%rdi
call   1070 <msgbox@plt>
lea    0xe76(%rip),%rdi
call   1070 <msgbox@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1080 <curs_set@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<editor_save>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
call   1080 <curs_set@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119d <editor_save+0x3d>
mov    %rbx,%rdi
call   1060 <save_map@plt>
cmp    $0x1,%eax
jne    11b5 <editor_save+0x55>
lea    0xe6d(%rip),%rdi
call   1040 <bail@plt>
jmp    11b5 <editor_save+0x55>
lea    0xe7b(%rip),%rdi
call   1070 <msgbox@plt>
lea    0xe8e(%rip),%rdi
call   1070 <msgbox@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
pop    %rbx
jmp    1080 <curs_set@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [28 x i8] c"editor_save() -> save_map()\00"
@.str.2 = [31 x i8] c"Unable to open map for saving!\00"
@.str.3 = [42 x i8] c"Please use Save As to set valid filename.\00"
define void @editor_save(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = call i32 @curs_set(i32 0)
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @save_map(i32* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @bail(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
br label %19
16: ; preds = %1
%17 = call i32 @msgbox(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @msgbox(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %16, %15
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @curs_set(i32 1)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [28 x i8] c"editor_save() -> save_map()\00"
@.str.2 = [31 x i8] c"Unable to open map for saving!\00"
@.str.3 = [42 x i8] c"Please use Save As to set valid filename.\00"
define void @editor_save(i8* nocapture %0) {
%2 = tail call i32 @curs_set(i32 0)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32 @save_map(i32* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @bail(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %1
%11 = tail call i32 @msgbox(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @msgbox(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %5, %8, %10
%14 = tail call i32 @fclose(i32* %3)
%15 = tail call i32 @curs_set(i32 1)
ret void
}