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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *, long, ...);
int /*<<< orphan*/ sprintf(char *, char *, long, ...);
int /*<<< orphan*/ write(int, char *, size_t);
void update_map(int in, int out, int len, pid_t pid) {
  int fd;
  size_t map_len;
  char *mapping;
  char *map_file;
  map_len = snprintf(NULL, 0, "%d %d %d", in, out, len) + 1;
  mapping = malloc(map_len);
  sprintf(mapping, "%d %d %d", in, out, len);
  map_file = malloc(snprintf(NULL, 0, "/proc/%ld/uid_map", (long)pid) + 1);
  sprintf(map_file, "/proc/%ld/uid_map", (long)pid);
  fd = open(map_file, O_RDWR);
  write(fd, mapping, map_len);
  close(fd);
  free(mapping);
  free(map_file);
}


x86 assembly (clang, -O0):
<update_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movslq -0x4(%rbp),%rcx
mov    -0x8(%rbp),%r8d
mov    -0xc(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe62(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x4(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe1e(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r13d
mov    %esi,%ebx
movslq %edi,%rbp
lea    0xe73(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbp,%rcx
mov    %ebx,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
add    $0x1,%eax
movslq %eax,%r15
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
lea    0xe44(%rip),%rsi
mov    %rbp,%rdx
mov    %ebx,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe37(%rip),%rbx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1080 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %d\00"
@.str.1 = [18 x i8] c"/proc/%ld/uid_map\00"
@O_RDWR = global i32 0
define void @update_map(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 %3, i64* %8
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call i32 (i32*, i32, i8*, i64, ...) @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %15, i32 %16)
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
store i64 %19, i64* %10
%20 = load i64, i64* %10
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %25, i32 %26, i32 %27)
%29 = load i64, i64* %8
%30 = call i32 (i32*, i32, i8*, i64, ...) @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %29)
%31 = add nsw i32 %30, 1
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %12
%33 = load i8*, i8** %12
%34 = load i64, i64* %8
%35 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %34)
%36 = load i8*, i8** %12
%37 = load i32, i32* @O_RDWR
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = load i8*, i8** %11
%41 = load i64, i64* %10
%42 = call i32 @write(i32 %39, i8* %40, i64 %41)
%43 = load i32, i32* %9
%44 = call i32 @close(i32 %43)
%45 = load i8*, i8** %11
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %12
%48 = call i32 @free(i8* %47)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %d\00"
@.str.1 = [18 x i8] c"/proc/%ld/uid_map\00"
@O_RDWR = global i32 0
define void @update_map(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = sext i32 %0 to i64
%6 = tail call i32 (i32*, i32, i8*, i64, ...) @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %5, i32 %1, i32 %2)
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = tail call i8* @malloc(i32 %7)
%10 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %5, i32 %1, i32 %2)
%11 = tail call i32 (i32*, i32, i8*, i64, ...) @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%12 = add nsw i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%15 = load i32, i32* @O_RDWR
%16 = tail call i32 @open(i8* %13, i32 %15)
%17 = tail call i32 @write(i32 %16, i8* %9, i64 %8)
%18 = tail call i32 @close(i32 %16)
%19 = tail call i32 @free(i8* %9)
%20 = tail call i32 @free(i8* %13)
ret void
}