#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
jne    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>
test   %rax,%rax
je     1227 <dump_pwent+0xa7>
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    0xe61(%rip),%r14
xchg   %ax,%ax
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>
mov    0x2daa(%rip),%rax
movslq (%rax),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
mov    0x2d8e(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdcc(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

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 eq 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
@.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 [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 = icmp eq i32* %6, null
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = load i8**, i8*** @sys_errlist
%13 = load i64, i64* @errno
%14 = getelementptr inbounds i8*, i8** %12, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %15)
br label %39
17: ; preds = %1
%18 = tail call i32 (...) @setpwent()
%19 = tail call %struct.passwd* (...) @getpwent()
%20 = icmp eq %struct.passwd* %19, null
br i1 %20, label %36, label %21
21: ; preds = %17, %21
%22 = phi %struct.passwd* [ %34, %21 ], [ %19, %17 ]
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 2
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 4
%32 = load i32, i32* %31
%33 = 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* %24, i8* %26, i8* %28, i32 %30, i32 %32)
%34 = tail call %struct.passwd* (...) @getpwent()
%35 = icmp eq %struct.passwd* %34, null
br i1 %35, label %36, label %21
36: ; preds = %21, %17
%37 = tail call i32 (...) @endpwent()
%38 = tail call i32 @fclose(i32* %6)
br label %39
39: ; preds = %36, %8
ret void
}