#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 *applet_from_path(char *);
int /*<<< orphan*/ errx(int, char *, ...);
int exec_busybox(char const *, int, char **);
int install_links();
scalar_t__ is_valid_applet(char const *);
scalar_t__ strcmp(char const *, char *);
int main(int argc, char **argv) {
  const char *app = applet_from_path(argv[0]);
  if (strcmp(app, "bbsuid") == 0) {
    if (argc == 2 && strcmp(argv[1], "--install") == 0)
      return install_links();
    errx(1, "Use --install to install symlinks");
  }
  if (is_valid_applet(app))
    return exec_busybox(app, argc, argv);
  errx(1, "%s is not a valid applet", app);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <applet_from_path@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ea <main+0x8a>
cmpl   $0x2,-0x8(%rbp)
jne    11d7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d7 <main+0x77>
mov    $0x0,%al
call   1070 <install_links@plt>
mov    %eax,-0x4(%rbp)
jmp    1233 <main+0xd3>
mov    $0x1,%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x18(%rbp),%rdi
call   1040 <is_valid_applet@plt>
cmp    $0x0,%rax
je     1215 <main+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <exec_busybox@plt>
mov    %eax,-0x4(%rbp)
jmp    1233 <main+0xd3>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    (%rsi),%rdi
call   1080 <applet_from_path@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b5 <main+0x55>
cmp    $0x2,%ebp
jne    11a2 <main+0x42>
mov    0x8(%r14),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f3 <main+0x93>
lea    0xe68(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    %rbx,%rdi
call   1040 <is_valid_applet@plt>
test   %rax,%rax
je     11d3 <main+0x73>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <exec_busybox@plt>
lea    0xe59(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <errx@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <install_links@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"bbsuid\00"
@.str.1 = [10 x i8] c"--install\00"
@.str.2 = [34 x i8] c"Use --install to install symlinks\00"
@.str.3 = [25 x i8] c"%s is not a valid applet\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i8* @applet_from_path(i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 (...) @install_links()
store i32 %24, i32* %3
br label %39
25: ; preds = %17, %14
%26 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %2
%28 = load i8*, i8** %6
%29 = call i64 @is_valid_applet(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = load i32, i32* %4
%34 = load i8**, i8*** %5
%35 = call i32 @exec_busybox(i8* %32, i32 %33, i8** %34)
store i32 %35, i32* %3
br label %39
36: ; preds = %27
%37 = load i8*, i8** %6
%38 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 1, i32* %3
br label %39
39: ; preds = %36, %31, %23
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"bbsuid\00"
@.str.1 = [10 x i8] c"--install\00"
@.str.2 = [34 x i8] c"Use --install to install symlinks\00"
@.str.3 = [25 x i8] c"%s is not a valid applet\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @applet_from_path(i8* %3)
%5 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 (...) @install_links()
br label %25
16: ; preds = %9, %7
%17 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = tail call i64 @is_valid_applet(i8* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @exec_busybox(i8* %4, i32 %0, i8** %1)
br label %25
23: ; preds = %18
%24 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %23, %21, %14
%26 = phi i32 [ %15, %14 ], [ %22, %21 ], [ 1, %23 ]
ret i32 %26
}