#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 stat {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ mount(char *, char *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ poll(int /*<<< orphan*/, int /*<<< orphan*/, int);
int child(void *arg) {
  pid_t pid;
  struct stat s;
  if (mount("proc", "/proc", "proc", 0, NULL)) {
    perror("mount");
    return -1;
  }
  pid = fork();
  if (pid < 0) {
    perror("fork");
    return -1;
  }
  if (!pid) {
    poll(0, 0, -1);
    exit(-1);
  }
  poll(0, 0, -1);
  return 0;
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9e(%rip),%rdx
lea    0xe96(%rip),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1030 <mount@plt>
cmp    $0x0,%rax
je     119b <child+0x4b>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <child+0xb1>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11c9 <child+0x79>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <child+0xb1>
cmpq   $0x0,-0x18(%rbp)
jne    11ec <child+0x9c>
xor    %esi,%esi
mov    $0xffffffff,%edx
mov    %esi,%edi
call   1040 <poll@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
xor    %esi,%esi
mov    $0xffffffff,%edx
mov    %esi,%edi
call   1040 <poll@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rsi
lea    0xea0(%rip),%rdi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <mount@plt>
test   %rax,%rax
jne    11a0 <child+0x50>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11a9 <child+0x59>
mov    %rax,%rbx
xor    %edi,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1040 <poll@plt>
test   %rbx,%rbx
je     11bc <child+0x6c>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe5f(%rip),%rdi
jmp    11b0 <child+0x60>
lea    0xe5c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1197 <child+0x47>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"proc\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [6 x i8] c"mount\00"
@.str.3 = [5 x i8] c"fork\00"
define i32 @child(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = call i64 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0, i32* null)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
10: ; preds = %1
%11 = call i64 (...) @fork()
store i64 %11, i64* %4
%12 = load i64, i64* %4
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
16: ; preds = %10
%17 = load i64, i64* %4
%18 = icmp ne i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32 @poll(i32 0, i32 0, i32 -1)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %16
%23 = call i32 @poll(i32 0, i32 0, i32 -1)
store i32 0, i32* %2
br label %24
24: ; preds = %22, %14, %8
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"proc\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [6 x i8] c"mount\00"
@.str.3 = [5 x i8] c"fork\00"
define i32 @child(i8* nocapture readnone %0) {
%2 = tail call i64 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0, i32* null)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = icmp eq i64 %5, 0
%9 = tail call i32 @poll(i32 0, i32 0, i32 -1)
br i1 %8, label %10, label %15
10: ; preds = %7
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %4, %1
%13 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %4 ]
%14 = tail call i32 @perror(i8* %13)
br label %15
15: ; preds = %12, %7
%16 = phi i32 [ 0, %7 ], [ -1, %12 ]
ret i32 %16
}