#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*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ backup(char *, char *);
int /*<<< orphan*/ binsh_in_filelist(char *);
int /*<<< orphan*/ force_symlink(char *, char *, char *);
int /*<<< orphan*/ reset_diversion(char *, char *, char *);
scalar_t__ undiverted(char *);
int main(int argc, char *argv[]) {
  if (access("/bin/sh", X_OK)) {
    backup("/bin/sh", "/bin/sh.distrib");
    backup("/usr/share/man/man1/sh.1.gz",
           "/usr/share/man/man1/sh.distrib.1.gz");
    force_symlink("bash", "/bin/sh", "/bin/sh.temp");
    force_symlink("bash.1.gz", "/usr/share/man/man1/sh.1.gz",
                  "/usr/share/man/man1/sh.1.gz.temp");
  }
  if (!binsh_in_filelist("bash"))
    return 0;
  if (undiverted("/bin/sh"))
    reset_diversion("dash", "/bin/sh", "/bin/sh.distrib");
  if (undiverted("/usr/share/man/man1/sh.1.gz"))
    reset_diversion("dash", "/usr/share/man/man1/sh.1.gz",
                    "/usr/share/man/man1/sh.distrib.1.gz");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
je     11ef <main+0x8f>
lea    0xe64(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1030 <backup@plt>
lea    0xe69(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1030 <backup@plt>
lea    0xe96(%rip),%rdi
lea    0xe37(%rip),%rsi
lea    0xe8d(%rip),%rdx
call   1040 <force_symlink@plt>
lea    0xe8e(%rip),%rdi
lea    0xe35(%rip),%rsi
lea    0xe8a(%rip),%rdx
call   1040 <force_symlink@plt>
lea    0xe62(%rip),%rdi
call   1080 <binsh_in_filelist@plt>
cmp    $0x0,%eax
jne    1210 <main+0xb0>
movl   $0x0,-0x4(%rbp)
jmp    1277 <main+0x117>
lea    0xde9(%rip),%rdi
call   1060 <undiverted@plt>
cmp    $0x0,%rax
je     1240 <main+0xe0>
lea    0xe68(%rip),%rdi
lea    0xdcc(%rip),%rsi
lea    0xdcd(%rip),%rdx
call   1050 <reset_diversion@plt>
lea    0xdd1(%rip),%rdi
call   1060 <undiverted@plt>
cmp    $0x0,%rax
je     1270 <main+0x110>
lea    0xe38(%rip),%rdi
lea    0xdb4(%rip),%rsi
lea    0xdc9(%rip),%rdx
call   1050 <reset_diversion@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
je     11d6 <main+0x76>
lea    0xe7b(%rip),%rbx
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <backup@plt>
lea    0xe7d(%rip),%r14
lea    0xe92(%rip),%rsi
mov    %r14,%rdi
call   1030 <backup@plt>
lea    0xea7(%rip),%rdi
lea    0xea5(%rip),%rdx
mov    %rbx,%rsi
call   1040 <force_symlink@plt>
lea    0xea3(%rip),%rdi
lea    0xea6(%rip),%rdx
mov    %r14,%rsi
call   1040 <force_symlink@plt>
lea    0xe7b(%rip),%rdi
call   1080 <binsh_in_filelist@plt>
test   %eax,%eax
je     123c <main+0xdc>
lea    0xe13(%rip),%rdi
call   1060 <undiverted@plt>
test   %rax,%rax
je     1211 <main+0xb1>
lea    0xe97(%rip),%rdi
lea    0xdfb(%rip),%rsi
lea    0xdfc(%rip),%rdx
call   1050 <reset_diversion@plt>
lea    0xe00(%rip),%rdi
call   1060 <undiverted@plt>
test   %rax,%rax
je     123c <main+0xdc>
lea    0xe6c(%rip),%rdi
lea    0xde8(%rip),%rsi
lea    0xdfd(%rip),%rdx
call   1050 <reset_diversion@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@X_OK = global i32 0
@.str.1 = [16 x i8] c"/bin/sh.distrib\00"
@.str.2 = [28 x i8] c"/usr/share/man/man1/sh.1.gz\00"
@.str.3 = [36 x i8] c"/usr/share/man/man1/sh.distrib.1.gz\00"
@.str.4 = [5 x i8] c"bash\00"
@.str.5 = [13 x i8] c"/bin/sh.temp\00"
@.str.6 = [10 x i8] c"bash.1.gz\00"
@.str.7 = [33 x i8] c"/usr/share/man/man1/sh.1.gz.temp\00"
@.str.8 = [5 x i8] c"dash\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @X_OK
%7 = call i64 @access(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = call i32 @backup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @backup(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @force_symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @force_symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %14
14: ; preds = %9, %2
%15 = call i32 @binsh_in_filelist(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %14
store i32 0, i32* %3
br label %29
18: ; preds = %14
%19 = call i64 @undiverted(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @reset_diversion(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = call i64 @undiverted(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @reset_diversion(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
store i32 0, i32* %3
br label %29
29: ; preds = %28, %17
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@X_OK = global i32 0
@.str.1 = [16 x i8] c"/bin/sh.distrib\00"
@.str.2 = [28 x i8] c"/usr/share/man/man1/sh.1.gz\00"
@.str.3 = [36 x i8] c"/usr/share/man/man1/sh.distrib.1.gz\00"
@.str.4 = [5 x i8] c"bash\00"
@.str.5 = [13 x i8] c"/bin/sh.temp\00"
@.str.6 = [10 x i8] c"bash.1.gz\00"
@.str.7 = [33 x i8] c"/usr/share/man/man1/sh.1.gz.temp\00"
@.str.8 = [5 x i8] c"dash\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @X_OK
%4 = tail call i64 @access(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 @backup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @backup(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @force_symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%10 = tail call i32 @force_symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %11
11: ; preds = %6, %2
%12 = tail call i32 @binsh_in_filelist(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %11
%15 = tail call i64 @undiverted(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @reset_diversion(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = tail call i64 @undiverted(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @reset_diversion(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %19, %22, %11
ret i32 0
}