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


x86 assembly (clang, -O0):
<getpwnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <endpwent@plt>
mov    $0x0,%al
call   1040 <getpwent@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1179 <getpwnam+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1189 <getpwnam+0x59>
jmp    118e <getpwnam+0x5e>
jmp    1143 <getpwnam+0x13>
mov    $0x0,%al
call   1050 <endpwent@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpwnam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <endpwent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115e <getpwnam+0x2e>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1140 <getpwnam+0x10>
xor    %eax,%eax
call   1050 <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 (...) @endpwent()
br label %5
5: ; preds = %17, %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 %15
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 ne i64 %13, 0
br label %15
15: ; preds = %8, %5
%16 = phi i1 [ false, %5 ], [ %14, %8 ]
br i1 %16, label %17, label %18
17: ; preds = %15
br label %5
18: ; preds = %15
%19 = call i32 (...) @endpwent()
%20 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %20
}

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