#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ write_file(char *, int, char *, int);
void update_gidmap(int pid, char *map, int map_len) {
  if (map == NULL || map_len <= 0)
    return;
  if (write_file(map, map_len, "/proc/%d/gid_map", pid) < 0)
    do {
      fprintf(stderr,
              "nsenter: "
              "failed to update /proc/%d/gid_map"
              ": %m\n",
              pid);
      exit(4 + 1);
    } while (0);
}


x86 assembly (clang, -O0):
<update_gidmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1157 <update_gidmap+0x27>
cmpl   $0x0,-0x14(%rbp)
jg     115c <update_gidmap+0x2c>
jmp    11a3 <update_gidmap+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%ecx
lea    0xe93(%rip),%rdx
call   1030 <write_file@plt>
cmp    $0x0,%rax
jge    11a3 <update_gidmap+0x73>
jmp    1181 <update_gidmap+0x51>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x5,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_gidmap>:
push   %rbx
test   %rsi,%rsi
je     1157 <update_gidmap+0x27>
test   %edx,%edx
jle    1157 <update_gidmap+0x27>
mov    %edi,%ebx
lea    0xebd(%rip),%rax
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rax,%rdx
mov    %ebx,%ecx
call   1030 <write_file@plt>
test   %rax,%rax
js     1159 <update_gidmap+0x29>
pop    %rbx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0x5,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/%d/gid_map\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"nsenter: failed to update /proc/%d/gid_map: %m\0A\00"
define void @update_gidmap(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i32, i32* %6
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %3
br label %26
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = call i64 @write_file(i8* %14, i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %13
br label %20
20: ; preds = %19
%21 = load i32, i32* @stderr
%22 = load i32, i32* %4
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @exit(i32 5)
unreachable
25: ; No predecessors!
br label %26
26: ; preds = %12, %25, %13
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/%d/gid_map\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"nsenter: failed to update /proc/%d/gid_map: %m\0A\00"
define void @update_gidmap(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
%5 = icmp slt i32 %2, 1
%6 = or i1 %4, %5
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = tail call i64 @write_file(i8* %1, i32 %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%13 = tail call i32 @exit(i32 5)
unreachable
14: ; preds = %3, %7
ret void
}