#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ dump_pwent(char *);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  pid_t pids[2];
  int i, status;
  if (argc != 2) {
    printf("ERROR: must specify output file identifier\n");
    return 1;
  }
  for (i = 0; i < 2; i++) {
    if ((pids[i] = fork()) == -1) {
      perror("fork");
      return 1;
    }
    if (pids[i] == 0) {
      dump_pwent(argv[1]);
      return 0;
    }
  }
  for (i = 0; i < 2; i++) {
    waitpid(pids[i], &status, 0);
  }
  printf("PASS: getpwent_r.c\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1249 <main+0xf9>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1204 <main+0xb4>
mov    $0x0,%al
call   1070 <fork@plt>
movslq -0x1c(%rbp),%rcx
mov    %eax,-0x18(%rbp,%rcx,4)
cmp    $0xffffffff,%eax
jne    11c9 <main+0x79>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1249 <main+0xf9>
movslq -0x1c(%rbp),%rax
cmpl   $0x0,-0x18(%rbp,%rax,4)
jne    11f1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <dump_pwent@plt>
movl   $0x0,-0x4(%rbp)
jmp    1249 <main+0xf9>
jmp    11f6 <main+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <main+0x3f>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1236 <main+0xe6>
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120b <main+0xbb>
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11b4 <main+0x64>
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11c7 <main+0x77>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11dd <main+0x8d>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11c7 <main+0x77>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     11dd <main+0x8d>
lea    0x4(%rsp),%r14
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
jmp    11d0 <main+0x80>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11d0 <main+0x80>
mov    0x8(%r14),%rdi
call   1040 <dump_pwent@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    11d0 <main+0x80>

LLVM IR (-O0):
@.str = [44 x i8] c"ERROR: must specify output file identifier\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [20 x i8] c"PASS: getpwent_r.c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %55
13: ; preds = %2
store i32 0, i32* %7
br label %14
14: ; preds = %37, %13
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %40
17: ; preds = %14
%18 = call i32 (...) @fork()
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %20
store i32 %18, i32* %21
%22 = icmp eq i32 %18, -1
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %55
25: ; preds = %17
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @dump_pwent(i8* %34)
store i32 0, i32* %3
br label %55
36: ; preds = %25
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %14
40: ; preds = %14
store i32 0, i32* %7
br label %41
41: ; preds = %50, %40
%42 = load i32, i32* %7
%43 = icmp slt i32 %42, 2
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @waitpid(i32 %48, i32* %8, i32 0)
br label %50
50: ; preds = %44
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %41
53: ; preds = %41
%54 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %55
55: ; preds = %53, %31, %23, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"fork\00"
@str = [19 x i8] c"PASS: getpwent_r.c\00"
@str.3 = [43 x i8] c"ERROR: must specify output file identifier\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @fork()
switch i32 %7, label %16 [
i32 -1, label %10
i32 0, label %12
]
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.3, i64 0, i64 0))
br label %22
10: ; preds = %16, %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %16, %6
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @dump_pwent(i8* %14)
br label %22
16: ; preds = %6
%17 = tail call i32 (...) @fork()
switch i32 %17, label %18 [
i32 -1, label %10
i32 0, label %12
]
18: ; preds = %16
%19 = call i32 @waitpid(i32 %7, i32* %3, i32 0)
%20 = call i32 @waitpid(i32 %17, i32* %3, i32 0)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %18, %12, %10, %8
%23 = phi i32 [ 1, %8 ], [ 1, %10 ], [ 0, %12 ], [ 0, %18 ]
ret i32 %23
}