#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 {
  char *pw_name;
  int pw_uid;
  int pw_gid;
  char *pw_shell;
};

/* Variables and functions */
int /*<<< orphan*/ endpwent();
struct passwd *getpwent();
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ setpwent();
int _getpwent(char const *progname) {
  struct passwd *pw;
  setpwent();
  printf("%s: Testing getpwent()\n", progname);
  while ((pw = getpwent()) != NULL)
    printf("%s: %s (%u:%u) %s\n", progname, pw->pw_name, pw->pw_uid, pw->pw_gid,
           pw->pw_shell);
  endpwent();
  return 0;
}


x86 assembly (clang, -O0):
<_getpwent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <setpwent@plt>
mov    -0x8(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11af <_getpwent+0x6f>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r9
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1165 <_getpwent+0x25>
mov    $0x0,%al
call   1060 <endpwent@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getpwent>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <setpwent@plt>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getpwent@plt>
test   %rax,%rax
je     11a7 <_getpwent+0x67>
lea    0xea6(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rax),%rdx
mov    0x8(%rax),%ecx
mov    0xc(%rax),%r8d
mov    0x10(%rax),%r9
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getpwent@plt>
test   %rax,%rax
jne    1180 <_getpwent+0x40>
xor    %eax,%eax
call   1060 <endpwent@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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