#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 int /*<<< orphan*/ cmdline;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void setup_setgroups() {
  char cmdline[PATH_MAX];
  int fd = open("/proc/self/setgroups", O_WRONLY);
  int status __attribute__((unused));
  if (fd >= 0) {
    snprintf(cmdline, sizeof(cmdline), "deny");
    status = write(fd, cmdline, strlen(cmdline));
    close(fd);
  }
}


x86 assembly (clang, -O0):
<setup_setgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x28(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x10(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11e8 <setup_setgroups+0x98>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xe5a(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_setgroups>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e8f(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11c0 <setup_setgroups+0x70>
mov    %eax,%r15d
lea    0xe7d(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
call   1060 <close@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [21 x i8] c"/proc/self/setgroups\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"deny\00"
define void @setup_setgroups() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %1
%8 = alloca i8, i64 %6
store i64 %6, i64* %2
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %0
%14 = trunc i64 %6 to i32
%15 = call i32 @snprintf(i8* %8, i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = call i32 @strlen(i8* %8)
%18 = call i32 @write(i32 %16, i8* %8, i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %13, %0
%22 = load i8*, i8** %1
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [21 x i8] c"/proc/self/setgroups\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"deny\00"
define void @setup_setgroups() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = call i32 @snprintf(i8* %3, i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @strlen(i8* %3)
%10 = call i32 @write(i32 %5, i8* %3, i32 %9)
%11 = call i32 @close(i32 %5)
br label %12
12: ; preds = %7, %0
ret void
}