#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 */
struct child_options {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ PR_SET_PDEATHSIG;
int /*<<< orphan*/ SIGKILL;
int dispatch_command(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ prctl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                 int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int setup_fs(struct child_options const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
char *strerror(int const);
int child_main(const struct child_options *child_options) {
  if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0) < 0) {
    perror("prctl");
    fputs("Child won't die even if parent does.\n", stderr);
  }
  int ret = setup_fs(child_options);
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("Setting up root filesystem");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      return 1;
    }
  } while (0);
  ssize_t size;
  size_t bufsize;
  char *str = NULL;
  while ((size = getline(&str, &bufsize, stdin)) > 0) {
    char *newline = strchr(str, '\n');
    if (newline)
      *newline = '\0';
    ret = dispatch_command(str);
    if (ret < 0) {
      fprintf(stderr, "%s\n", strerror(-ret));
      puts("error");
    }
    fflush(stdout);
  }
  free(str);
  return ret < 0 ? 1 : 0;
}


x86 assembly (clang, -O0):
<child_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1090 <prctl@plt>
cmp    $0x0,%rax
jge    1217 <child_main+0x57>
lea    0xe03(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xdf4(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1040 <setup_fs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    128f <child_main+0xcf>
lea    0xdf2(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1283 <child_main+0xc3>
mov    -0x20(%rbp),%rdi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
xor    %edi,%edi
sub    -0x18(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xdc9(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <child_main+0x19b>
jmp    1294 <child_main+0xd4>
movq   $0x0,-0x38(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10c0 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    133f <child_main+0x17f>
mov    -0x38(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12e2 <child_main+0x122>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   10d0 <dispatch_command@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    132c <child_main+0x16c>
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
xor    %edi,%edi
sub    -0x14(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd2e(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd26(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    129c <child_main+0xdc>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <prctl@plt>
test   %rax,%rax
js     1320 <child_main+0x160>
mov    %rbx,%rdi
call   1040 <setup_fs@plt>
mov    %eax,%ebx
test   %eax,%eax
js     12d7 <child_main+0x117>
movq   $0x0,0x8(%rsp)
mov    0x2dce(%rip),%r14
mov    (%r14),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10c0 <getline@plt>
test   %eax,%eax
jle    12c8 <child_main+0x108>
mov    0x2d85(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    126a <child_main+0xaa>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
call   10a0 <fflush@plt>
mov    (%r14),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   10c0 <getline@plt>
test   %eax,%eax
jle    12c8 <child_main+0x108>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1289 <child_main+0xc9>
movb   $0x0,(%rax)
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <dispatch_command@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1250 <child_main+0x90>
mov    0x2d32(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
neg    %edi
call   10e0 <strerror@plt>
mov    %ebp,%edi
lea    0xd97(%rip),%rsi
mov    %rax,%rdx
call   1080 <fprintf@plt>
lea    0xd8c(%rip),%rdi
call   1050 <puts@plt>
jmp    1250 <child_main+0x90>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
shr    $0x1f,%ebx
jmp    130f <child_main+0x14f>
mov    0x2cf2(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xd44(%rip),%rdi
call   1070 <fputs@plt>
mov    0x0(%rbp),%ebp
neg    %ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xd47(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd9(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
lea    0xcca(%rip),%rdi
call   1070 <fputs@plt>
jmp    11f8 <child_main+0x38>

LLVM IR (-O0):
%struct.child_options = type { i32 }
@PR_SET_PDEATHSIG = global i32 0
@SIGKILL = global i32 0
@.str = [6 x i8] c"prctl\00"
@.str.1 = [38 x i8] c"Child won't die even if parent does.\0A\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Setting up root filesystem\00"
@.str.3 = [6 x i8] c": %s\0A\00"
@stdin = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [6 x i8] c"error\00"
@stdout = global i32 0
define i32 @child_main(%struct.child_options* %0) {
%2 = alloca i32
%3 = alloca %struct.child_options*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store %struct.child_options* %0, %struct.child_options** %3
%11 = load i32, i32* @PR_SET_PDEATHSIG
%12 = load i32, i32* @SIGKILL
%13 = call i64 @prctl(i32 %11, i32 %12, i32 0, i32 0, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %1
%20 = load %struct.child_options*, %struct.child_options** %3
%21 = call i32 @setup_fs(%struct.child_options* %20)
store i32 %21, i32* %4
br label %22
22: ; preds = %19
%23 = load i32, i32* %4
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %22
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = load i8*, i8** %6
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* %30, i32 %31)
%33 = load i32, i32* @stderr
%34 = load i32, i32* %5
%35 = sub nsw i32 0, %34
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %29, %26
store i32 1, i32* %2
br label %74
39: ; preds = %22
br label %40
40: ; preds = %39
store i8* null, i8** %9
br label %41
41: ; preds = %64, %40
%42 = load i32, i32* @stdin
%43 = call i32 @getline(i8** %9, i64* %8, i32 %42)
store i32 %43, i32* %7
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %67
45: ; preds = %41
%46 = load i8*, i8** %9
%47 = call i8* @strchr(i8* %46, i8 signext 10)
store i8* %47, i8** %10
%48 = load i8*, i8** %10
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = load i8*, i8** %10
store i8 0, i8* %51
br label %52
52: ; preds = %50, %45
%53 = load i8*, i8** %9
%54 = call i32 @dispatch_command(i8* %53)
store i32 %54, i32* %4
%55 = load i32, i32* %4
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %52
%58 = load i32, i32* @stderr
%59 = load i32, i32* %4
%60 = sub nsw i32 0, %59
%61 = call i8* @strerror(i32 %60)
%62 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %57, %52
%65 = load i32, i32* @stdout
%66 = call i32 @fflush(i32 %65)
br label %41
67: ; preds = %41
%68 = load i8*, i8** %9
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* %4
%71 = icmp slt i32 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i32 1, i32 0
store i32 %73, i32* %2
br label %74
74: ; preds = %67, %38
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
%struct.child_options = type { i32 }
@PR_SET_PDEATHSIG = global i32 0
@SIGKILL = global i32 0
@.str = [6 x i8] c"prctl\00"
@.str.1 = [38 x i8] c"Child won't die even if parent does.\0A\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Setting up root filesystem\00"
@.str.3 = [6 x i8] c": %s\0A\00"
@stdin = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [6 x i8] c"error\00"
@stdout = global i32 0
define i32 @child_main(%struct.child_options* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = load i32, i32* @PR_SET_PDEATHSIG
%5 = load i32, i32* @SIGKILL
%6 = tail call i64 @prctl(i32 %4, i32 %5, i32 0, i32 0, i32 0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %1
%13 = tail call i32 @setup_fs(%struct.child_options* %0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @stderr
%19 = sub nsw i32 0, %13
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %55
22: ; preds = %12
%23 = bitcast i64* %2 to i8*
%24 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%25 = load i32, i32* @stdin
%26 = call i32 @getline(i8** %3, i64* %2, i32 %25)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %50
28: ; preds = %22, %44
%29 = load i8*, i8** %3
%30 = call i8* @strchr(i8* dereferenceable(1) %29, i8 signext 10)
%31 = icmp eq i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %28
store i8 0, i8* %30
%33 = load i8*, i8** %3
br label %34
34: ; preds = %32, %28
%35 = phi i8* [ %33, %32 ], [ %29, %28 ]
%36 = call i32 @dispatch_command(i8* %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = sub nsw i32 0, %36
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %38, %34
%45 = load i32, i32* @stdout
%46 = call i32 @fflush(i32 %45)
%47 = load i32, i32* @stdin
%48 = call i32 @getline(i8** %3, i64* %2, i32 %47)
%49 = icmp sgt i32 %48, 0
br i1 %49, label %28, label %50
50: ; preds = %44, %22
%51 = phi i32 [ %13, %22 ], [ %36, %44 ]
%52 = load i8*, i8** %3
%53 = call i32 @free(i8* %52)
%54 = lshr i32 %51, 31
br label %55
55: ; preds = %15, %50
%56 = phi i32 [ %54, %50 ], [ 1, %15 ]
ret i32 %56
}