#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 uid_t;
struct stat {
  int st_uid;
  int st_gid;
};
struct passwd {
  char *pw_name;
};
typedef enum nss_status { ____Placeholder_nss_status } nss_status;

/* Variables and functions */
int NSS_STATUS_UNAVAIL;
int snprintf(char *, int, char *, int);
scalar_t__ stat(char *, struct stat *);
scalar_t__ unbit_magic_buf(char *, size_t, char **, size_t *);
int unbit_res(char *, size_t, char *, int, int, struct passwd *, char **,
              size_t *);
enum nss_status _nss_unbit_getpwuid_r(uid_t uid, struct passwd *res,
                                      char *buffer, size_t buflen,
                                      int *errnop) {
  struct stat st;
  char filename[1024];
  if (uid < 30000)
    return NSS_STATUS_UNAVAIL;
  int ret = snprintf(filename, 1024,
                     "/containers/"
                     "%d",
                     (int)uid);
  if (ret <= 0 || ret > 1024)
    return NSS_STATUS_UNAVAIL;
  if (stat(filename, &st))
    return NSS_STATUS_UNAVAIL;
  if (st.st_uid != uid)
    return NSS_STATUS_UNAVAIL;
  if (st.st_gid != uid)
    return NSS_STATUS_UNAVAIL;
  char *name = filename + (sizeof("/containers/") - 1);
  size_t name_len = ret - (sizeof("/containers/") - 1);
  res->pw_name = buffer;
  if (unbit_magic_buf(name, name_len, &buffer, &buflen))
    return NSS_STATUS_UNAVAIL;
  return unbit_res(name, name_len, filename,
                   (sizeof("/containers/") - 1) + name_len, uid, res, &buffer,
                   &buflen);
}


