#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 passwd {
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ _SC_LOGIN_NAME_MAX;
int /*<<< orphan*/ endpwent();
struct passwd *getpwent();
int /*<<< orphan*/ setpwent();
scalar_t__ strncmp(int /*<<< orphan*/, char const *, long);
long sysconf(int /*<<< orphan*/);
struct passwd *_getpwnam(const char *name) {
  struct passwd *p;
  long usernameMax;
  usernameMax = sysconf(_SC_LOGIN_NAME_MAX);
  if (usernameMax == -1) {
    usernameMax = 256;
  }
  setpwent();
  for (p = getpwent(); p != NULL && strncmp(p->pw_name, name, usernameMax) != 0;
       p = getpwent())
    ;
  endpwent();
  return p;
}


x86 assembly (clang, -O0):
<_getpwnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1181 <_getpwnam+0x31>
movq   $0x100,-0x18(%rbp)
mov    $0x0,%al
call   1040 <setpwent@plt>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     11c0 <_getpwnam+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11d0 <_getpwnam+0x80>
jmp    11e5 <_getpwnam+0x95>
jmp    11d5 <_getpwnam+0x85>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x10(%rbp)
jmp    1193 <_getpwnam+0x43>
mov    $0x0,%al
call   1060 <endpwent@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getpwnam>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
mov    $0x100,%r15d
cmovne %rax,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <setpwent@plt>
xor    %eax,%eax
call   1050 <getpwent@plt>
test   %rax,%rax
je     11b3 <_getpwnam+0x63>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    (%rbx),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b3 <_getpwnam+0x63>
xor    %eax,%eax
call   1050 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <_getpwnam+0x40>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <endpwent@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@_SC_LOGIN_NAME_MAX = global i32 0
define %struct.passwd* @_getpwnam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i32, i32* @_SC_LOGIN_NAME_MAX
%6 = call i64 @sysconf(i32 %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
store i64 256, i64* %4
br label %10
10: ; preds = %9, %1
%11 = call i32 (...) @setpwent()
%12 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %12, %struct.passwd** %3
br label %13
13: ; preds = %27, %10
%14 = load %struct.passwd*, %struct.passwd** %3
%15 = icmp ne %struct.passwd* %14, null
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load i8*, i8** %2
%21 = load i64, i64* %4
%22 = call i64 @strncmp(i32 %19, i8* %20, i64 %21)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %16, %13
%25 = phi i1 [ false, %13 ], [ %23, %16 ]
br i1 %25, label %26, label %29
26: ; preds = %24
br label %27
27: ; preds = %26
%28 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %28, %struct.passwd** %3
br label %13
29: ; preds = %24
%30 = call i32 (...) @endpwent()
%31 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %31
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@_SC_LOGIN_NAME_MAX = global i32 0
define %struct.passwd* @_getpwnam(i8* %0) {
%2 = load i32, i32* @_SC_LOGIN_NAME_MAX
%3 = tail call i64 @sysconf(i32 %2)
%4 = icmp eq i64 %3, -1
%5 = select i1 %4, i64 256, i64 %3
%6 = tail call i32 (...) @setpwent()
%7 = tail call %struct.passwd* (...) @getpwent()
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %18, label %9
9: ; preds = %1, %15
%10 = phi %struct.passwd* [ %16, %15 ], [ %7, %1 ]
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i64 @strncmp(i32 %12, i8* %0, i64 %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = tail call %struct.passwd* (...) @getpwent()
%17 = icmp eq %struct.passwd* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %15, %1
%19 = phi %struct.passwd* [ null, %1 ], [ null, %15 ], [ %10, %9 ]
%20 = tail call i32 (...) @endpwent()
ret %struct.passwd* %19
}