#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;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ write_file(char *, int /*<<< orphan*/, char *, int);
void update_setgroups(int pid, bool setgroup) {
  char *policy;
  if (setgroup)
    policy = "allow";
  else
    policy = "deny";
  if (write_file(policy, strlen(policy), "/proc/%d/setgroups", pid) < 0) {
    if (errno != ENOENT)
      do {
        fprintf(stderr,
                "nsenter: "
                "failed to write '%s' to /proc/%d/setgroups"
                ": %m\n",
                policy, pid);
        exit(2 + 1);
      } while (0);
  }
}


x86 assembly (clang, -O0):
<update_setgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1168 <update_setgroups+0x28>
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1173 <update_setgroups+0x33>
lea    0xe97(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
mov    -0x4(%rbp),%ecx
lea    0xe77(%rip),%rdx
call   1040 <write_file@plt>
cmp    $0x0,%rax
jge    11ed <update_setgroups+0xad>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
je     11e8 <update_setgroups+0xa8>
jmp    11c2 <update_setgroups+0x82>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
jmp    11ed <update_setgroups+0xad>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_setgroups>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
test   %esi,%esi
lea    0xeb8(%rip),%rax
lea    0xeab(%rip),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xea3(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%ecx
call   1040 <write_file@plt>
test   %rax,%rax
jns    118f <update_setgroups+0x4f>
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <update_setgroups+0x56>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"allow\00"
@.str.1 = [5 x i8] c"deny\00"
@.str.2 = [19 x i8] c"/proc/%d/setgroups\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.3 = [57 x i8] c"nsenter: failed to write '%s' to /proc/%d/setgroups: %m\0A\00"
define void @update_setgroups(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
br label %10
9: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %10
10: ; preds = %9, %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = load i32, i32* %3
%15 = call i64 @write_file(i8* %11, i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %10
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
br label %22
22: ; preds = %21
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %5
%25 = load i32, i32* %3
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %24, i32 %25)
%27 = call i32 @exit(i32 3)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %17
br label %30
30: ; preds = %29, %10
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"allow\00"
@.str.1 = [5 x i8] c"deny\00"
@.str.2 = [19 x i8] c"/proc/%d/setgroups\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.3 = [57 x i8] c"nsenter: failed to write '%s' to /proc/%d/setgroups: %m\0A\00"
define void @update_setgroups(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0)
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i64 @write_file(i8* %4, i32 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %0)
%15 = tail call i32 @exit(i32 3)
unreachable
16: ; preds = %8, %2
ret void
}