#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*/ FILE;

/* Variables and functions */
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int deny_groups() {
  FILE *f = fopen("/proc/self/setgroups", "w");
  if (!f) {
    perror("fopen /proc/self/setgroups");
    return 1;
  }
  if (fputs("deny\n", f) < 0) {
    perror("fputs");
    return 1;
  }
  return fclose(f);
}


x86 assembly (clang, -O0):
<deny_groups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb9(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <deny_groups+0x42>
lea    0xe91(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c0 <deny_groups+0x80>
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1040 <fputs@plt>
cmp    $0x0,%rax
jge    11b4 <deny_groups+0x74>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c0 <deny_groups+0x80>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deny_groups>:
push   %rbx
lea    0xec0(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1179 <deny_groups+0x39>
mov    %rax,%rbx
lea    0xeba(%rip),%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
test   %rax,%rax
js     1182 <deny_groups+0x42>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <fclose@plt>
lea    0xe82(%rip),%rdi
jmp    1189 <deny_groups+0x49>
lea    0xe9a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/proc/self/setgroups\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [27 x i8] c"fopen /proc/self/setgroups\00"
@.str.3 = [6 x i8] c"deny\0A\00"
@.str.4 = [6 x i8] c"fputs\00"
define i32 @deny_groups() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp ne i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %17
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %17
14: ; preds = %8
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
store i32 %16, i32* %1
br label %17
17: ; preds = %14, %12, %6
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [21 x i8] c"/proc/self/setgroups\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [27 x i8] c"fopen /proc/self/setgroups\00"
@.str.3 = [6 x i8] c"deny\0A\00"
@.str.4 = [6 x i8] c"fputs\00"
define i32 @deny_groups() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %12
5: ; preds = %0
%6 = tail call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %12
10: ; preds = %5
%11 = tail call i32 @fclose(i32* %1)
br label %12
12: ; preds = %10, %8, %3
%13 = phi i32 [ 1, %8 ], [ %11, %10 ], [ 1, %3 ]
ret i32 %13
}