x86 assembly (clang, -O0):
<_nss_unbit_getpwuid_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x7530,-0x8(%rbp)
jge    117c <_nss_unbit_getpwuid_r+0x3c>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d8 <_nss_unbit_getpwuid_r+0x198>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x400,%esi
lea    0xe6e(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jle    11ba <_nss_unbit_getpwuid_r+0x7a>
cmpl   $0x400,-0x434(%rbp)
jle    11cb <_nss_unbit_getpwuid_r+0x8b>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d8 <_nss_unbit_getpwuid_r+0x198>
lea    -0x430(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     11f6 <_nss_unbit_getpwuid_r+0xb6>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d8 <_nss_unbit_getpwuid_r+0x198>
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1213 <_nss_unbit_getpwuid_r+0xd3>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d8 <_nss_unbit_getpwuid_r+0x198>
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1230 <_nss_unbit_getpwuid_r+0xf0>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d8 <_nss_unbit_getpwuid_r+0x198>
lea    -0x430(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x440(%rbp)
movslq -0x434(%rbp),%rax
sub    $0xc,%rax
mov    %rax,-0x448(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x440(%rbp),%rdi
mov    -0x448(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <unbit_magic_buf@plt>
cmp    $0x0,%rax
je     1295 <_nss_unbit_getpwuid_r+0x155>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d8 <_nss_unbit_getpwuid_r+0x198>
mov    -0x440(%rbp),%rdi
mov    -0x448(%rbp),%rsi
lea    -0x430(%rbp),%rdx
mov    -0x448(%rbp),%rax
add    $0xc,%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%r8d
mov    -0x10(%rbp),%r9
lea    -0x18(%rbp),%r10
lea    -0x20(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <unbit_res@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_unbit_getpwuid_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdx,0x10(%rsp)
mov    %rcx,0x18(%rsp)
cmp    $0x752f,%edi
jle    11e0 <_nss_unbit_getpwuid_r+0xa0>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe8e(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %eax,%r15d
lea    -0x401(%r15),%eax
cmp    $0xfffffbff,%eax
jbe    11e0 <_nss_unbit_getpwuid_r+0xa0>
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
jne    11e0 <_nss_unbit_getpwuid_r+0xa0>
cmp    %ebp,0x8(%rsp)
jne    11e0 <_nss_unbit_getpwuid_r+0xa0>
cmp    %ebp,0xc(%rsp)
jne    11e0 <_nss_unbit_getpwuid_r+0xa0>
lea    0x2c(%rsp),%r12
mov    %r15d,%r13d
add    $0xfffffffffffffff4,%r13
mov    %rbx,(%r14)
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rbx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rcx
call   1060 <unbit_magic_buf@plt>
test   %rax,%rax
je     11fb <_nss_unbit_getpwuid_r+0xbb>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x20(%rsp),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %r14,%r9
push   %rbx
lea    0x18(%rsp),%rax
push   %rax
call   1050 <unbit_res@plt>
add    $0x10,%rsp
jmp    11e9 <_nss_unbit_getpwuid_r+0xa9>

LLVM IR (-O0):
%struct.passwd = type { i8* }
%struct.stat = type { i32, i32 }
@NSS_STATUS_UNAVAIL = global i32 0
@.str = [15 x i8] c"/containers/%d\00"
define i32 @_nss_unbit_getpwuid_r(i32 %0, %struct.passwd* %1, i8* %2, i64 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.passwd*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32*
%12 = alloca %struct.stat
%13 = alloca [1024 x i8]
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
store i32 %0, i32* %7
store %struct.passwd* %1, %struct.passwd** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i32* %4, i32** %11
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 30000
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %20, i32* %6
br label %77
21: ; preds = %5
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call i32 @snprintf(i8* %22, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 %24, i32* %14
%25 = load i32, i32* %14
%26 = icmp sle i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* %14
%29 = icmp sgt i32 %28, 1024
br i1 %29, label %30, label %32
30: ; preds = %27, %21
%31 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %31, i32* %6
br label %77
32: ; preds = %27
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%34 = call i64 @stat(i8* %33, %struct.stat* %12)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %37, i32* %6
br label %77
38: ; preds = %32
%39 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i32, i32* %7
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %44, i32* %6
br label %77
45: ; preds = %38
%46 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load i32, i32* %7
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %51, i32* %6
br label %77
52: ; preds = %45
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%54 = getelementptr inbounds i8, i8* %53, i64 12
store i8* %54, i8** %15
%55 = load i32, i32* %14
%56 = sext i32 %55 to i64
%57 = sub i64 %56, 12
store i64 %57, i64* %16
%58 = load i8*, i8** %9
%59 = load %struct.passwd*, %struct.passwd** %8
%60 = getelementptr inbounds %struct.passwd, %struct.passwd* %59, i32 0, i32 0
store i8* %58, i8** %60
%61 = load i8*, i8** %15
%62 = load i64, i64* %16
%63 = call i64 @unbit_magic_buf(i8* %61, i64 %62, i8** %9, i64* %10)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %52
%66 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %66, i32* %6
br label %77
67: ; preds = %52
%68 = load i8*, i8** %15
%69 = load i64, i64* %16
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%71 = load i64, i64* %16
%72 = add i64 12, %71
%73 = trunc i64 %72 to i32
%74 = load i32, i32* %7
%75 = load %struct.passwd*, %struct.passwd** %8
%76 = call i32 @unbit_res(i8* %68, i64 %69, i8* %70, i32 %73, i32 %74, %struct.passwd* %75, i8** %9, i64* %10)
store i32 %76, i32* %6
br label %77
77: ; preds = %67, %65, %50, %43, %36, %30, %19
%78 = load i32, i32* %6
ret i32 %78
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
%struct.stat = type { i32, i32 }
@NSS_STATUS_UNAVAIL = global i32 0
@.str = [15 x i8] c"/containers/%d\00"
define i32 @_nss_unbit_getpwuid_r(i32 %0, %struct.passwd* %1, i8* %2, i64 %3, i32* nocapture readnone %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.stat
%9 = alloca [1024 x i8]
store i8* %2, i8** %6
store i64 %3, i64* %7
%10 = bitcast %struct.stat* %8 to i8*
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%12 = icmp slt i32 %0, 30000
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %49
15: ; preds = %5
%16 = call i32 @snprintf(i8* %11, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0)
%17 = add i32 %16, -1025
%18 = icmp ult i32 %17, -1024
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %49
21: ; preds = %15
%22 = call i64 @stat(i8* %11, %struct.stat* %8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %49
26: ; preds = %21
%27 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, %0
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %49
32: ; preds = %26
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 1
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, %0
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %49
38: ; preds = %32
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 12
%40 = zext i32 %16 to i64
%41 = add nsw i64 %40, -12
%42 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 0
store i8* %2, i8** %42
%43 = call i64 @unbit_magic_buf(i8* %39, i64 %41, i8** %6, i64* %7)
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %38
%46 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %49
47: ; preds = %38
%48 = call i32 @unbit_res(i8* %39, i64 %41, i8* %11, i32 %16, i32 %0, %struct.passwd* %1, i8** %6, i64* %7)
br label %49
49: ; preds = %19, %24, %30, %36, %47, %45, %13
%50 = phi i32 [ %14, %13 ], [ %20, %19 ], [ %25, %24 ], [ %31, %30 ], [ %37, %36 ], [ %46, %45 ], [ %48, %47 ]
ret i32 %50
}