#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 */

/* Variables and functions */
int /*<<< orphan*/ command_reader(char *, int);
int /*<<< orphan*/ exit_jerk();
int /*<<< orphan*/ print_mesg(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ save_file();
int set_flag_edit();
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int save_exit_mode(void) {
  char command_buffer[5];
  command_reader(command_buffer, 5);
  if (0 == strlen(command_buffer))
    return 1;
  if (('\0' == command_buffer[2]) && (0 == strncmp(command_buffer, "q!", 2)))
    exit_jerk();
  if (('\0' == command_buffer[1]) && (0 == strncmp(command_buffer, "q", 1))) {
    if (1 == set_flag_edit()) {
      print_mesg(0, 1,
                 "FILE HAS BEEN EDITED,ADD ! TO OVERWRITE ALL THE CHANGES");
      return 1;
    } else
      exit_jerk();
  }
  if (('\0' == command_buffer[2]) && (0 == strncmp(command_buffer, "wq", 2))) {
    save_file();
    exit_jerk();
  }
  if (('\0' == command_buffer[1]) && (0 == strncmp(command_buffer, "w", 1))) {
    save_file();
    return 0;
  } else {
    print_mesg(0, 1, "INVALID JINV COMMAND");
    return 1;
  }
}


x86 assembly (clang, -O0):
<save_exit_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x9(%rbp),%rdi
mov    $0x5,%esi
call   1060 <command_reader@plt>
lea    -0x9(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a9 <save_exit_mode+0x39>
movl   $0x1,-0x4(%rbp)
jmp    12f0 <save_exit_mode+0x180>
movsbl -0x7(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11e1 <save_exit_mode+0x71>
lea    -0x9(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e1 <save_exit_mode+0x71>
mov    $0x0,%al
call   1080 <exit_jerk@plt>
movsbl -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1253 <save_exit_mode+0xe3>
lea    -0x9(%rbp),%rdi
lea    0xe42(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1253 <save_exit_mode+0xe3>
mov    $0x0,%al
call   1050 <set_flag_edit@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1247 <save_exit_mode+0xd7>
xor    %edi,%edi
mov    $0x1,%esi
lea    0xdcd(%rip),%rdx
call   1070 <print_mesg@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f0 <save_exit_mode+0x180>
mov    $0x0,%al
call   1080 <exit_jerk@plt>
jmp    1253 <save_exit_mode+0xe3>
movsbl -0x7(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1292 <save_exit_mode+0x122>
lea    -0x9(%rbp),%rdi
lea    0xdcf(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1292 <save_exit_mode+0x122>
mov    $0x0,%al
call   1090 <save_file@plt>
mov    $0x0,%al
call   1080 <exit_jerk@plt>
movsbl -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    12d6 <save_exit_mode+0x166>
lea    -0x9(%rbp),%rdi
lea    0xd93(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12d6 <save_exit_mode+0x166>
mov    $0x0,%al
call   1090 <save_file@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f0 <save_exit_mode+0x180>
xor    %edi,%edi
mov    $0x1,%esi
lea    0xd5c(%rip),%rdx
call   1070 <print_mesg@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_exit_mode>:
push   %rbx
sub    $0x10,%rsp
lea    0xb(%rsp),%rdi
mov    $0x5,%esi
call   1050 <command_reader@plt>
cmpb   $0x0,0xb(%rsp)
je     11d7 <save_exit_mode+0x77>
cmpb   $0x0,0xd(%rsp)
jne    119d <save_exit_mode+0x3d>
lea    0xe77(%rip),%rsi
lea    0xb(%rsp),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e1 <save_exit_mode+0x81>
cmpb   $0x0,0xc(%rsp)
jne    11ef <save_exit_mode+0x8f>
lea    0xe91(%rip),%rsi
lea    0xb(%rsp),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11ef <save_exit_mode+0x8f>
xor    %eax,%eax
call   1040 <set_flag_edit@plt>
cmp    $0x1,%eax
jne    1221 <save_exit_mode+0xc1>
lea    0xe31(%rip),%rdx
jmp    1258 <save_exit_mode+0xf8>
mov    $0x1,%ebx
jmp    1269 <save_exit_mode+0x109>
xor    %eax,%eax
call   1070 <exit_jerk@plt>
cmpb   $0x0,0xc(%rsp)
je     11a4 <save_exit_mode+0x44>
cmpb   $0x0,0xd(%rsp)
jne    122f <save_exit_mode+0xcf>
lea    0xe3e(%rip),%rsi
lea    0xb(%rsp),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    122f <save_exit_mode+0xcf>
xor    %eax,%eax
call   1080 <save_file@plt>
xor    %eax,%eax
call   1070 <exit_jerk@plt>
jmp    122f <save_exit_mode+0xcf>
xor    %eax,%eax
call   1070 <exit_jerk@plt>
cmpb   $0x0,0xd(%rsp)
je     11f6 <save_exit_mode+0x96>
cmpb   $0x0,0xc(%rsp)
jne    1251 <save_exit_mode+0xf1>
lea    0xe01(%rip),%rsi
lea    0xb(%rsp),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1271 <save_exit_mode+0x111>
lea    0xde8(%rip),%rdx
mov    $0x1,%ebx
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <print_mesg@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <save_file@plt>
jmp    1269 <save_exit_mode+0x109>

LLVM IR (-O0):
@.str = [3 x i8] c"q!\00"
@.str.1 = [2 x i8] c"q\00"
@.str.2 = [56 x i8] c"FILE HAS BEEN EDITED,ADD ! TO OVERWRITE ALL THE CHANGES\00"
@.str.3 = [3 x i8] c"wq\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [21 x i8] c"INVALID JINV COMMAND\00"
define i32 @save_exit_mode() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = call i32 @command_reader(i8* %3, i32 5)
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%6 = call i64 @strlen(i8* %5)
%7 = icmp eq i64 0, %6
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %62
9: ; preds = %0
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 0, %12
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%16 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = icmp eq i64 0, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (...) @exit_jerk()
br label %20
20: ; preds = %18, %14, %9
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 0, %23
br i1 %24, label %25, label %37
25: ; preds = %20
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%28 = icmp eq i64 0, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = call i32 (...) @set_flag_edit()
%31 = icmp eq i32 1, %30
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @print_mesg(i32 0, i32 1, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %62
34: ; preds = %29
%35 = call i32 (...) @exit_jerk()
br label %36
36: ; preds = %34
br label %37
37: ; preds = %36, %25, %20
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 0, %40
br i1 %41, label %42, label %49
42: ; preds = %37
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%45 = icmp eq i64 0, %44
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = call i32 (...) @save_file()
%48 = call i32 (...) @exit_jerk()
br label %49
49: ; preds = %46, %42, %37
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 0, %52
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%56 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%57 = icmp eq i64 0, %56
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 (...) @save_file()
store i32 0, i32* %1
br label %62
60: ; preds = %54, %49
%61 = call i32 @print_mesg(i32 0, i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %62
62: ; preds = %60, %58, %32, %8
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"q!\00"
@.str.1 = [2 x i8] c"q\00"
@.str.2 = [56 x i8] c"FILE HAS BEEN EDITED,ADD ! TO OVERWRITE ALL THE CHANGES\00"
@.str.3 = [3 x i8] c"wq\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [21 x i8] c"INVALID JINV COMMAND\00"
define i32 @save_exit_mode() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @command_reader(i8* %2, i32 5)
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %48, label %6
6: ; preds = %0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (...) @exit_jerk()
br label %15
15: ; preds = %13, %10, %6
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = call i32 (...) @set_flag_edit()
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @print_mesg(i32 0, i32 1, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
br label %48
27: ; preds = %22
%28 = call i32 (...) @exit_jerk()
br label %29
29: ; preds = %27, %19, %15
%30 = load i8, i8* %7
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 (...) @save_file()
%37 = call i32 (...) @exit_jerk()
br label %38
38: ; preds = %35, %32, %29
%39 = load i8, i8* %16
%40 = icmp eq i8 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (...) @save_file()
br label %48
46: ; preds = %41, %38
%47 = call i32 @print_mesg(i32 0, i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %0, %46, %44, %25
%49 = phi i32 [ 1, %25 ], [ 0, %44 ], [ 1, %46 ], [ 1, %0 ]
ret i32 %49
}