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

/* Variables and functions */
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
void do_edit(char *file, int line) {
  char *ed = getenv("VISUAL");
  char linebuf[20];
  if (!ed)
    ed = getenv("EDITOR");
  if (!ed)
    ed = "/usr/bin/edit";
  snprintf(linebuf, sizeof(linebuf), "+%d", line);
  switch (fork()) {
  case 0:
    execlp(ed, ed, linebuf, file, NULL);
    exit(2);
  case -1:
    break;
  default:
    wait(NULL);
  }
}


x86 assembly (clang, -O0):
<do_edit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <do_edit+0x3a>
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <do_edit+0x50>
lea    0xe62(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
lea    0xe62(%rip),%rdx
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
call   1040 <snprintf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     1216 <do_edit+0xb6>
jmp    11e2 <do_edit+0x82>
mov    -0x34(%rbp),%eax
test   %eax,%eax
jne    121b <do_edit+0xbb>
jmp    11f2 <do_edit+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <execlp@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
jmp    1224 <do_edit+0xc4>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_edit>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <do_edit+0x30>
lea    0xe7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rdx
mov    %rsp,%rdi
mov    $0x14,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11bd <do_edit+0x5d>
test   %eax,%eax
je     11c6 <do_edit+0x66>
xor    %edi,%edi
call   1070 <wait@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %rbx,%rbx
lea    0xe3e(%rip),%rdi
cmovne %rbx,%rdi
mov    %rsp,%rdx
mov    %rdi,%rsi
mov    %r14,%rcx
xor    %r8d,%r8d
call   1060 <execlp@plt>
mov    $0x2,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"VISUAL\00"
@.str.1 = [7 x i8] c"EDITOR\00"
@.str.2 = [14 x i8] c"/usr/bin/edit\00"
@.str.3 = [4 x i8] c"+%d\00"
define void @do_edit(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [20 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %5
br label %12
12: ; preds = %10, %2
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %16
16: ; preds = %15, %12
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @snprintf(i8* %17, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @fork()
switch i32 %20, label %29 [
i32 0, label %21
i32 -1, label %28
]
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i8*, i8** %5
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32 @execlp(i8* %22, i8* %23, i8* %24, i8* %25, i32* null)
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %16
br label %31
29: ; preds = %16
%30 = call i32 @wait(i32* null)
br label %31
31: ; preds = %29, %28
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"VISUAL\00"
@.str.1 = [7 x i8] c"EDITOR\00"
@.str.2 = [14 x i8] c"/usr/bin/edit\00"
@.str.3 = [4 x i8] c"+%d\00"
define void @do_edit(i8* %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = phi i8* [ %4, %2 ], [ %8, %7 ]
%11 = call i32 @snprintf(i8* %5, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%12 = call i32 (...) @fork()
switch i32 %12, label %18 [
i32 0, label %13
i32 -1, label %20
]
13: ; preds = %9
%14 = icmp eq i8* %10, null
%15 = select i1 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %10
%16 = call i32 @execlp(i8* %15, i8* %15, i8* %5, i8* %0, i32* null)
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %9
%19 = call i32 @wait(i32* null)
br label %20
20: ; preds = %18, %9
ret void
}