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

/* Variables and functions */
int /*<<< orphan*/ endpwent();
size_t errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *, ...);
int getpid();
struct passwd *getpwent();
int /*<<< orphan*/ setpwent();
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ stderr;
char **sys_errlist;
void dump_pwent(char *id) {
  struct passwd *pw;
  char fname[255];
  FILE *fptr;
  sprintf(fname, "/tmp/getpwent_r-%s.out-%d", id, getpid());
  if ((fptr = fopen(fname, "w")) < 0) {
    fprintf(stderr, "ERROR: could not open file %s: %s\n", fname,
            sys_errlist[errno]);
    return;
  }
  setpwent();
  while ((pw = getpwent()) != NULL) {
    fprintf(fptr, "%s:%s:%s:%d:%d\n", pw->pw_name, pw->pw_passwd, pw->pw_gecos,
            pw->pw_uid, pw->pw_gid);
  }
  endpwent();
  fclose(fptr);
}


x86 assembly (clang, -O0):
<dump_pwent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x128(%rbp),%rdi
mov    -0x120(%rbp),%rdx
mov    %eax,%ecx
lea    0xe3a(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
jae    122b <dump_pwent+0xab>
mov    0x2de2(%rip),%rax
movslq (%rax),%rdi
lea    -0x110(%rbp),%rdx
mov    0x2df1(%rip),%rax
mov    (%rax),%rax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    129d <dump_pwent+0x11d>
mov    $0x0,%al
call   1050 <setpwent@plt>
mov    $0x0,%al
call   1070 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     128a <dump_pwent+0x10a>
mov    -0x118(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r9d
mov    -0x10(%rbp),%rax
mov    0x1c(%rax),%eax
lea    0xdc4(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1232 <dump_pwent+0xb2>
mov    $0x0,%al
call   1080 <endpwent@plt>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_pwent>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe65(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   10a0 <sprintf@plt>
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <setpwent@plt>
xor    %eax,%eax
call   1070 <getpwent@plt>
test   %rax,%rax
je     120e <dump_pwent+0x8e>
lea    0xe43(%rip),%r14
nopl   0x0(%rax)
mov    (%rax),%rdx
mov    0x8(%rax),%rcx
mov    0x10(%rax),%r8
mov    0x18(%rax),%r9d
mov    0x1c(%rax),%eax
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1070 <getpwent@plt>
test   %rax,%rax
jne    11e0 <dump_pwent+0x60>
xor    %eax,%eax
call   1080 <endpwent@plt>
mov    %rbx,%rdi
add    $0x118,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8*, i32, i32 }
@.str = [26 x i8] c"/tmp/getpwent_r-%s.out-%d\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"ERROR: could not open file %s: %s\0A\00"
@sys_errlist = global i8** null
@errno = global i64 0
@.str.3 = [16 x i8] c"%s:%s:%s:%d:%d\0A\00"
define void @dump_pwent(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
%4 = alloca [255 x i8]
%5 = alloca i32*
store i8* %0, i8** %2
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 (...) @getpid()
%9 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %8)
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp ult i32* %11, null
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = load i8**, i8*** @sys_errlist
%19 = load i64, i64* @errno
%20 = getelementptr inbounds i8*, i8** %18, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %21)
br label %50
23: ; preds = %1
%24 = call i32 (...) @setpwent()
br label %25
25: ; preds = %28, %23
%26 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %26, %struct.passwd** %3
%27 = icmp ne %struct.passwd* %26, null
br i1 %27, label %28, label %46
28: ; preds = %25
%29 = load i32*, i32** %5
%30 = load %struct.passwd*, %struct.passwd** %3
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = load %struct.passwd*, %struct.passwd** %3
%34 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i32 0, i32 1
%35 = load i8*, i8** %34
%36 = load %struct.passwd*, %struct.passwd** %3
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 2
%38 = load i8*, i8** %37
%39 = load %struct.passwd*, %struct.passwd** %3
%40 = getelementptr inbounds %struct.passwd, %struct.passwd* %39, i32 0, i32 3
%41 = load i32, i32* %40
%42 = load %struct.passwd*, %struct.passwd** %3
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 4
%44 = load i32, i32* %43
%45 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %32, i8* %35, i8* %38, i32 %41, i32 %44)
br label %25
46: ; preds = %25
%47 = call i32 (...) @endpwent()
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %46, %13
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8*, i32, i32 }
@.str = [26 x i8] c"/tmp/getpwent_r-%s.out-%d\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@sys_errlist = global i8** null
@errno = global i64 0
@.str.3 = [16 x i8] c"%s:%s:%s:%d:%d\0A\00"
define void @dump_pwent(i8* %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @getpid()
%5 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %4)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 (...) @setpwent()
%8 = tail call %struct.passwd* (...) @getpwent()
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %25, label %10
10: ; preds = %1, %10
%11 = phi %struct.passwd* [ %23, %10 ], [ %8, %1 ]
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 2
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 4
%21 = load i32, i32* %20
%22 = tail call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %15, i8* %17, i32 %19, i32 %21)
%23 = tail call %struct.passwd* (...) @getpwent()
%24 = icmp eq %struct.passwd* %23, null
br i1 %24, label %25, label %10
25: ; preds = %10, %1
%26 = tail call i32 (...) @endpwent()
%27 = tail call i32 @fclose(i32* %6)
ret void
}