#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 */
char *getenv(char *);
int import(char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
scalar_t__ system(char *);
char *tmpnam(int /*<<< orphan*/ *);
int edit(const char *me) {
  int result = 1;
  char *tmpname = tmpnam(NULL);
  char editor[255];
  char buf[255];
  if (!tmpname)
    return 0;
  if (getenv("EDITOR"))
    sprintf(editor, "%s %s", getenv("EDITOR"), tmpname);
  else
    sprintf(editor, "vi %s", tmpname);
  sprintf(buf, "%s export > %s", me, tmpname);
  if (system(buf))
    return 0;
  if (!system(editor)) {
    result = import(tmpname);
    remove(tmpname);
  }
  return result;
}


x86 assembly (clang, -O0):
<edit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <tmpnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <edit+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    1274 <edit+0x114>
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11eb <edit+0x8b>
lea    -0x120(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    0xe3b(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x228(%rbp),%rdi
mov    %rax,%rdx
mov    -0x20(%rbp),%rcx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1204 <edit+0xa4>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x220(%rbp),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
je     1243 <edit+0xe3>
movl   $0x0,-0x4(%rbp)
jmp    1274 <edit+0x114>
lea    -0x120(%rbp),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
jne    126e <edit+0x10e>
mov    -0x20(%rbp),%rdi
call   1060 <import@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edit>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %edi,%edi
call   1080 <tmpnam@plt>
test   %rax,%rax
je     1204 <edit+0xa4>
mov    %rax,%r15
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b0 <edit+0x50>
lea    0xe69(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    11c4 <edit+0x64>
lea    0xe56(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe48(%rip),%rsi
xor    %ebx,%ebx
lea    0x100(%rsp),%r12
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r12,%rdi
call   1050 <system@plt>
test   %rax,%rax
jne    1204 <edit+0xa4>
mov    %rsp,%rdi
call   1050 <system@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1215 <edit+0xb5>
mov    %ebx,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1060 <import@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <remove@plt>
mov    %ebx,%eax
jmp    1206 <edit+0xa6>

LLVM IR (-O0):
@.str = [7 x i8] c"EDITOR\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [6 x i8] c"vi %s\00"
@.str.3 = [15 x i8] c"%s export > %s\00"
define i32 @edit(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [255 x i8]
%7 = alloca [255 x i8]
store i8* %0, i8** %3
store i32 1, i32* %4
%8 = call i8* @tmpnam(i32* null)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i32 0, i32* %2
br label %44
12: ; preds = %1
%13 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%17 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %5
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18)
br label %24
20: ; preds = %12
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %15
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = load i8*, i8** %5
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %27)
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%30 = call i64 @system(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %24
store i32 0, i32* %2
br label %44
33: ; preds = %24
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%35 = call i64 @system(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = call i32 @import(i8* %38)
store i32 %39, i32* %4
%40 = load i8*, i8** %5
%41 = call i32 @remove(i8* %40)
br label %42
42: ; preds = %37, %33
%43 = load i32, i32* %4
store i32 %43, i32* %2
br label %44
44: ; preds = %42, %32, %11
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [7 x i8] c"EDITOR\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [6 x i8] c"vi %s\00"
@.str.3 = [15 x i8] c"%s export > %s\00"
define i32 @edit(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca [255 x i8]
%4 = tail call i8* @tmpnam(i32* null)
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = icmp eq i8* %4, null
br i1 %7, label %25, label %8
8: ; preds = %1
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %4)
br label %15
13: ; preds = %8
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %15
15: ; preds = %13, %11
%16 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %4)
%17 = call i64 @system(i8* %6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = call i64 @system(i8* %5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @import(i8* %4)
%24 = tail call i32 @remove(i8* %4)
br label %25
25: ; preds = %19, %22, %15, %1
%26 = phi i32 [ 0, %1 ], [ 0, %15 ], [ 1, %19 ], [ %23, %22 ]
ret i32 %26
}