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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
void update_process_idmap(char *pathfmt, int pid, char *map, int map_len) {
  char buf[PATH_MAX];
  int len;
  int fd;
  len = snprintf(buf, sizeof(buf), pathfmt, pid);
  if (len < 0) {
    fprintf(stderr,
            "nsenter: "
            "failed to construct '%s' for %d"
            ": %m\n",
            pathfmt, pid);
    exit(1);
  }
  fd = open(buf, O_RDWR);
  if (fd == -1) {
    fprintf(stderr,
            "nsenter: "
            "failed to open %s"
            ": %m\n",
            buf);
    exit(1);
  }
  len = write(fd, map, map_len);
  if (len == -1) {
    fprintf(stderr,
            "nsenter: "
            "failed to write to %s"
            ": %m\n",
            buf);
    close(fd);
    exit(1);
  } else if (len != map_len) {
    fprintf(stderr,
            "nsenter: "
            "Failed to write data to %s (%d/%d)"
            ": %m\n",
            buf, len, map_len);
    close(fd);
    exit(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<update_process_idmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1040 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11e5 <update_process_idmap+0x85>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1229 <update_process_idmap+0xc9>
mov    -0x40(%rbp),%rdx
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1272 <update_process_idmap+0x112>
mov    -0x40(%rbp),%rdx
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     12b2 <update_process_idmap+0x152>
mov    -0x40(%rbp),%rdx
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12b7 <update_process_idmap+0x157>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_process_idmap>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%r13
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r15d,%ecx
call   1040 <snprintf@plt>
test   %eax,%eax
js     11f0 <update_process_idmap+0x90>
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1217 <update_process_idmap+0xb7>
mov    %eax,%r15d
mov    %eax,%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     123b <update_process_idmap+0xdb>
cmp    %r14d,%eax
jne    1257 <update_process_idmap+0xf7>
mov    %r15d,%edi
call   1050 <close@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    %r13,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1276 <update_process_idmap+0x116>
mov    0x2d72(%rip),%rcx
mov    (%rcx),%edi
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"nsenter: failed to construct '%s' for %d: %m\0A\00"
@O_RDWR = global i32 0
@.str.1 = [32 x i8] c"nsenter: failed to open %s: %m\0A\00"
@.str.2 = [36 x i8] c"nsenter: failed to write to %s: %m\0A\00"
@.str.3 = [49 x i8] c"nsenter: Failed to write data to %s (%d/%d): %m\0A\00"
define void @update_process_idmap(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = trunc i64 %14 to i32
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @snprintf(i8* %16, i32 %17, i8* %18, i32 %19)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %4
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %4
%30 = load i32, i32* @O_RDWR
%31 = call i32 @open(i8* %16, i32 %30)
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = load i32, i32* %12
%40 = load i8*, i8** %7
%41 = load i32, i32* %8
%42 = call i32 @write(i32 %39, i8* %40, i32 %41)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%48 = load i32, i32* %12
%49 = call i32 @close(i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %38
%52 = load i32, i32* %11
%53 = load i32, i32* %8
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %63
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = load i32, i32* %11
%58 = load i32, i32* %8
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %16, i32 %57, i32 %58)
%60 = load i32, i32* %12
%61 = call i32 @close(i32 %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %51
br label %64
64: ; preds = %63
%65 = load i32, i32* %12
%66 = call i32 @close(i32 %65)
%67 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"nsenter: failed to construct '%s' for %d: %m\0A\00"
@O_RDWR = global i32 0
@.str.1 = [32 x i8] c"nsenter: failed to open %s: %m\0A\00"
@.str.2 = [36 x i8] c"nsenter: failed to write to %s: %m\0A\00"
@.str.3 = [49 x i8] c"nsenter: Failed to write data to %s (%d/%d): %m\0A\00"
define void @update_process_idmap(i8* %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @snprintf(i8* %7, i32 %5, i8* %0, i32 %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %7, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = call i32 @write(i32 %16, i8* %2, i32 %3)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%28 = call i32 @close(i32 %16)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = icmp eq i32 %23, %3
br i1 %31, label %37, label %32
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %7, i32 %23, i32 %3)
%35 = call i32 @close(i32 %16)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = call i32 @close(i32 %16)
ret void
}