#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 EX_OSERR;
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ errx(int, char *);
int execv(char *, char **);
scalar_t__ geteuid();
int /*<<< orphan*/ is_emacs_valid(int /*<<< orphan*/);
int runit(char const **, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ret;
  if (!is_emacs_valid(0)) {
    const char *newargs[2];
    newargs[0] = "/usr/libexec"
                 "/dumpemacs";
    if (geteuid() != 0) {
      newargs[1] = "-n";
      newargs[2] = NULL;
    } else {
      newargs[1] = NULL;
    }
    ret = runit(newargs, 0);
    if (ret) {
      errx(1, "Failed to dump emacs");
    }
  }
  ret = execv("/usr/bin"
              "/emacs-"
              "x86_64",
              argv);
  if (ret) {
    err(EX_OSERR, "execv(%s) failed",
        "/usr/bin"
        "/emacs-"
        "x86_64");
  }
  return EX_OSERR;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1060 <is_emacs_valid@plt>
cmp    $0x0,%eax
jne    11f0 <main+0x90>
lea    0xe73(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
je     11ba <main+0x5a>
lea    0xe6e(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
jmp    11c2 <main+0x62>
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1030 <runit@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11eb <main+0x8b>
mov    $0x1,%edi
lea    0xe34(%rip),%rsi
call   1040 <errx@plt>
jmp    11f0 <main+0x90>
mov    -0x10(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1080 <execv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1229 <main+0xc9>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
lea    0xe0b(%rip),%rdx
call   1070 <err@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
xor    %edi,%edi
call   1060 <is_emacs_valid@plt>
test   %eax,%eax
jne    11c3 <main+0x63>
lea    0xe84(%rip),%rax
mov    %rax,(%rsp)
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
je     119f <main+0x3f>
movq   $0x0,0x10(%rsp)
lea    0xe78(%rip),%r14
mov    %r14,0x8(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <runit@plt>
test   %eax,%eax
je     11c3 <main+0x63>
lea    0xe61(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
call   1080 <execv@plt>
test   %eax,%eax
je     11f2 <main+0x92>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
lea    0xe42(%rip),%rdx
call   1070 <err@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/usr/libexec/dumpemacs\00"
@.str.1 = [3 x i8] c"-n\00"
@.str.2 = [21 x i8] c"Failed to dump emacs\00"
@.str.3 = [22 x i8] c"/usr/bin/emacs-x86_64\00"
@EX_OSERR = global i32 0
@.str.4 = [17 x i8] c"execv(%s) failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @is_emacs_valid(i32 0)
%9 = icmp ne i32 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %2
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %11
%12 = call i64 (...) @geteuid()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 2
store i8* null, i8** %16
br label %19
17: ; preds = %10
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* null, i8** %18
br label %19
19: ; preds = %17, %14
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%21 = call i32 @runit(i8** %20, i32 0)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
br label %27
27: ; preds = %26, %2
%28 = load i8**, i8*** %5
%29 = call i32 @execv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8** %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @EX_OSERR
%34 = call i32 @err(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %32, %27
%36 = load i32, i32* @EX_OSERR
ret i32 %36
}

LLVM IR (-O2):
@.str = [23 x i8] c"/usr/libexec/dumpemacs\00"
@.str.1 = [3 x i8] c"-n\00"
@.str.2 = [21 x i8] c"Failed to dump emacs\00"
@.str.3 = [22 x i8] c"/usr/bin/emacs-x86_64\00"
@EX_OSERR = global i32 0
@.str.4 = [17 x i8] c"execv(%s) failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i8*]
%4 = tail call i32 @is_emacs_valid(i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = bitcast [2 x i8*]* %3 to i8*
%8 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = tail call i64 (...) @geteuid()
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %12
br label %13
13: ; preds = %6, %11
%14 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %11 ], [ null, %6 ]
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* %14, i8** %15
%16 = call i32 @runit(i8** %8, i32 0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
br label %21
21: ; preds = %20, %2
%22 = call i32 @execv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8** %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* @EX_OSERR
%26 = call i32 @err(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* @EX_OSERR
ret i32 %28
}