#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
int WriteFile(char *, char *, ...);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int setresgid(int, int, int);
int setresuid(int, int, int);
int /*<<< orphan*/ stderr;
void SetupUserNamespace(int uid, int gid, int new_uid, int new_gid) {
  int r = WriteFile("/proc/self/setgroups", "deny");
  if (r < 0 && errno != ENOENT) {
    perror("WriteFile(\"/proc/self/setgroups\", \"deny\")");
    exit(EXIT_FAILURE);
  }
  if ((WriteFile("/proc/self/uid_map", "%d %d 1\n", new_uid, uid)) == -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"
                    ":"
                    "629"
                    ": ");
    perror("WriteFile(\"/proc/self/uid_map\", \"%d %d 1\\n\", new_uid, uid)");
    exit(EXIT_FAILURE);
  };
  if ((WriteFile("/proc/self/gid_map", "%d %d 1\n", new_gid, gid)) == -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"
                    ":"
                    "630"
                    ": ");
    perror("WriteFile(\"/proc/self/gid_map\", \"%d %d 1\\n\", new_gid, gid)");
    exit(EXIT_FAILURE);
  };
  if ((setresuid(new_uid, new_uid, new_uid)) == -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"
                    ":"
                    "632"
                    ": ");
    perror("setresuid(new_uid, new_uid, new_uid)");
    exit(EXIT_FAILURE);
  };
  if ((setresgid(new_gid, new_gid, new_gid)) == -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"
                    ":"
                    "633"
                    ": ");
    perror("setresgid(new_gid, new_gid, new_gid)");
    exit(EXIT_FAILURE);
  };
}


