#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ die(int, int);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int system(char *);
void launcheditor(char *database, int status, int errno) {
  char *editor = getenv("EDITOR");
  char *buffer;
  assert(database != NULL);
  if (editor == NULL) {
    editor = "vim";
  }
  buffer = malloc(1024);
  strcpy(buffer, editor);
  strcat(buffer, " ");
  strcat(buffer, database);
  errno = system(buffer);
  free(buffer);
  die(status, errno);
}


x86 assembly (clang, -O0):
<launcheditor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11ca <launcheditor+0x4a>
lea    0xe41(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <die@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launcheditor>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xe6c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1070 <assert@plt>
test   %rbp,%rbp
lea    0xe53(%rip),%rbx
cmovne %rbp,%rbx
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
lea    0xe34(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r14d,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <die@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"EDITOR\00"
@.str.1 = [4 x i8] c"vim\00"
@.str.2 = [2 x i8] c" \00"
define void @launcheditor(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %17
17: ; preds = %16, %3
%18 = call i8* @malloc(i32 1024)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %7
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %8
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8*, i8** %8
%25 = load i8*, i8** %4
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @system(i8* %27)
store i32 %28, i32* %6
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = call i32 @die(i32 %31, i32 %32)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"EDITOR\00"
@.str.1 = [4 x i8] c"vim\00"
@.str.2 = [2 x i8] c" \00"
define void @launcheditor(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i8* %4, null
%9 = select i1 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4
%10 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%11 = tail call i32 @strcpy(i8* %10, i8* %9)
%12 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @strcat(i8* %10, i8* %0)
%14 = tail call i32 @system(i8* %10)
%15 = tail call i32 @free(i8* %10)
%16 = tail call i32 @die(i32 %1, i32 %14)
ret void
}