#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*/ _error(char const *, int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execv(char const *, char *const *);
int /*<<< orphan*/ execve(char const *, char *const *, int /*<<< orphan*/ *);
scalar_t__ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int setsid();
void _oinit_child(void) {
  const char rc[] = "/etc/rc";
  char *const rc_argv[] = {"rc", NULL};
  const char sh[] = "/bin/sh";
  char *const sh_argv[] = {"sh", "-i", NULL};
  if (setsid() == -1)
    _error("setsid", 1);
  else if (setpgid(0, 0) != 0)
    _error("setpgid", 1);
  execve(rc, rc_argv, NULL);
  _error(rc, 1);
  execv(sh, sh_argv);
  _error(sh, 1);
  _exit(errno);
}


x86 assembly (clang, -O0):
<_oinit_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2c76(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c73(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe78(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c65(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c62(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c5f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11db <_oinit_child+0x7b>
lea    0xe47(%rip),%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
jmp    1204 <_oinit_child+0xa4>
xor    %esi,%esi
mov    %esi,%edi
call   1070 <setpgid@plt>
cmp    $0x0,%rax
je     11ff <_oinit_child+0x9f>
lea    0xe25(%rip),%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
jmp    1204 <_oinit_child+0xa4>
lea    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execve@plt>
lea    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
lea    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <execv@plt>
lea    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<_oinit_child>:
push   %rbx
sub    $0x40,%rsp
movabs $0x63722f6374652f,%rax
mov    %rax,0x8(%rsp)
movaps 0x2c75(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x68732f6e69622f,%rax
mov    %rax,(%rsp)
mov    0x2c7b(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c5f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11bb <_oinit_child+0x5b>
lea    0xe50(%rip),%rdi
jmp    11d0 <_oinit_child+0x70>
xor    %edi,%edi
xor    %esi,%esi
call   1070 <setpgid@plt>
test   %rax,%rax
je     11da <_oinit_child+0x7a>
lea    0xe40(%rip),%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
lea    0x8(%rsp),%rbx
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <execve@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
mov    %rsp,%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <execv@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <_error@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@__const._oinit_child.rc = [8 x i8] c"/etc/rc\00"
@.str = [3 x i8] c"rc\00"
@__const._oinit_child.rc_argv = [2 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* null]
@__const._oinit_child.sh = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-i\00"
@__const._oinit_child.sh_argv = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [7 x i8] c"setsid\00"
@.str.4 = [8 x i8] c"setpgid\00"
@errno = global i32 0
define void @_oinit_child() {
%1 = alloca [8 x i8]
%2 = alloca [2 x i8*]
%3 = alloca [8 x i8]
%4 = alloca [3 x i8*]
%5 = bitcast [8 x i8]* %1 to i8*
%6 = bitcast [2 x i8*]* %2 to i8*
%7 = bitcast [8 x i8]* %3 to i8*
%8 = bitcast [3 x i8*]* %4 to i8*
%9 = call i32 (...) @setsid()
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %19
13: ; preds = %0
%14 = call i64 @setpgid(i32 0, i32 0)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %18
18: ; preds = %16, %13
br label %19
19: ; preds = %18, %11
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%22 = call i32 @execve(i8* %20, i8** %21, i32* null)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%24 = call i32 @_error(i8* %23, i32 1)
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%27 = call i32 @execv(i8* %25, i8** %26)
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%29 = call i32 @_error(i8* %28, i32 1)
%30 = load i32, i32* @errno
%31 = call i32 @_exit(i32 %30)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"rc\00"
@__const._oinit_child.rc_argv = [2 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-i\00"
@__const._oinit_child.sh_argv = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [7 x i8] c"setsid\00"
@.str.4 = [8 x i8] c"setpgid\00"
@errno = global i32 0
define void @_oinit_child() {
%1 = alloca i64
%2 = alloca [2 x i8*]
%3 = alloca i64
%4 = alloca [3 x i8*]
%5 = bitcast i64* %1 to i8*
store i64 27991570551956783, i64* %1
%6 = bitcast [2 x i8*]* %2 to i8*
%7 = bitcast i64* %3 to i8*
store i64 29400045130965551, i64* %3
%8 = bitcast [3 x i8*]* %4 to i8*
%9 = tail call i32 (...) @setsid()
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = tail call i64 @setpgid(i32 0, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11, %0
%15 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %0 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %11 ]
%16 = tail call i32 @_error(i8* %15, i32 1)
br label %17
17: ; preds = %14, %11
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%19 = call i32 @execve(i8* %5, i8** %18, i32* null)
%20 = call i32 @_error(i8* %5, i32 1)
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%22 = call i32 @execv(i8* %7, i8** %21)
%23 = call i32 @_error(i8* %7, i32 1)
%24 = load i32, i32* @errno
%25 = call i32 @_exit(i32 %24)
unreachable
}