#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__ uid_t;
struct passwd {
  char *pw_passwd;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
  scalar_t__ pw_gid;
  scalar_t__ pw_uid;
};
typedef scalar_t__ gid_t;
typedef enum nss_status { ____Placeholder_nss_status } nss_status;

/* Variables and functions */
int NSS_STATUS_SUCCESS;
int NSS_STATUS_UNAVAIL;
scalar_t__ unbit_magic_buf(char *, int, char **, size_t *);
enum nss_status unbit_res(char *name, size_t name_len, char *home,
                          size_t home_len, uid_t uid, struct passwd *res,
                          char **buffer, size_t *buflen) {
  res->pw_uid = uid;
  res->pw_gid = (gid_t)uid;
  res->pw_passwd = *buffer;
  if (unbit_magic_buf("x", 1, buffer, buflen))
    return NSS_STATUS_UNAVAIL;
  res->pw_gecos = *buffer;
  if (unbit_magic_buf(name, name_len, buffer, buflen))
    return NSS_STATUS_UNAVAIL;
  res->pw_dir = *buffer;
  if (unbit_magic_buf(home, home_len, buffer, buflen))
    return NSS_STATUS_UNAVAIL;
  res->pw_shell = *buffer;
  if (unbit_magic_buf("/bin/bash", 9, buffer, buflen))
    return NSS_STATUS_UNAVAIL;
  return NSS_STATUS_SUCCESS;
}


x86 assembly (clang, -O0):
<unbit_res>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
lea    0xe93(%rip),%rdi
mov    $0x1,%esi
call   1030 <unbit_magic_buf@plt>
cmp    $0x0,%rax
je     1192 <unbit_res+0x82>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <unbit_res+0x153>
mov    0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1030 <unbit_magic_buf@plt>
cmp    $0x0,%rax
je     11d3 <unbit_res+0xc3>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <unbit_res+0x153>
mov    0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1030 <unbit_magic_buf@plt>
cmp    $0x0,%rax
je     1214 <unbit_res+0x104>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <unbit_res+0x153>
mov    0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
lea    0xdd0(%rip),%rdi
mov    $0x9,%esi
call   1030 <unbit_magic_buf@plt>
cmp    $0x0,%rax
je     1257 <unbit_res+0x147>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <unbit_res+0x153>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unbit_res>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
mov    0x48(%rsp),%rcx
mov    0x40(%rsp),%rdx
mov    %r8,0x28(%r9)
mov    %r8,0x20(%r9)
mov    (%rdx),%rax
mov    %rax,(%r9)
lea    0xeb7(%rip),%rdi
mov    $0x1,%esi
call   1030 <unbit_magic_buf@plt>
mov    0x2e8e(%rip),%r12
test   %rax,%rax
jne    11d6 <unbit_res+0xc6>
mov    0x40(%rsp),%rdx
mov    (%rdx),%rax
mov    %rax,0x8(%rbx)
mov    %r14,%rdi
mov    %ebp,%esi
mov    0x48(%rsp),%rbp
mov    %rbp,%rcx
call   1030 <unbit_magic_buf@plt>
test   %rax,%rax
jne    11d6 <unbit_res+0xc6>
mov    0x40(%rsp),%rdx
mov    (%rdx),%rax
mov    %rax,0x10(%rbx)
mov    %r15,%rdi
mov    %r13d,%esi
mov    %rbp,%rcx
call   1030 <unbit_magic_buf@plt>
test   %rax,%rax
jne    11d6 <unbit_res+0xc6>
mov    0x40(%rsp),%rdx
mov    (%rdx),%rax
mov    %rax,0x18(%rbx)
lea    0xe4e(%rip),%rdi
mov    $0x9,%esi
mov    %rbp,%rcx
call   1030 <unbit_magic_buf@plt>
test   %rax,%rax
jne    11cf <unbit_res+0xbf>
mov    0x2e13(%rip),%r12
jmp    11d6 <unbit_res+0xc6>
mov    0x2e12(%rip),%r12
mov    (%r12),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8*, i8*, i64, i64 }
@.str = [2 x i8] c"x\00"
@NSS_STATUS_UNAVAIL = global i32 0
@.str.1 = [10 x i8] c"/bin/bash\00"
@NSS_STATUS_SUCCESS = global i32 0
define i32 @unbit_res(i8* %0, i64 %1, i8* %2, i64 %3, i64 %4, %struct.passwd* nocapture writeonly %5, i8** %6, i64* %7) {
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 5
store i64 %4, i64* %9
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 4
store i64 %4, i64* %10
%11 = load i8*, i8** %6
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
store i8* %11, i8** %12
%13 = tail call i64 @unbit_magic_buf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i8** %6, i64* %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %8
%16 = load i8*, i8** %6
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 1
store i8* %16, i8** %17
%18 = trunc i64 %1 to i32
%19 = tail call i64 @unbit_magic_buf(i8* %0, i32 %18, i8** %6, i64* %7)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %15
%22 = load i8*, i8** %6
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 2
store i8* %22, i8** %23
%24 = trunc i64 %3 to i32
%25 = tail call i64 @unbit_magic_buf(i8* %2, i32 %24, i8** %6, i64* %7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 3
store i8* %28, i8** %29
%30 = tail call i64 @unbit_magic_buf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9, i8** %6, i64* %7)
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i32* @NSS_STATUS_SUCCESS, i32* @NSS_STATUS_UNAVAIL
br label %33
33: ; preds = %27, %21, %15, %8
%34 = phi i32* [ @NSS_STATUS_UNAVAIL, %8 ], [ @NSS_STATUS_UNAVAIL, %15 ], [ @NSS_STATUS_UNAVAIL, %21 ], [ %32, %27 ]
%35 = load i32, i32* %34
ret i32 %35
}