#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct passwd *getpwent();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char const *);
struct passwd *get_user_entry(const char *user) {
  struct passwd *pw;
  if (!user || !*user)
    return NULL;
  while ((pw = getpwent())) {
    if (!strcmp(pw->pw_name, user))
      return pw;
  }
  fprintf(stderr, "No such user: %s\n", user);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<get_user_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1164 <get_user_entry+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1171 <get_user_entry+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11dc <get_user_entry+0x9c>
jmp    1176 <get_user_entry+0x36>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b5 <get_user_entry+0x75>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11b0 <get_user_entry+0x70>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <get_user_entry+0x9c>
jmp    1176 <get_user_entry+0x36>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_entry>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117f <get_user_entry+0x3f>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     117f <get_user_entry+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getpwent@plt>
test   %rax,%rax
je     118c <get_user_entry+0x4c>
mov    %rax,%rbx
mov    (%rax),%edi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    1160 <get_user_entry+0x20>
jmp    1181 <get_user_entry+0x41>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"No such user: %s\0A\00"
@EXIT_FAILURE = global i32 0
define %struct.passwd* @get_user_entry(i8* %0) {
%2 = alloca %struct.passwd*
%3 = alloca i8*
%4 = alloca %struct.passwd*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %7, %1
store %struct.passwd* null, %struct.passwd** %2
br label %32
12: ; preds = %7
br label %13
13: ; preds = %25, %12
%14 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %14, %struct.passwd** %4
%15 = icmp ne %struct.passwd* %14, null
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load %struct.passwd*, %struct.passwd** %4
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load i8*, i8** %3
%21 = call i32 @strcmp(i32 %19, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %16
%24 = load %struct.passwd*, %struct.passwd** %4
store %struct.passwd* %24, %struct.passwd** %2
br label %32
25: ; preds = %16
br label %13
26: ; preds = %13
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %23, %11
%33 = load %struct.passwd*, %struct.passwd** %2
ret %struct.passwd* %33
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"No such user: %s\0A\00"
@EXIT_FAILURE = global i32 0
define %struct.passwd* @get_user_entry(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %3, %9
%7 = tail call %struct.passwd* (...) @getpwent()
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %7, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @strcmp(i32 %11, i8* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %6
14: ; preds = %6
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %9, %1, %3
%20 = phi %struct.passwd* [ null, %3 ], [ null, %1 ], [ %7, %9 ]
ret %struct.passwd* %20
}