#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;
  char *pw_passwd;
  int pw_uid;
  int pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ getpwent_r(struct passwd *, char *, int, struct passwd **);
int /*<<< orphan*/ printf(char *, char *, char *, int, int, char *, char *,
                          char *);
int main(int argc, char *argv[]) {
  struct passwd pw, *tmp;
  char buf[1000];
  while (getpwent_r(&pw, buf, sizeof(buf), &tmp) == 0) {
    printf("name %s\npassword %s\nuid %u\ngid %u\ngecos %s\ndir %s\nshell %s\n",
           pw.pw_name, pw.pw_passwd, pw.pw_uid, pw.pw_gid, pw.pw_gecos,
           pw.pw_dir, pw.pw_shell);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x430(%rbp),%rsi
lea    -0x40(%rbp),%rdi
mov    $0x3e8,%edx
lea    -0x48(%rbp),%rcx
call   1030 <getpwent_r@plt>
cmp    $0x0,%rax
jne    1191 <main+0x71>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    -0x20(%rbp),%r10
mov    -0x18(%rbp),%rax
lea    0xe82(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <printf@plt>
jmp    1139 <main+0x19>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x438,%rsp
lea    0x20(%rsp),%rdi
lea    0x50(%rsp),%rsi
lea    0x18(%rsp),%rcx
mov    $0x3e8,%edx
call   1030 <getpwent_r@plt>
test   %rax,%rax
jne    11b1 <main+0x91>
lea    0xead(%rip),%r14
lea    0x20(%rsp),%r15
lea    0x50(%rsp),%r12
lea    0x18(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x20(%rsp),%rsi
mov    0x28(%rsp),%rdx
mov    0x30(%rsp),%ecx
mov    0x34(%rsp),%r8d
mov    0x38(%rsp),%r9
movups 0x40(%rsp),%xmm0
movups %xmm0,(%rsp)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x3e8,%edx
mov    %rbx,%rcx
call   1030 <getpwent_r@plt>
test   %rax,%rax
je     1170 <main+0x50>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@.str = [60 x i8] c"name %s\0Apassword %s\0Auid %u\0Agid %u\0Agecos %s\0Adir %s\0Ashell %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd
%7 = alloca %struct.passwd*
%8 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %13, %2
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%11 = call i64 @getpwent_r(%struct.passwd* %6, i8* %10, i32 1000, %struct.passwd** %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 2
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 4
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 5
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i32 0, i32 6
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17, i32 %19, i32 %21, i8* %23, i8* %25, i8* %27)
br label %9
29: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@.str = [60 x i8] c"name %s\0Apassword %s\0Auid %u\0Agid %u\0Agecos %s\0Adir %s\0Ashell %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.passwd
%4 = alloca %struct.passwd*
%5 = alloca [1000 x i8]
%6 = bitcast %struct.passwd* %3 to i8*
%7 = bitcast %struct.passwd** %4 to i8*
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%9 = call i64 @getpwent_r(%struct.passwd* %3, i8* %8, i32 1000, %struct.passwd** %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %2
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 2
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 3
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 4
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 5
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 6
br label %19
19: ; preds = %11, %19
%20 = load i8*, i8** %12
%21 = load i8*, i8** %13
%22 = load i32, i32* %14
%23 = load i32, i32* %15
%24 = load i8*, i8** %16
%25 = load i8*, i8** %17
%26 = load i8*, i8** %18
%27 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21, i32 %22, i32 %23, i8* %24, i8* %25, i8* %26)
%28 = call i64 @getpwent_r(%struct.passwd* %3, i8* %8, i32 1000, %struct.passwd** %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %19, label %30
30: ; preds = %19, %2
ret i32 0
}