#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*/ TIOCSCTTY;
int /*<<< orphan*/ do_mounts();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ run_process(char *);
int /*<<< orphan*/ setsid();
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  puts("Mounting...");
  do_mounts();
  setsid();
  ioctl(0, TIOCSCTTY, 1);
  puts("Starting '/bin/sh'...");
  run_process("/bin/sh");
  printf("Init failed: %s\n", strerror(errno));
  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)
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1050 <do_mounts@plt>
mov    $0x0,%al
call   1080 <setsid@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    $0x1,%edx
call   1070 <ioctl@plt>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5a(%rip),%rdi
call   1030 <run_process@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe45(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <do_mounts@plt>
xor    %eax,%eax
call   1080 <setsid@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    $0x1,%edx
call   1070 <ioctl@plt>
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6f(%rip),%rdi
call   1030 <run_process@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe5d(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Mounting...\00"
@TIOCSCTTY = global i32 0
@.str.1 = [22 x i8] c"Starting '/bin/sh'...\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [17 x i8] c"Init failed: %s\0A\00"
@errno = global i32 0
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 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @do_mounts()
%8 = call i32 (...) @setsid()
%9 = load i32, i32* @TIOCSCTTY
%10 = call i32 @ioctl(i32 0, i32 %9, i32 1)
%11 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @run_process(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Mounting...\00"
@TIOCSCTTY = global i32 0
@.str.1 = [22 x i8] c"Starting '/bin/sh'...\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [17 x i8] c"Init failed: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @do_mounts()
%5 = tail call i32 (...) @setsid()
%6 = load i32, i32* @TIOCSCTTY
%7 = tail call i32 @ioctl(i32 0, i32 %6, i32 1)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @run_process(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %11)
ret i32 0
}