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


x86 assembly (clang, -O0):
<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     118b <getpwnam+0x4b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1186 <getpwnam+0x46>
jmp    118b <getpwnam+0x4b>
jmp    1153 <getpwnam+0x13>
mov    $0x0,%al
call   1060 <endpwent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpwnam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <setpwent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116e <getpwnam+0x2e>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1150 <getpwnam+0x10>
xor    %eax,%eax
call   1060 <endpwent@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
define %struct.passwd* @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 i8*, i8** %2
%10 = load %struct.passwd*, %struct.passwd** %3
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @strcmp(i8* %9, i32 %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 = call i32 (...) @endpwent()
%19 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %19
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define %struct.passwd* @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 %11, 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(i8* %0, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %6, %3
%12 = tail call i32 (...) @endpwent()
ret %struct.passwd* %4
}