#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*/ STDOUT_FILENO;
int /*<<< orphan*/ disable_raw_mode();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void safe_exit(int value, char *string) {
  write(STDOUT_FILENO, "\x1b[2J", 4);
  write(STDOUT_FILENO, "\x1b[H", 3);
  disable_raw_mode();
  if (value) {
    printf("\n%s\n\n", string);
  }
  exit(value);
}


x86 assembly (clang, -O0):
<safe_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    $0x0,%al
call   1050 <disable_raw_mode@plt>
cmpl   $0x0,-0x4(%rbp)
je     11a4 <safe_exit+0x64>
mov    -0x10(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<safe_exit>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e9f(%rip),%r15
mov    (%r15),%edi
lea    0xea5(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    (%r15),%edi
lea    0xe96(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1050 <disable_raw_mode@plt>
test   %ebx,%ebx
je     1193 <safe_exit+0x53>
lea    0xe7e(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [5 x i8] c"\1B[2J\00"
@.str.1 = [4 x i8] c"\1B[H\00"
@.str.2 = [6 x i8] c"\0A%s\0A\0A\00"
define void @safe_exit(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* @STDOUT_FILENO
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = load i32, i32* @STDOUT_FILENO
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%9 = call i32 (...) @disable_raw_mode()
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %3
%17 = call i32 @exit(i32 %16)
unreachable
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [5 x i8] c"\1B[2J\00"
@.str.1 = [4 x i8] c"\1B[H\00"
@.str.2 = [6 x i8] c"\0A%s\0A\0A\00"
define void @safe_exit(i32 %0, i8* %1) {
%3 = load i32, i32* @STDOUT_FILENO
%4 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%5 = load i32, i32* @STDOUT_FILENO
%6 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%7 = tail call i32 (...) @disable_raw_mode()
%8 = icmp eq i32 %0, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @exit(i32 %0)
unreachable
}