#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 */
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
char *string(char *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
void denysetgroups(pid_t pid) {
  char *path, *text = "deny";
  int fd;
  path = string("/proc/%d/setgroups", pid);
  if ((fd = open(path, O_WRONLY)) < 0)
    die(0, "Failed to disable setgroups() in container");
  else if (write(fd, text, strlen(text)) != (ssize_t)strlen(text))
    die(0, "Failed to disable setgroups() in container");
  close(fd);
  free(path);
}


x86 assembly (clang, -O0):
<denysetgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1060 <string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11ca <denysetgroups+0x5a>
xor    %edi,%edi
lea    0xe58(%rip),%rsi
call   1090 <die@plt>
jmp    1220 <denysetgroups+0xb0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     121b <denysetgroups+0xab>
xor    %edi,%edi
lea    0xe02(%rip),%rsi
call   1090 <die@plt>
jmp    1220 <denysetgroups+0xb0>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<denysetgroups>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%esi
lea    0xe99(%rip),%rdi
call   1050 <string@plt>
mov    %rax,%rbx
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11a4 <denysetgroups+0x44>
lea    0xe6e(%rip),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
call   1040 <write@plt>
cmp    $0x4,%rax
je     11b2 <denysetgroups+0x52>
lea    0xe6d(%rip),%rsi
xor    %edi,%edi
call   1080 <die@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"deny\00"
@.str.1 = [19 x i8] c"/proc/%d/setgroups\00"
@O_WRONLY = global i32 0
@.str.2 = [43 x i8] c"Failed to disable setgroups() in container\00"
define void @denysetgroups(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i32, i32* %2
%7 = call i8* @string(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @die(i32 0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %26
14: ; preds = %1
%15 = load i32, i32* %5
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = call i64 @write(i32 %15, i8* %16, i64 %18)
%20 = load i8*, i8** %4
%21 = call i64 @strlen(i8* %20)
%22 = icmp ne i64 %19, %21
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @die(i32 0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %14
br label %26
26: ; preds = %25, %12
%27 = load i32, i32* %5
%28 = call i32 @close(i32 %27)
%29 = load i8*, i8** %3
%30 = call i32 @free(i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"deny\00"
@.str.1 = [19 x i8] c"/proc/%d/setgroups\00"
@O_WRONLY = global i32 0
@.str.2 = [43 x i8] c"Failed to disable setgroups() in container\00"
define void @denysetgroups(i32 %0) {
%2 = tail call i8* @string(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* %2, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i64 @write(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%8 = icmp eq i64 %7, 4
br i1 %8, label %11, label %9
9: ; preds = %6, %1
%10 = tail call i32 @die(i32 0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = tail call i32 @close(i32 %4)
%13 = tail call i32 @free(i8* %2)
ret void
}