#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*/ MS_BIND;
int O_CREAT;
int O_RDONLY;
int close(int);
int /*<<< orphan*/ exit(int);
int mkdir(char *, int);
int mount(char const *, char const *, int /*<<< orphan*/ *, int /*<<< orphan*/,
          int /*<<< orphan*/ *);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
void SetupSlashDev() {
  if ((mkdir("dev", 0755)) == -1) {
    perror("mkdir(\"dev\", 0755)");
    exit(1);
  };
  const char *devs[] = {"/dev/null", "/dev/random", "/dev/urandom", "/dev/zero",
                        NULL};
  for (int i = 0; devs[i] != NULL; i++) {
    int handle = open(devs[i] + 1, O_CREAT | O_RDONLY, 0644);
    if ((handle) == -1) {
      perror("handle");
      exit(1);
    };
    if ((close(handle)) == -1) {
      perror("close(handle)");
      exit(1);
    };
    if ((mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)) == -1) {
      perror("mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)");
      exit(1);
    };
  }
}


x86 assembly (clang, -O0):
<SetupSlashDev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11a8 <SetupSlashDev+0x38>
lea    0xe6b(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0xe58(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe58(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmpq   $0x0,-0x30(%rbp,%rax,8)
je     12cc <SetupSlashDev+0x15c>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
add    $0x1,%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    0x2dc8(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1247 <SetupSlashDev+0xd7>
lea    0xe0c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    126e <SetupSlashDev+0xfe>
lea    0xdec(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
add    $0x1,%rsi
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1040 <mount@plt>
cmp    $0xffffffff,%eax
jne    12b9 <SetupSlashDev+0x149>
lea    0xdaf(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12be <SetupSlashDev+0x14e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11eb <SetupSlashDev+0x7b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetupSlashDev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe8b(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1265 <SetupSlashDev+0x105>
movq   $0x0,0x20(%rsp)
lea    0xe7f(%rip),%r14
mov    %r14,(%rsp)
lea    0x8(%rsp),%r15
lea    0xe79(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe79(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe7a(%rip),%rax
mov    %rax,0x18(%rsp)
mov    0x2e2c(%rip),%r12
mov    0x2e0d(%rip),%r13
mov    0x2dfe(%rip),%rbp
nopw   0x0(%rax,%rax,1)
lea    0x1(%r14),%rbx
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     123d <SetupSlashDev+0xdd>
mov    %eax,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1246 <SetupSlashDev+0xe6>
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1040 <mount@plt>
cmp    $0xffffffff,%eax
je     124f <SetupSlashDev+0xef>
mov    (%r15),%r14
add    $0x8,%r15
test   %r14,%r14
jne    11e0 <SetupSlashDev+0x80>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe00(%rip),%rdi
jmp    1256 <SetupSlashDev+0xf6>
lea    0xdfe(%rip),%rdi
jmp    1256 <SetupSlashDev+0xf6>
lea    0xe03(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xd98(%rip),%rdi
jmp    1256 <SetupSlashDev+0xf6>

LLVM IR (-O0):
@.str = [4 x i8] c"dev\00"
@.str.1 = [19 x i8] c"mkdir(\22dev\22, 0755)\00"
@.str.2 = [10 x i8] c"/dev/null\00"
@.str.3 = [12 x i8] c"/dev/random\00"
@.str.4 = [13 x i8] c"/dev/urandom\00"
@.str.5 = [10 x i8] c"/dev/zero\00"
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.6 = [7 x i8] c"handle\00"
@.str.7 = [14 x i8] c"close(handle)\00"
@MS_BIND = global i32 0
@.str.8 = [49 x i8] c"mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)\00"
define void @SetupSlashDev() {
%1 = alloca [5 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 493)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = bitcast [5 x i8*]* %1 to i8*
%11 = bitcast i8* %10 to [5 x i8*]*
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i32 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i32 0, i32 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i32 0, i32 2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i32 0, i32 3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8** %15
store i32 0, i32* %2
br label %16
16: ; preds = %61, %9
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %64
22: ; preds = %16
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i32, i32* @O_CREAT
%29 = load i32, i32* @O_RDONLY
%30 = or i32 %28, %29
%31 = call i32 @open(i8* %27, i32 %30, i32 420)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %22
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %22
%38 = load i32, i32* %3
%39 = call i32 @close(i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %50
%52 = load i8*, i8** %51
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = load i32, i32* @MS_BIND
%55 = call i32 @mount(i8* %48, i8* %53, i32* null, i32 %54, i32* null)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %44
%58 = call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %44
br label %61
61: ; preds = %60
%62 = load i32, i32* %2
%63 = add nsw i32 %62, 1
store i32 %63, i32* %2
br label %16
64: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"dev\00"
@.str.1 = [19 x i8] c"mkdir(\22dev\22, 0755)\00"
@.str.2 = [10 x i8] c"/dev/null\00"
@.str.3 = [12 x i8] c"/dev/random\00"
@.str.4 = [13 x i8] c"/dev/urandom\00"
@.str.5 = [10 x i8] c"/dev/zero\00"
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.6 = [7 x i8] c"handle\00"
@.str.7 = [14 x i8] c"close(handle)\00"
@MS_BIND = global i32 0
@.str.8 = [49 x i8] c"mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)\00"
define void @SetupSlashDev() {
%1 = alloca [5 x i8*]
%2 = tail call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 493)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = bitcast [5 x i8*]* %1 to i8*
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 4
%10 = bitcast i8** %9 to i64*
store i64 0, i64* %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %14
br label %20
15: ; preds = %38
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %42
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
ret void
20: ; preds = %7, %15
%21 = phi i64 [ 0, %7 ], [ %42, %15 ]
%22 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %7 ], [ %17, %15 ]
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i32, i32* @O_CREAT
%25 = load i32, i32* @O_RDONLY
%26 = or i32 %25, %24
%27 = tail call i32 @open(i8* %23, i32 %26, i32 420)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = tail call i32 @close(i32 %27)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = load i32, i32* @MS_BIND
%40 = tail call i32 @mount(i8* %22, i8* %23, i32* null, i32 %39, i32* null)
%41 = icmp eq i32 %40, -1
%42 = add nuw i64 %21, 1
br i1 %41, label %43, label %15
43: ; preds = %38
%44 = tail call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%45 = tail call i32 @exit(i32 1)
unreachable
}