#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*/ CreateFile(char const *);
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ MS_BIND;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int mkdir(char *, int);
int mount(char const *, char const *, int /*<<< orphan*/ *, int /*<<< orphan*/,
          int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int symlink(char *, char *);
void SetupDevices() {
  if ((mkdir("dev", 0755)) == -1) {
    fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/"
                    "heads/master/src/namespace-sandbox/namespace-sandbox.c"
                    ":"
                    "411"
                    ": ");
    perror("mkdir(\"dev\", 0755)");
    exit(EXIT_FAILURE);
  };
  const char *devs[] = {"/dev/null", "/dev/random", "/dev/urandom", "/dev/zero",
                        NULL};
  for (int i = 0; devs[i] != NULL; i++) {
    CreateFile(devs[i] + 1);
    if ((mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)) == -1) {
      fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/"
                      "heads/master/src/namespace-sandbox/namespace-sandbox.c"
                      ":"
                      "416"
                      ": ");
      perror("mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)");
      exit(EXIT_FAILURE);
    };
  }
  if ((symlink("/proc/self/fd", "dev/fd")) == -1) {
    fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/"
                    "heads/master/src/namespace-sandbox/namespace-sandbox.c"
                    ":"
                    "419"
                    ": ");
    perror("symlink(\"/proc/self/fd\", \"dev/fd\")");
    exit(EXIT_FAILURE);
  };
}


x86 assembly (clang, -O0):
<SetupDevices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe71(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11d1 <SetupDevices+0x51>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xef3(%rip),%rdi
call   1090 <perror@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xedc(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xedb(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xedc(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xede(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmpq   $0x0,-0x30(%rbp,%rax,8)
je     12ad <SetupDevices+0x12d>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
add    $0x1,%rdi
call   1080 <CreateFile@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    0x2d95(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1040 <mount@plt>
cmp    $0xffffffff,%eax
jne    129a <SetupDevices+0x11a>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xf17(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    129f <SetupDevices+0x11f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1214 <SetupDevices+0x94>
lea    0xf1b(%rip),%rdi
lea    0xf22(%rip),%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
jne    12f8 <SetupDevices+0x178>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xf0b(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xfac(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetupDevices>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe7e(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1264 <SetupDevices+0xf4>
movq   $0x0,0x20(%rsp)
lea    0xf1f(%rip),%rbx
mov    %rbx,(%rsp)
lea    0x8(%rsp),%r15
lea    0xf19(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xf19(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xf1a(%rip),%rax
mov    %rax,0x18(%rsp)
mov    0x2e0f(%rip),%r12
nopl   0x0(%rax)
lea    0x1(%rbx),%r14
mov    %r14,%rdi
call   1070 <CreateFile@plt>
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1040 <mount@plt>
cmp    $0xffffffff,%eax
je     1235 <SetupDevices+0xc5>
mov    (%r15),%rbx
add    $0x8,%r15
test   %rbx,%rbx
jne    11e0 <SetupDevices+0x70>
lea    0xfb7(%rip),%rdi
lea    0xfbe(%rip),%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
je     1282 <SetupDevices+0x112>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xf4d(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe31(%rip),%rdi
jmp    1251 <SetupDevices+0xe1>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xf52(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xff3(%rip),%rdi
jmp    1251 <SetupDevices+0xe1>

LLVM IR (-O0):
@.str = [4 x i8] c"dev\00"
@stderr = global i32 0
@.str.1 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:411: \00"
@.str.2 = [19 x i8] c"mkdir(\22dev\22, 0755)\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [10 x i8] c"/dev/null\00"
@.str.4 = [12 x i8] c"/dev/random\00"
@.str.5 = [13 x i8] c"/dev/urandom\00"
@.str.6 = [10 x i8] c"/dev/zero\00"
@MS_BIND = global i32 0
@.str.7 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:416: \00"
@.str.8 = [49 x i8] c"mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)\00"
@.str.9 = [14 x i8] c"/proc/self/fd\00"
@.str.10 = [7 x i8] c"dev/fd\00"
@.str.11 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:419: \00"
@.str.12 = [35 x i8] c"symlink(\22/proc/self/fd\22, \22dev/fd\22)\00"
define void @SetupDevices() {
%1 = alloca [5 x i8*]
%2 = alloca i32
%3 = call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 493)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = bitcast [5 x i8*]* %1 to i8*
%13 = bitcast i8* %12 to [5 x i8*]*
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8** %17
store i32 0, i32* %2
br label %18
18: ; preds = %50, %11
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %53
24: ; preds = %18
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @CreateFile(i8* %29)
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i32, i32* @MS_BIND
%41 = call i32 @mount(i8* %34, i8* %39, i32* null, i32 %40, i32* null)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %49
43: ; preds = %24
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.7, i64 0, i64 0))
%46 = call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %24
br label %50
50: ; preds = %49
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %18
53: ; preds = %18
%54 = call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.11, i64 0, i64 0))
%59 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %53
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"dev\00"
@stderr = global i32 0
@.str.1 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:411: \00"
@.str.2 = [19 x i8] c"mkdir(\22dev\22, 0755)\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [10 x i8] c"/dev/null\00"
@.str.4 = [12 x i8] c"/dev/random\00"
@.str.5 = [13 x i8] c"/dev/urandom\00"
@.str.6 = [10 x i8] c"/dev/zero\00"
@MS_BIND = global i32 0
@.str.7 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:416: \00"
@.str.8 = [49 x i8] c"mount(devs[i], devs[i] + 1, NULL, MS_BIND, NULL)\00"
@.str.9 = [14 x i8] c"/proc/self/fd\00"
@.str.10 = [7 x i8] c"dev/fd\00"
@.str.11 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:419: \00"
@.str.12 = [35 x i8] c"symlink(\22/proc/self/fd\22, \22dev/fd\22)\00"
define void @SetupDevices() {
%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 %10
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = bitcast [5 x i8*]* %1 to i8*
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 4
%13 = bitcast i8** %12 to i64*
store i64 0, i64* %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8** %17
br label %25
18: ; preds = %25
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %33
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%24 = icmp eq i32 %23, -1
br i1 %24, label %40, label %46
25: ; preds = %10, %18
%26 = phi i64 [ 0, %10 ], [ %33, %18 ]
%27 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %10 ], [ %20, %18 ]
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = tail call i32 @CreateFile(i8* %28)
%30 = load i32, i32* @MS_BIND
%31 = tail call i32 @mount(i8* %27, i8* %28, i32* null, i32 %30, i32* null)
%32 = icmp eq i32 %31, -1
%33 = add nuw i64 %26, 1
br i1 %32, label %34, label %18
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.7, i64 0, i64 0))
%37 = tail call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %22
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.11, i64 0, i64 0))
%43 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = tail call i32 @exit(i32 %44)
unreachable
46: ; preds = %22
ret void
}