#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 */
struct group {
  char *gr_passwd;
  char **gr_mem;
  scalar_t__ gr_gid;
};
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_gres(char *name, size_t name_len, gid_t gid,
                           struct group *res, char **buffer, size_t *buflen) {
  res->gr_gid = (gid_t)gid;
  res->gr_passwd = *buffer;
  if (unbit_magic_buf("x", 1, buffer, buflen))
    return NSS_STATUS_UNAVAIL;
  if (*buflen < sizeof(char *))
    return NSS_STATUS_UNAVAIL;
  res->gr_mem = (char **)*buffer;
  res->gr_mem[0] = NULL;
  return NSS_STATUS_SUCCESS;
}


x86 assembly (clang, -O0):
<unbit_gres>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
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    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xea7(%rip),%rdi
mov    $0x1,%esi
call   1030 <unbit_magic_buf@plt>
cmp    $0x0,%rax
je     117e <unbit_gres+0x6e>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <unbit_gres+0xb7>
mov    -0x38(%rbp),%rax
cmpq   $0x8,(%rax)
jae    119d <unbit_gres+0x8d>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <unbit_gres+0xb7>
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
movq   $0x0,(%rax)
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unbit_gres>:
push   %r15
push   %r14
push   %rbx
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,0x10(%rcx)
mov    (%r8),%rax
mov    %rax,(%rcx)
lea    0xed1(%rip),%rdi
mov    $0x1,%esi
mov    %r8,%rdx
mov    %r9,%rcx
call   1030 <unbit_magic_buf@plt>
mov    0x2ea2(%rip),%rcx
test   %rax,%rax
jne    1166 <unbit_gres+0x56>
cmpq   $0x8,(%r15)
jb     1166 <unbit_gres+0x56>
mov    (%r14),%rax
mov    %rax,0x8(%rbx)
movq   $0x0,(%rax)
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.group = type { i8*, i8**, i64 }
@.str = [2 x i8] c"x\00"
@NSS_STATUS_UNAVAIL = global i32 0
@NSS_STATUS_SUCCESS = global i32 0
define i32 @unbit_gres(i8* %0, i64 %1, i64 %2, %struct.group* %3, i8** %4, i64* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca %struct.group*
%12 = alloca i8**
%13 = alloca i64*
store i8* %0, i8** %8
store i64 %1, i64* %9
store i64 %2, i64* %10
store %struct.group* %3, %struct.group** %11
store i8** %4, i8*** %12
store i64* %5, i64** %13
%14 = load i64, i64* %10
%15 = load %struct.group*, %struct.group** %11
%16 = getelementptr inbounds %struct.group, %struct.group* %15, i32 0, i32 2
store i64 %14, i64* %16
%17 = load i8**, i8*** %12
%18 = load i8*, i8** %17
%19 = load %struct.group*, %struct.group** %11
%20 = getelementptr inbounds %struct.group, %struct.group* %19, i32 0, i32 0
store i8* %18, i8** %20
%21 = load i8**, i8*** %12
%22 = load i64*, i64** %13
%23 = call i64 @unbit_magic_buf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i8** %21, i64* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %6
%26 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %26, i32* %7
br label %44
27: ; preds = %6
%28 = load i64*, i64** %13
%29 = load i64, i64* %28
%30 = icmp ult i64 %29, 8
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %32, i32* %7
br label %44
33: ; preds = %27
%34 = load i8**, i8*** %12
%35 = load i8*, i8** %34
%36 = bitcast i8* %35 to i8**
%37 = load %struct.group*, %struct.group** %11
%38 = getelementptr inbounds %struct.group, %struct.group* %37, i32 0, i32 1
store i8** %36, i8*** %38
%39 = load %struct.group*, %struct.group** %11
%40 = getelementptr inbounds %struct.group, %struct.group* %39, i32 0, i32 1
%41 = load i8**, i8*** %40
%42 = getelementptr inbounds i8*, i8** %41, i64 0
store i8* null, i8** %42
%43 = load i32, i32* @NSS_STATUS_SUCCESS
store i32 %43, i32* %7
br label %44
44: ; preds = %33, %31, %25
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
%struct.group = type { i8*, i8**, i64 }
@.str = [2 x i8] c"x\00"
@NSS_STATUS_UNAVAIL = global i32 0
@NSS_STATUS_SUCCESS = global i32 0
define i32 @unbit_gres(i8* nocapture readnone %0, i64 %1, i64 %2, %struct.group* nocapture writeonly %3, i8** %4, i64* %5) {
%7 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 2
store i64 %2, i64* %7
%8 = load i8*, i8** %4
%9 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 0
store i8* %8, i8** %9
%10 = tail call i64 @unbit_magic_buf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i8** %4, i64* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %6
%13 = load i64, i64* %5
%14 = icmp ult i64 %13, 8
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = bitcast i8** %4 to i8***
%17 = load i8**, i8*** %16
%18 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 1
store i8** %17, i8*** %18
store i8* null, i8** %17
br label %19
19: ; preds = %12, %6, %15
%20 = phi i32* [ @NSS_STATUS_SUCCESS, %15 ], [ @NSS_STATUS_UNAVAIL, %6 ], [ @NSS_STATUS_UNAVAIL, %12 ]
%21 = load i32, i32* %20
ret i32 %21
}