#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 O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TIOCSCTTY;
int console_open(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ initlog(char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ wait(int *);
void sysinit() {
  int status, fd;
  if (fork() == 0) {
    setsid();
    if ((fd = console_open(O_RDWR | O_NOCTTY)) >= 0) {
      (void)ioctl(fd, TIOCSCTTY, 1);
      dup(fd);
      dup(fd);
    }
    execl("/bin/bash", "bash", "/etc/sysinit", NULL);
    exit(1);
  }
  wait(&status);
  if (status > 0) {
    initlog("sysinit error!");
  }
}


x86 assembly (clang, -O0):
<sysinit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    1221 <sysinit+0x91>
mov    $0x0,%al
call   1070 <setsid@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
or     (%rax),%edi
call   1040 <console_open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     11f9 <sysinit+0x69>
mov    -0x8(%rbp),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    -0x8(%rbp),%edi
call   1050 <dup@plt>
mov    -0x8(%rbp),%edi
call   1050 <dup@plt>
lea    0xe00(%rip),%rdi
lea    0xdfe(%rip),%rsi
lea    0xdfc(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execl@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x4(%rbp),%rdi
call   10a0 <wait@plt>
cmpl   $0x0,-0x4(%rbp)
jle    1240 <sysinit+0xb0>
lea    0xddc(%rip),%rdi
call   1030 <initlog@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysinit>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     11c4 <sysinit+0x34>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
cmpl   $0x0,0xc(%rsp)
jle    11be <sysinit+0x2e>
lea    0xe5e(%rip),%rdi
call   1030 <initlog@plt>
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1070 <setsid@plt>
mov    0x2e16(%rip),%rax
mov    0x2dff(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   1040 <console_open@plt>
test   %eax,%eax
js     120b <sysinit+0x7b>
mov    %eax,%ebx
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
lea    0xdee(%rip),%rdi
lea    0xdec(%rip),%rsi
lea    0xdea(%rip),%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@TIOCSCTTY = global i32 0
@.str = [10 x i8] c"/bin/bash\00"
@.str.1 = [5 x i8] c"bash\00"
@.str.2 = [13 x i8] c"/etc/sysinit\00"
@.str.3 = [15 x i8] c"sysinit error!\00"
define void @sysinit() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %23
5: ; preds = %0
%6 = call i32 (...) @setsid()
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = call i32 @console_open(i32 %9)
store i32 %10, i32* %2
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %5
%13 = load i32, i32* %2
%14 = load i32, i32* @TIOCSCTTY
%15 = call i32 @ioctl(i32 %13, i32 %14, i32 1)
%16 = load i32, i32* %2
%17 = call i32 @dup(i32 %16)
%18 = load i32, i32* %2
%19 = call i32 @dup(i32 %18)
br label %20
20: ; preds = %12, %5
%21 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* null)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %0
%24 = call i32 @wait(i32* %1)
%25 = load i32, i32* %1
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @initlog(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
ret void
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@TIOCSCTTY = global i32 0
@.str = [10 x i8] c"/bin/bash\00"
@.str.1 = [5 x i8] c"bash\00"
@.str.2 = [13 x i8] c"/etc/sysinit\00"
@.str.3 = [15 x i8] c"sysinit error!\00"
define void @sysinit() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %0
%6 = tail call i32 (...) @setsid()
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %8, %7
%10 = tail call i32 @console_open(i32 %9)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %5
%13 = load i32, i32* @TIOCSCTTY
%14 = tail call i32 @ioctl(i32 %10, i32 %13, i32 1)
%15 = tail call i32 @dup(i32 %10)
%16 = tail call i32 @dup(i32 %10)
br label %17
17: ; preds = %12, %5
%18 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* null)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i32 @wait(i32* %1)
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @initlog(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
ret void
}