#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*/ O_WRONLY;
int check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
int write(int, char *, int);
void setgroups() {
  int fd = check(open("/proc/self/setgroups", O_WRONLY), "open(setgroups)");
  if (write(fd, "deny", 5) != 5) {
    err(1, "write(setgroups)");
  }
  check(close(fd), "close(setgroups)");
}


x86 assembly (clang, -O0):
<setgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%edi
lea    0xe9f(%rip),%rsi
call   1070 <check@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe9d(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
je     11ac <setgroups+0x5c>
mov    $0x1,%edi
lea    0xe83(%rip),%rsi
call   1050 <err@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%edi
lea    0xe7e(%rip),%rsi
call   1070 <check@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setgroups>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
lea    0xea8(%rip),%rsi
mov    %eax,%edi
call   1070 <check@plt>
mov    %eax,%ebx
lea    0xea8(%rip),%rsi
mov    %eax,%edi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
je     119f <setgroups+0x4f>
lea    0xe95(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe8e(%rip),%rsi
mov    %eax,%edi
pop    %rbx
jmp    1070 <check@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"/proc/self/setgroups\00"
@O_WRONLY = global i32 0
@.str.1 = [16 x i8] c"open(setgroups)\00"
@.str.2 = [5 x i8] c"deny\00"
@.str.3 = [17 x i8] c"write(setgroups)\00"
@.str.4 = [17 x i8] c"close(setgroups)\00"
define void @setgroups() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = call i32 @check(i32 %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%7 = icmp ne i32 %6, 5
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* %1
%12 = call i32 @close(i32 %11)
%13 = call i32 @check(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
ret void
}

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