#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_grent(char *);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  pid_t pid;
  if (argc != 2) {
    printf("ERROR: must specify output file identifier\n");
    return 1;
  }
  if ((pid = fork()) == -1) {
    printf("ERROR: unable to fork\n");
    return 1;
  }
  if (pid > 0) {
    int status;
    dump_grent(argv[1]);
    wait(&status);
  } else {
    dump_grent(argv[1]);
    return 0;
  }
  printf("PASS: run getgrent_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     1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11a3 <main+0x63>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xb4>
cmpl   $0x0,-0x14(%rbp)
jle    11c8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <dump_grent@plt>
lea    -0x18(%rbp),%rdi
call   1050 <wait@plt>
jmp    11e1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <dump_grent@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <main+0xb4>
lea    0xe5b(%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   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    117e <main+0x3e>
mov    %rsi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     1187 <main+0x47>
test   %eax,%eax
jle    119a <main+0x5a>
mov    0x8(%rbx),%rdi
call   1040 <dump_grent@plt>
lea    0xc(%rsp),%rdi
call   1050 <wait@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
jmp    11a3 <main+0x63>
lea    0xea8(%rip),%rdi
jmp    118e <main+0x4e>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11a5 <main+0x65>
mov    0x8(%rbx),%rdi
call   1040 <dump_grent@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [44 x i8] c"ERROR: must specify output file identifier\0A\00"
@.str.1 = [23 x i8] c"ERROR: unable to fork\0A\00"
@.str.2 = [24 x i8] c"PASS: run getgrent_r.c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
12: ; preds = %2
%13 = call i32 (...) @fork()
store i32 %13, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %33
17: ; preds = %12
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @dump_grent(i8* %23)
%25 = call i32 @wait(i32* %7)
br label %31
26: ; preds = %17
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @dump_grent(i8* %29)
store i32 0, i32* %3
br label %33
31: ; preds = %20
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %33
33: ; preds = %31, %26, %15, %10
%34 = load i32, i32* %3
ret i32 %34
}

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