#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*/ printf(char *);
int /*<<< orphan*/ setpwent();
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
struct passwd *getpwnam(const char *name) {
  printf("my getpwnam method\n");
  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)
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <setpwent@plt>
mov    $0x0,%al
call   1060 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11a7 <getpwnam+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a2 <getpwnam+0x52>
jmp    11a7 <getpwnam+0x57>
jmp    116f <getpwnam+0x1f>
mov    $0x0,%al
call   1070 <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
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <setpwent@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118e <getpwnam+0x3e>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1170 <getpwnam+0x20>
xor    %eax,%eax
call   1070 <endpwent@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [20 x i8] c"my getpwnam method\0A\00"
define %struct.passwd* @getpwnam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
store i8* %0, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @setpwent()
br label %6
6: ; preds = %17, %1
%7 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %7, %struct.passwd** %3
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load %struct.passwd*, %struct.passwd** %3
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @strcmp(i8* %10, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
br label %18
17: ; preds = %9
br label %6
18: ; preds = %16, %6
%19 = call i32 (...) @endpwent()
%20 = load %struct.passwd*, %struct.passwd** %3
ret %struct.passwd* %20
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@str = [19 x i8] c"my getpwnam method\00"
define %struct.passwd* @getpwnam(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @setpwent()
br label %4
4: ; preds = %7, %1
%5 = tail call %struct.passwd* (...) @getpwent()
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i64 @strcmp(i8* %0, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %4
12: ; preds = %7, %4
%13 = tail call i32 (...) @endpwent()
ret %struct.passwd* %5
}