x86 assembly (clang, -O0):
<SetupUserNamespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1060 <WriteFile@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ca <SetupUserNamespace+0x6a>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11ca <SetupUserNamespace+0x6a>
lea    0xe63(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    0xe6d(%rip),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <WriteFile@plt>
cmp    $0xffffffff,%eax
jne    121d <SetupUserNamespace+0xbd>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xf03(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xf1e(%rip),%rdi
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1060 <WriteFile@plt>
cmp    $0xffffffff,%eax
jne    1270 <SetupUserNamespace+0x110>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xf0a(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xfab(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <setresuid@plt>
cmp    $0xffffffff,%eax
jne    12b6 <SetupUserNamespace+0x156>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xfac(%rip),%rsi
call   1050 <fprintf@plt>
lea    0x104d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <setresgid@plt>
cmp    $0xffffffff,%eax
jne    12fc <SetupUserNamespace+0x19c>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0x1038(%rip),%rsi
call   1050 <fprintf@plt>
lea    0x10d9(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetupUserNamespace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%r15d
lea    0xe88(%rip),%rdi
lea    0xe96(%rip),%rsi
xor    %eax,%eax
call   1060 <WriteFile@plt>
test   %eax,%eax
jns    11a4 <SetupUserNamespace+0x44>
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%rax
jne    1285 <SetupUserNamespace+0x125>
lea    0xe99(%rip),%rdi
lea    0xea5(%rip),%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <WriteFile@plt>
cmp    $0xffffffff,%eax
je     120d <SetupUserNamespace+0xad>
lea    0xf7e(%rip),%rdi
lea    0xe86(%rip),%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <WriteFile@plt>
cmp    $0xffffffff,%eax
je     122b <SetupUserNamespace+0xcb>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %ebp,%edx
call   1030 <setresuid@plt>
cmp    $0xffffffff,%eax
je     1249 <SetupUserNamespace+0xe9>
mov    %ebx,%edi
mov    %ebx,%esi
mov    %ebx,%edx
call   1040 <setresgid@plt>
cmp    $0xffffffff,%eax
je     1267 <SetupUserNamespace+0x107>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xee4(%rip),%rdi
jmp    128c <SetupUserNamespace+0x12c>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xf20(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xfc1(%rip),%rdi
jmp    128c <SetupUserNamespace+0x12c>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xfea(%rip),%rsi
call   1050 <fprintf@plt>
lea    0x108b(%rip),%rdi
jmp    128c <SetupUserNamespace+0x12c>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0x109e(%rip),%rsi
call   1050 <fprintf@plt>
lea    0x113f(%rip),%rdi
jmp    128c <SetupUserNamespace+0x12c>
lea    0xd8e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"/proc/self/setgroups\00"
@.str.1 = [5 x i8] c"deny\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [42 x i8] c"WriteFile(\22/proc/self/setgroups\22, \22deny\22)\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"/proc/self/uid_map\00"
@.str.4 = [9 x i8] c"%d %d 1\0A\00"
@stderr = global i32 0
@.str.5 = [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:629: \00"
@.str.6 = [59 x i8] c"WriteFile(\22/proc/self/uid_map\22, \22%d %d 1\\n\22, new_uid, uid)\00"
@.str.7 = [19 x i8] c"/proc/self/gid_map\00"
@.str.8 = [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:630: \00"
@.str.9 = [59 x i8] c"WriteFile(\22/proc/self/gid_map\22, \22%d %d 1\\n\22, new_gid, gid)\00"
@.str.10 = [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:632: \00"
@.str.11 = [37 x i8] c"setresuid(new_uid, new_uid, new_uid)\00"
@.str.12 = [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:633: \00"
@.str.13 = [37 x i8] c"setresgid(new_gid, new_gid, new_gid)\00"
define void @SetupUserNamespace(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = call i32 (i8*, i8*, ...) @WriteFile(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %4
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENOENT
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13, %4
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = call i32 (i8*, i8*, ...) @WriteFile(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %21
%33 = load i32, i32* %8
%34 = load i32, i32* %6
%35 = call i32 (i8*, i8*, ...) @WriteFile(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %33, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.8, i64 0, i64 0))
%40 = call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %32
%44 = load i32, i32* %7
%45 = load i32, i32* %7
%46 = load i32, i32* %7
%47 = call i32 @setresuid(i32 %44, i32 %45, i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %55
49: ; preds = %43
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.10, i64 0, i64 0))
%52 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %43
%56 = load i32, i32* %8
%57 = load i32, i32* %8
%58 = load i32, i32* %8
%59 = call i32 @setresgid(i32 %56, i32 %57, i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %67
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.12, i64 0, i64 0))
%64 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %55
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"/proc/self/setgroups\00"
@.str.1 = [5 x i8] c"deny\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [42 x i8] c"WriteFile(\22/proc/self/setgroups\22, \22deny\22)\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"/proc/self/uid_map\00"
@.str.4 = [9 x i8] c"%d %d 1\0A\00"
@stderr = global i32 0
@.str.5 = [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:629: \00"
@.str.6 = [59 x i8] c"WriteFile(\22/proc/self/uid_map\22, \22%d %d 1\\n\22, new_uid, uid)\00"
@.str.7 = [19 x i8] c"/proc/self/gid_map\00"
@.str.8 = [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:630: \00"
@.str.9 = [59 x i8] c"WriteFile(\22/proc/self/gid_map\22, \22%d %d 1\\n\22, new_gid, gid)\00"
@.str.10 = [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:632: \00"
@.str.11 = [37 x i8] c"setresuid(new_uid, new_uid, new_uid)\00"
@.str.12 = [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:633: \00"
@.str.13 = [37 x i8] c"setresgid(new_gid, new_gid, new_gid)\00"
define void @SetupUserNamespace(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 (i8*, i8*, ...) @WriteFile(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7, %4
%16 = tail call i32 (i8*, i8*, ...) @WriteFile(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %2, i32 %0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = tail call i32 (i8*, i8*, ...) @WriteFile(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %3, i32 %1)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.8, i64 0, i64 0))
%30 = tail call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %24
%34 = tail call i32 @setresuid(i32 %2, i32 %2, i32 %2)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.10, i64 0, i64 0))
%39 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %33
%43 = tail call i32 @setresgid(i32 %3, i32 %3, i32 %3)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.12, i64 0, i64 0))
%48 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = tail call i32 @exit(i32 %49)
unreachable
51: ; preds = %42
ret void
}