#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*/ O_RDWR;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int login(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ putstr(char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fdtty1, sh_pid, pid;
  signal(SIGINT, SIG_IGN);
  unlink("/etc/mtab");
  do {
    fdtty1 = open("/dev/tty1", O_RDWR);
  } while (fdtty1 < 0);
  if (fdtty1 != 0)
    close(0);
  dup(fdtty1);
  close(1);
  dup(fdtty1);
  close(2);
  dup(fdtty1);
  putstr("init version 0.8.1ac\n");
  for (;;) {
    sh_pid = login("/dev/tty1");
    do {
      pid = wait(NULL);
    } while (sh_pid != pid);
    write(1, "\n", 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    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
lea    0xe3c(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11c9 <main+0x39>
cmpl   $0x0,-0x14(%rbp)
je     11fc <main+0x6c>
xor    %edi,%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <dup@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <dup@plt>
mov    $0x2,%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <dup@plt>
lea    0xde5(%rip),%rdi
call   1090 <putstr@plt>
lea    0xdcf(%rip),%rdi
call   1070 <login@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1243 <main+0xb3>
mov    $0x1,%edx
lea    0xdc1(%rip),%rsi
mov    %edx,%edi
call   1040 <write@plt>
jmp    1234 <main+0xa4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
lea    0xe4e(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e2a(%rip),%rbp
lea    0xe45(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     11d0 <main+0x40>
mov    %eax,%ebx
je     11ea <main+0x5a>
xor    %edi,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
mov    $0x2,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
lea    0xdfa(%rip),%rdi
call   1090 <putstr@plt>
lea    0xde4(%rip),%r14
lea    0xdfb(%rip),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1070 <login@plt>
mov    %eax,%ebp
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   10b0 <wait@plt>
cmp    %eax,%ebp
jne    1240 <main+0xb0>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    1230 <main+0xa0>

LLVM IR (-O0):
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [10 x i8] c"/dev/tty1\00"
@O_RDWR = global i32 0
@.str.2 = [22 x i8] c"init version 0.8.1ac\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @SIGINT
%10 = load i32, i32* @SIG_IGN
%11 = call i32 @signal(i32 %9, i32 %10)
%12 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %16, %2
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %13
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %13, label %19
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @close(i32 0)
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %6
%26 = call i32 @dup(i32 %25)
%27 = call i32 @close(i32 1)
%28 = load i32, i32* %6
%29 = call i32 @dup(i32 %28)
%30 = call i32 @close(i32 2)
%31 = load i32, i32* %6
%32 = call i32 @dup(i32 %31)
%33 = call i32 @putstr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %42, %24
%35 = call i32 @login(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 %35, i32* %7
br label %36
36: ; preds = %38, %34
%37 = call i32 @wait(i32* null)
store i32 %37, i32* %8
br label %38
38: ; preds = %36
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = icmp ne i32 %39, %40
br i1 %41, label %36, label %42
42: ; preds = %38
%43 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %34
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [10 x i8] c"/dev/tty1\00"
@O_RDWR = global i32 0
@.str.2 = [22 x i8] c"init version 0.8.1ac\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @SIGINT
%4 = load i32, i32* @SIG_IGN
%5 = tail call i32 @signal(i32 %3, i32 %4)
%6 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %7, %2
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %7, label %11
11: ; preds = %7
%12 = icmp eq i32 %9, 0
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = tail call i32 @close(i32 0)
br label %15
15: ; preds = %13, %11
%16 = tail call i32 @dup(i32 %9)
%17 = tail call i32 @close(i32 1)
%18 = tail call i32 @dup(i32 %9)
%19 = tail call i32 @close(i32 2)
%20 = tail call i32 @dup(i32 %9)
%21 = tail call i32 @putstr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %27, %15
%23 = tail call i32 @login(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %24, %22
%25 = tail call i32 @wait(i32* null)
%26 = icmp eq i32 %23, %25
br i1 %26, label %27, label %24
27: ; preds = %24
%28 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %22
}