#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*/ endpwent();
struct passwd *getpwent();
struct passwd *np_copy_passwd(struct passwd *);
int /*<<< orphan*/ setpwent();
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
struct passwd *np_getpwnam(const char *name) {
  struct passwd *pwd;
  setpwent();
  while ((pwd = getpwent()) != NULL) {
    if (strcmp(pwd->pw_name, name) == 0) {
      break;
    }
  }
  if (pwd != NULL) {
    pwd = np_copy_passwd(pwd);
  }
  endpwent();
  return pwd;
}


x86 assembly (clang, -O0):
<np_getpwnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <setpwent@plt>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     119b <np_getpwnam+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1196 <np_getpwnam+0x46>
jmp    119b <np_getpwnam+0x4b>
jmp    1163 <np_getpwnam+0x13>
cmpq   $0x0,-0x10(%rbp)
je     11b3 <np_getpwnam+0x63>
mov    -0x10(%rbp),%rdi
call   1060 <np_copy_passwd@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <endpwent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<np_getpwnam>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <setpwent@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getpwent@plt>
test   %rax,%rax
je     1199 <np_getpwnam+0x49>
mov    %rax,%rbx
mov    (%rax),%edi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1170 <np_getpwnam+0x20>
mov    %rbx,%rdi
call   1060 <np_copy_passwd@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <endpwent@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
define %struct.passwd* @np_getpwnam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
store i8* %0, i8** %2
%4 = call i32 (...) @setpwent()
br label %5
5: ; preds = %16, %1
%6 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %6, %struct.passwd** %3
%7 = icmp ne %struct.passwd* %6, null
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load %struct.passwd*, %struct.passwd** %3
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = call i64 @strcmp(i32 %11, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
br label %17
16: ; preds = %8
br label %5
17: ; preds = %15, %5
%18 = load %struct.passwd*, %struct.passwd** %3
%19 = icmp ne %struct.passwd* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load %struct.passwd*, %struct.passwd** %3
%22 = call %struct.passwd* @np_copy_passwd(%struct.passwd* %21)
store %struct.passwd* %22, %struct.passwd** %3
br label %23
23: ; preds = %20, %17
%24 = call i32 (...) @endpwent()
%25 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %25
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define %struct.passwd* @np_getpwnam(i8* %0) {
%2 = tail call i32 (...) @setpwent()
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.passwd* (...) @getpwent()
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @strcmp(i32 %8, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %6
%12 = tail call %struct.passwd* @np_copy_passwd(%struct.passwd* %4)
br label %13
13: ; preds = %3, %11
%14 = phi %struct.passwd* [ %12, %11 ], [ null, %3 ]
%15 = tail call i32 (...) @endpwent()
ret %struct.passwd* %14
}