#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ endpwent();
struct passwd *getpwent();
struct passwd *getpwnam(char *);
struct passwd *getpwuid(int);
int /*<<< orphan*/ print_pwd_entry(struct passwd *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setpwent();
void test_pwd() {
  struct passwd *pwd_ent;
  printf("All entries:\n");
  while ((pwd_ent = getpwent()) != NULL) {
    print_pwd_entry(pwd_ent);
  }
  printf("Back to start!\n");
  setpwent();
  printf("First entry again:\n");
  pwd_ent = getpwent();
  print_pwd_entry(pwd_ent);
  endpwent();
  printf("Entry for user 'root':\n");
  pwd_ent = getpwnam("root");
  if (pwd_ent != NULL) {
    print_pwd_entry(pwd_ent);
  }
  printf("Entry for user 'alfred'\n");
  pwd_ent = getpwnam("alfred");
  if (pwd_ent != NULL) {
    print_pwd_entry(pwd_ent);
  }
  printf("Entry for user with uid 0\n");
  pwd_ent = getpwuid(0);
  if (pwd_ent != NULL) {
    print_pwd_entry(pwd_ent);
  }
  printf("Entry for user with uid 65534\n");
  pwd_ent = getpwuid(65534);
  if (pwd_ent != NULL) {
    print_pwd_entry(pwd_ent);
  }
  printf("Entry for user with uid 666\n");
  pwd_ent = getpwuid(666);
  if (pwd_ent != NULL) {
    print_pwd_entry(pwd_ent);
  }
}


x86 assembly (clang, -O0):
<test_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getpwent@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11a7 <test_pwd+0x37>
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
jmp    1184 <test_pwd+0x14>
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <setpwent@plt>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getpwent@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
mov    $0x0,%al
call   1090 <endpwent@plt>
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1211 <test_pwd+0xa1>
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
lea    0xe44(%rip),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1241 <test_pwd+0xd1>
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     126c <test_pwd+0xfc>
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffe,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     129a <test_pwd+0x12a>
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    $0x29a,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12c8 <test_pwd+0x158>
mov    -0x8(%rbp),%rdi
call   1050 <print_pwd_entry@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pwd>:
push   %rax
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
nopl   (%rax)
xor    %eax,%eax
call   1080 <getpwent@plt>
test   %rax,%rax
je     1196 <test_pwd+0x26>
mov    %rax,%rdi
call   1050 <print_pwd_entry@plt>
jmp    1180 <test_pwd+0x10>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <setpwent@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <getpwent@plt>
mov    %rax,%rdi
call   1050 <print_pwd_entry@plt>
xor    %eax,%eax
call   1090 <endpwent@plt>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
lea    0xe22(%rip),%rdi
call   1060 <getpwnam@plt>
test   %rax,%rax
je     11f0 <test_pwd+0x80>
mov    %rax,%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe02(%rip),%rdi
call   1060 <getpwnam@plt>
test   %rax,%rax
je     1215 <test_pwd+0xa5>
mov    %rax,%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1235 <test_pwd+0xc5>
mov    %rax,%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffe,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1258 <test_pwd+0xe8>
mov    %rax,%rdi
call   1050 <print_pwd_entry@plt>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
mov    $0x29a,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     127c <test_pwd+0x10c>
mov    %rax,%rdi
pop    %rax
jmp    1050 <print_pwd_entry@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [14 x i8] c"All entries:\0A\00"
@.str.1 = [16 x i8] c"Back to start!\0A\00"
@.str.2 = [20 x i8] c"First entry again:\0A\00"
@.str.3 = [24 x i8] c"Entry for user 'root':\0A\00"
@.str.4 = [5 x i8] c"root\00"
@.str.5 = [25 x i8] c"Entry for user 'alfred'\0A\00"
@.str.6 = [7 x i8] c"alfred\00"
@.str.7 = [27 x i8] c"Entry for user with uid 0\0A\00"
@.str.8 = [31 x i8] c"Entry for user with uid 65534\0A\00"
@.str.9 = [29 x i8] c"Entry for user with uid 666\0A\00"
define void @test_pwd() {
%1 = alloca %struct.passwd*
%2 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %6, %0
%4 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %4, %struct.passwd** %1
%5 = icmp ne %struct.passwd* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load %struct.passwd*, %struct.passwd** %1
%8 = call i32 @print_pwd_entry(%struct.passwd* %7)
br label %3
9: ; preds = %3
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (...) @setpwent()
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%13 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %13, %struct.passwd** %1
%14 = load %struct.passwd*, %struct.passwd** %1
%15 = call i32 @print_pwd_entry(%struct.passwd* %14)
%16 = call i32 (...) @endpwent()
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%18 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store %struct.passwd* %18, %struct.passwd** %1
%19 = load %struct.passwd*, %struct.passwd** %1
%20 = icmp ne %struct.passwd* %19, null
br i1 %20, label %21, label %24
21: ; preds = %9
%22 = load %struct.passwd*, %struct.passwd** %1
%23 = call i32 @print_pwd_entry(%struct.passwd* %22)
br label %24
24: ; preds = %21, %9
%25 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%26 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
store %struct.passwd* %26, %struct.passwd** %1
%27 = load %struct.passwd*, %struct.passwd** %1
%28 = icmp ne %struct.passwd* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load %struct.passwd*, %struct.passwd** %1
%31 = call i32 @print_pwd_entry(%struct.passwd* %30)
br label %32
32: ; preds = %29, %24
%33 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%34 = call %struct.passwd* @getpwuid(i32 0)
store %struct.passwd* %34, %struct.passwd** %1
%35 = load %struct.passwd*, %struct.passwd** %1
%36 = icmp ne %struct.passwd* %35, null
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load %struct.passwd*, %struct.passwd** %1
%39 = call i32 @print_pwd_entry(%struct.passwd* %38)
br label %40
40: ; preds = %37, %32
%41 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%42 = call %struct.passwd* @getpwuid(i32 65534)
store %struct.passwd* %42, %struct.passwd** %1
%43 = load %struct.passwd*, %struct.passwd** %1
%44 = icmp ne %struct.passwd* %43, null
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load %struct.passwd*, %struct.passwd** %1
%47 = call i32 @print_pwd_entry(%struct.passwd* %46)
br label %48
48: ; preds = %45, %40
%49 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%50 = call %struct.passwd* @getpwuid(i32 666)
store %struct.passwd* %50, %struct.passwd** %1
%51 = load %struct.passwd*, %struct.passwd** %1
%52 = icmp ne %struct.passwd* %51, null
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load %struct.passwd*, %struct.passwd** %1
%55 = call i32 @print_pwd_entry(%struct.passwd* %54)
br label %56
56: ; preds = %53, %48
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str.4 = [5 x i8] c"root\00"
@.str.6 = [7 x i8] c"alfred\00"
@str = [13 x i8] c"All entries:\00"
@str.10 = [15 x i8] c"Back to start!\00"
@str.11 = [19 x i8] c"First entry again:\00"
@str.12 = [23 x i8] c"Entry for user 'root':\00"
@str.13 = [24 x i8] c"Entry for user 'alfred'\00"
@str.14 = [26 x i8] c"Entry for user with uid 0\00"
@str.15 = [30 x i8] c"Entry for user with uid 65534\00"
@str.16 = [28 x i8] c"Entry for user with uid 666\00"
define void @test_pwd() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%2 = tail call %struct.passwd* (...) @getpwent()
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %9, label %4
4: ; preds = %0, %4
%5 = phi %struct.passwd* [ %7, %4 ], [ %2, %0 ]
%6 = tail call i32 @print_pwd_entry(%struct.passwd* %5)
%7 = tail call %struct.passwd* (...) @getpwent()
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %4
9: ; preds = %4, %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0))
%11 = tail call i32 (...) @setpwent()
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.11, i64 0, i64 0))
%13 = tail call %struct.passwd* (...) @getpwent()
%14 = tail call i32 @print_pwd_entry(%struct.passwd* %13)
%15 = tail call i32 (...) @endpwent()
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0))
%17 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq %struct.passwd* %17, null
br i1 %18, label %21, label %19
19: ; preds = %9
%20 = tail call i32 @print_pwd_entry(%struct.passwd* %17)
br label %21
21: ; preds = %19, %9
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
%23 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%24 = icmp eq %struct.passwd* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @print_pwd_entry(%struct.passwd* %23)
br label %27
27: ; preds = %25, %21
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.14, i64 0, i64 0))
%29 = tail call %struct.passwd* @getpwuid(i32 0)
%30 = icmp eq %struct.passwd* %29, null
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = tail call i32 @print_pwd_entry(%struct.passwd* %29)
br label %33
33: ; preds = %31, %27
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.15, i64 0, i64 0))
%35 = tail call %struct.passwd* @getpwuid(i32 65534)
%36 = icmp eq %struct.passwd* %35, null
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = tail call i32 @print_pwd_entry(%struct.passwd* %35)
br label %39
39: ; preds = %37, %33
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.16, i64 0, i64 0))
%41 = tail call %struct.passwd* @getpwuid(i32 666)
%42 = icmp eq %struct.passwd* %41, null
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = tail call i32 @print_pwd_entry(%struct.passwd* %41)
br label %45
45: ; preds = %43, %39
ret void
}