#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 __nss_configure_lookup(char *, char *);
int /*<<< orphan*/ endpwent();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct passwd *getpwent();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_passwd_struct(int /*<<< orphan*/, struct passwd *);
int /*<<< orphan*/ setpwent();
int /*<<< orphan*/ stderr;
int main(void) {
  fprintf(stderr, "Configuring exfiles password lookup...\n");
  if (-1 == __nss_configure_lookup("passwd", "exfiles")) {
    perror("Error configuring NSS");
    exit(1);
  }
  struct passwd *p;
  setpwent();
  do {
    p = getpwent();
    if (NULL == p) {
      break;
    }
    print_passwd_struct(stderr, p);
  } while (NULL != p);
  endpwent();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe7d(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1030 <__nss_configure_lookup@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11dc <main+0x5c>
lea    0xe6a(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1040 <setpwent@plt>
mov    $0x0,%al
call   1060 <getpwent@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11ff <main+0x7f>
jmp    121d <main+0x9d>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1090 <print_passwd_struct@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11e3 <main+0x63>
mov    $0x0,%al
call   1070 <endpwent@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e58(%rip),%rbx
mov    (%rbx),%edi
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe8b(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <__nss_configure_lookup@plt>
cmp    $0xffffffff,%eax
je     11e3 <main+0x63>
xor    %eax,%eax
call   1040 <setpwent@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <getpwent@plt>
test   %rax,%rax
je     11d8 <main+0x58>
mov    (%rbx),%edi
mov    %rax,%rsi
call   1090 <print_passwd_struct@plt>
jmp    11c0 <main+0x40>
xor    %eax,%eax
call   1070 <endpwent@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe4d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [40 x i8] c"Configuring exfiles password lookup...\0A\00"
@.str.1 = [7 x i8] c"passwd\00"
@.str.2 = [8 x i8] c"exfiles\00"
@.str.3 = [22 x i8] c"Error configuring NSS\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.passwd*
store i32 0, i32* %1
%3 = load i32, i32* @stderr
%4 = call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @__nss_configure_lookup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32 -1, %5
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 (...) @setpwent()
br label %12
12: ; preds = %21, %10
%13 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %13, %struct.passwd** %2
%14 = load %struct.passwd*, %struct.passwd** %2
%15 = icmp eq %struct.passwd* null, %14
br i1 %15, label %16, label %17
16: ; preds = %12
br label %24
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load %struct.passwd*, %struct.passwd** %2
%20 = call i32 @print_passwd_struct(i32 %18, %struct.passwd* %19)
br label %21
21: ; preds = %17
%22 = load %struct.passwd*, %struct.passwd** %2
%23 = icmp ne %struct.passwd* null, %22
br i1 %23, label %12, label %24
24: ; preds = %21, %16
%25 = call i32 (...) @endpwent()
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [40 x i8] c"Configuring exfiles password lookup...\0A\00"
@.str.1 = [7 x i8] c"passwd\00"
@.str.2 = [8 x i8] c"exfiles\00"
@.str.3 = [22 x i8] c"Error configuring NSS\00"
define i32 @main() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @__nss_configure_lookup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 (...) @setpwent()
%10 = tail call %struct.passwd* (...) @getpwent()
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %18, label %12
12: ; preds = %8, %12
%13 = phi %struct.passwd* [ %16, %12 ], [ %10, %8 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 @print_passwd_struct(i32 %14, %struct.passwd* %13)
%16 = tail call %struct.passwd* (...) @getpwent()
%17 = icmp eq %struct.passwd* %16, null
br i1 %17, label %18, label %12
18: ; preds = %12, %8
%19 = tail call i32 (...) @endpwent()
ret i32 0
}