#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;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
int setgroups_deny(void) {
  int fd;
  ssize_t ret, len;
  const char *deny_str = "deny";
  if ((fd = open("/proc/self/setgroups", O_WRONLY)) == -1) {
    perror("setgroups_deny: open failed");
    return -1;
  }
  len = strlen(deny_str);
  ret = write(fd, deny_str, len);
  close(fd);
  if (ret < 0) {
    perror("setgroups_deny: write failed");
    return -1;
  } else if (ret != len) {
    perror("setgroups_deny: partial write");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setgroups_deny>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    119c <setgroups_deny+0x4c>
lea    0xe8f(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <setgroups_deny+0xca>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmpq   $0x0,-0x10(%rbp)
jge    11e8 <setgroups_deny+0x98>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <setgroups_deny+0xca>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     120e <setgroups_deny+0xbe>
lea    0xe56(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <setgroups_deny+0xca>
jmp    1213 <setgroups_deny+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setgroups_deny>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1192 <setgroups_deny+0x52>
mov    %eax,%ebx
lea    0xe99(%rip),%rsi
mov    $0x4,%edx
mov    %eax,%edi
call   1030 <write@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1040 <close@plt>
test   %r14,%r14
js     119b <setgroups_deny+0x5b>
xor    %eax,%eax
cmp    $0x4,%r14
jne    11a4 <setgroups_deny+0x64>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe81(%rip),%rdi
jmp    11ab <setgroups_deny+0x6b>
lea    0xe94(%rip),%rdi
jmp    11ab <setgroups_deny+0x6b>
lea    0xea8(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    118a <setgroups_deny+0x4a>

LLVM IR (-O0):
@.str = [5 x i8] c"deny\00"
@.str.1 = [21 x i8] c"/proc/self/setgroups\00"
@O_WRONLY = global i32 0
@.str.2 = [28 x i8] c"setgroups_deny: open failed\00"
@.str.3 = [29 x i8] c"setgroups_deny: write failed\00"
@.str.4 = [30 x i8] c"setgroups_deny: partial write\00"
define i32 @setgroups_deny() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %32
11: ; preds = %0
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %4
%14 = load i32, i32* %2
%15 = load i8*, i8** %5
%16 = load i64, i64* %4
%17 = call i64 @write(i32 %14, i8* %15, i64 %16)
store i64 %17, i64* %3
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
%20 = load i64, i64* %3
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %32
24: ; preds = %11
%25 = load i64, i64* %3
%26 = load i64, i64* %4
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %32
30: ; preds = %24
br label %31
31: ; preds = %30
store i32 0, i32* %1
br label %32
32: ; preds = %31, %28, %22, %9
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"deny\00"
@.str.1 = [21 x i8] c"/proc/self/setgroups\00"
@O_WRONLY = global i32 0
@.str.2 = [28 x i8] c"setgroups_deny: open failed\00"
@.str.3 = [29 x i8] c"setgroups_deny: write failed\00"
@.str.4 = [30 x i8] c"setgroups_deny: partial write\00"
define i32 @setgroups_deny() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = tail call i64 @write(i32 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%6 = tail call i32 @close(i32 %2)
%7 = icmp slt i64 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = icmp eq i64 %5, 4
br i1 %9, label %13, label %10
10: ; preds = %8, %4, %0
%11 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), %0 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), %8 ]
%12 = tail call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ 0, %8 ], [ -1, %10 ]
ret i32 %14
}