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

/* Variables and functions */
int /*<<< orphan*/ proc_setgroups_write(int, char *);
int /*<<< orphan*/ update_process_idmap(char *, int, char *, int);
void update_process_gidmap(int pid, uint8_t is_setgroup, char *map,
                           int map_len) {
  if ((map == NULL) || (map_len <= 0)) {
    return;
  }
  if (is_setgroup == 1) {
    proc_setgroups_write(pid, "allow");
  } else {
    proc_setgroups_write(pid, "deny");
  }
  update_process_idmap("/proc/%d/gid_map", pid, map, map_len);
}


x86 assembly (clang, -O0):
<update_process_gidmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114a <update_process_gidmap+0x2a>
cmpl   $0x0,-0x14(%rbp)
jg     114f <update_process_gidmap+0x2f>
jmp    1192 <update_process_gidmap+0x72>
cmpl   $0x1,-0x8(%rbp)
jne    116d <update_process_gidmap+0x4d>
mov    -0x4(%rbp),%edi
lea    0xe9d(%rip),%rsi
call   1040 <proc_setgroups_write@plt>
jmp    117c <update_process_gidmap+0x5c>
mov    -0x4(%rbp),%edi
lea    0xe8f(%rip),%rsi
call   1040 <proc_setgroups_write@plt>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe7e(%rip),%rdi
call   1030 <update_process_idmap@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_process_gidmap>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     1167 <update_process_gidmap+0x47>
mov    %ecx,%ebp
test   %ecx,%ecx
jle    1167 <update_process_gidmap+0x47>
mov    %rdx,%rbx
mov    %edi,%r14d
cmp    $0x1,%esi
lea    0xec1(%rip),%rax
lea    0xec0(%rip),%rsi
cmove  %rax,%rsi
call   1040 <proc_setgroups_write@plt>
lea    0xeb5(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <update_process_idmap@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"allow\00"
@.str.1 = [5 x i8] c"deny\00"
@.str.2 = [17 x i8] c"/proc/%d/gid_map\00"
define void @update_process_gidmap(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i8*, i8** %7
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = load i32, i32* %8
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %4
br label %29
15: ; preds = %11
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %5
%20 = call i32 @proc_setgroups_write(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %24
21: ; preds = %15
%22 = load i32, i32* %5
%23 = call i32 @proc_setgroups_write(i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %5
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = call i32 @update_process_idmap(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26, i32 %27)
br label %29
29: ; preds = %24, %14
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"allow\00"
@.str.1 = [5 x i8] c"deny\00"
@.str.2 = [17 x i8] c"/proc/%d/gid_map\00"
define void @update_process_gidmap(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %2, null
%6 = icmp slt i32 %3, 1
%7 = or i1 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = icmp eq i32 %1, 1
%10 = select i1 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%11 = tail call i32 @proc_setgroups_write(i32 %0, i8* %10)
%12 = tail call i32 @update_process_idmap(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %2, i32 %3)
br label %13
13: ; preds = %4, %8
ret void
}