#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 {
  int dummy;
};
struct group {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ endgrent();
int /*<<< orphan*/ endpwent();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct group *getgrent();
struct passwd *getpwent();
int group_keys(int, char **);
int passwd_keys(int, char **);
int /*<<< orphan*/ print_group(struct group *);
int /*<<< orphan*/ print_passwd(struct passwd *);
int /*<<< orphan*/ setgrent();
int /*<<< orphan*/ setpwent();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  switch (argv[1][0]) {
  case 'g':
    if (strcmp(argv[1], "group") == 0) {
      if (argc == 2) {
        struct group *grp;
        setgrent();
        while ((grp = getgrent()) != NULL)
          print_group(grp);
        endgrent();
      } else
        return group_keys(argc - 2, &argv[2]);
    } else
      goto error;
    break;
  case 'p':
    if (strcmp(argv[1], "passwd") == 0) {
      if (argc == 2) {
        struct passwd *pwd;
        setpwent();
        while ((pwd = getpwent()) != NULL)
          print_passwd(pwd);
        endpwent();
      } else
        return passwd_keys(argc - 2, &argv[2]);
    } else
      goto error;
    break;
  default:
  error:
    fprintf(stderr, "Unknown database: %s\n", argv[1]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x67,%eax
je     1203 <main+0x43>
jmp    11f2 <main+0x32>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
je     128a <main+0xca>
jmp    1311 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdee(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1280 <main+0xc0>
cmpl   $0x2,-0x8(%rbp)
jne    1260 <main+0xa0>
mov    $0x0,%al
call   1050 <setgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1254 <main+0x94>
mov    -0x18(%rbp),%rdi
call   10d0 <print_group@plt>
jmp    1231 <main+0x71>
mov    $0x0,%al
call   1030 <endgrent@plt>
jmp    127b <main+0xbb>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   10a0 <group_keys@plt>
mov    %eax,-0x4(%rbp)
jmp    1346 <main+0x186>
jmp    1285 <main+0xc5>
jmp    1316 <main+0x156>
jmp    133f <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd6d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1307 <main+0x147>
cmpl   $0x2,-0x8(%rbp)
jne    12e7 <main+0x127>
mov    $0x0,%al
call   1070 <setpwent@plt>
mov    $0x0,%al
call   1090 <getpwent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12db <main+0x11b>
mov    -0x20(%rbp),%rdi
call   10e0 <print_passwd@plt>
jmp    12b8 <main+0xf8>
mov    $0x0,%al
call   10c0 <endpwent@plt>
jmp    1302 <main+0x142>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   10b0 <passwd_keys@plt>
mov    %eax,-0x4(%rbp)
jmp    1346 <main+0x186>
jmp    130c <main+0x14c>
jmp    1316 <main+0x156>
jmp    133f <main+0x17f>
jmp    1316 <main+0x156>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcdf(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1346 <main+0x186>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x8(%rsi),%rbp
movsbl 0x0(%rbp),%eax
cmp    $0x70,%eax
je     122a <main+0x6a>
cmp    $0x67,%eax
jne    123d <main+0x7d>
lea    0xe1d(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    123d <main+0x7d>
cmp    $0x2,%r14d
jne    1286 <main+0xc6>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <setgrent@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getgrent@plt>
test   %rax,%rax
je     129d <main+0xdd>
mov    %rax,%rdi
call   10d0 <print_group@plt>
jmp    1210 <main+0x50>
lea    0xdd5(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1261 <main+0xa1>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    %rbp,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x2,%r14d
jne    12a6 <main+0xe6>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <setpwent@plt>
xor    %eax,%eax
call   1090 <getpwent@plt>
test   %rax,%rax
je     12bd <main+0xfd>
mov    %rax,%rdi
call   10e0 <print_passwd@plt>
jmp    1270 <main+0xb0>
add    $0xfffffffe,%r14d
add    $0x10,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    10a0 <group_keys@plt>
xor    %eax,%eax
call   1030 <endgrent@plt>
jmp    125a <main+0x9a>
add    $0xfffffffe,%r14d
add    $0x10,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    10b0 <passwd_keys@plt>
xor    %eax,%eax
call   10c0 <endpwent@plt>
jmp    125a <main+0x9a>

LLVM IR (-O0):
%struct.group = type { i32 }
%struct.passwd = type { i32 }
@.str = [6 x i8] c"group\00"
@.str.1 = [7 x i8] c"passwd\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Unknown database: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.group*
%7 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %70 [
i32 103, label %14
i32 112, label %42
]
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %14
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = call i32 (...) @setgrent()
br label %25
25: ; preds = %28, %23
%26 = call %struct.group* (...) @getgrent()
store %struct.group* %26, %struct.group** %6
%27 = icmp ne %struct.group* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load %struct.group*, %struct.group** %6
%30 = call i32 @print_group(%struct.group* %29)
br label %25
31: ; preds = %25
%32 = call i32 (...) @endgrent()
br label %39
33: ; preds = %20
%34 = load i32, i32* %4
%35 = sub nsw i32 %34, 2
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = call i32 @group_keys(i32 %35, i8** %37)
store i32 %38, i32* %3
br label %78
39: ; preds = %31
br label %41
40: ; preds = %14
br label %71
41: ; preds = %39
br label %77
42: ; preds = %2
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @strcmp(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %68
48: ; preds = %42
%49 = load i32, i32* %4
%50 = icmp eq i32 %49, 2
br i1 %50, label %51, label %61
51: ; preds = %48
%52 = call i32 (...) @setpwent()
br label %53
53: ; preds = %56, %51
%54 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %54, %struct.passwd** %7
%55 = icmp ne %struct.passwd* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load %struct.passwd*, %struct.passwd** %7
%58 = call i32 @print_passwd(%struct.passwd* %57)
br label %53
59: ; preds = %53
%60 = call i32 (...) @endpwent()
br label %67
61: ; preds = %48
%62 = load i32, i32* %4
%63 = sub nsw i32 %62, 2
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = call i32 @passwd_keys(i32 %63, i8** %65)
store i32 %66, i32* %3
br label %78
67: ; preds = %59
br label %69
68: ; preds = %42
br label %71
69: ; preds = %67
br label %77
70: ; preds = %2
br label %71
71: ; preds = %70, %68, %40
%72 = load i32, i32* @stderr
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %75)
store i32 1, i32* %3
br label %78
77: ; preds = %69, %41
store i32 0, i32* %3
br label %78
78: ; preds = %77, %71, %61, %33
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.group = type { i32 }
%struct.passwd = type { i32 }
@.str = [6 x i8] c"group\00"
@.str.1 = [7 x i8] c"passwd\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Unknown database: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %47 [
i32 103, label %7
i32 112, label %27
]
7: ; preds = %2
%8 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %47
10: ; preds = %7
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %23
12: ; preds = %10
%13 = tail call i32 (...) @setgrent()
%14 = tail call %struct.group* (...) @getgrent()
%15 = icmp eq %struct.group* %14, null
br i1 %15, label %21, label %16
16: ; preds = %12, %16
%17 = phi %struct.group* [ %19, %16 ], [ %14, %12 ]
%18 = tail call i32 @print_group(%struct.group* %17)
%19 = tail call %struct.group* (...) @getgrent()
%20 = icmp eq %struct.group* %19, null
br i1 %20, label %21, label %16
21: ; preds = %16, %12
%22 = tail call i32 (...) @endgrent()
br label %50
23: ; preds = %10
%24 = add nsw i32 %0, -2
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = tail call i32 @group_keys(i32 %24, i8** %25)
br label %50
27: ; preds = %2
%28 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %27
%31 = icmp eq i32 %0, 2
br i1 %31, label %32, label %43
32: ; preds = %30
%33 = tail call i32 (...) @setpwent()
%34 = tail call %struct.passwd* (...) @getpwent()
%35 = icmp eq %struct.passwd* %34, null
br i1 %35, label %41, label %36
36: ; preds = %32, %36
%37 = phi %struct.passwd* [ %39, %36 ], [ %34, %32 ]
%38 = tail call i32 @print_passwd(%struct.passwd* %37)
%39 = tail call %struct.passwd* (...) @getpwent()
%40 = icmp eq %struct.passwd* %39, null
br i1 %40, label %41, label %36
41: ; preds = %36, %32
%42 = tail call i32 (...) @endpwent()
br label %50
43: ; preds = %30
%44 = add nsw i32 %0, -2
%45 = getelementptr inbounds i8*, i8** %1, i64 2
%46 = tail call i32 @passwd_keys(i32 %44, i8** %45)
br label %50
47: ; preds = %2, %27, %7
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %50
50: ; preds = %21, %41, %47, %43, %23
%51 = phi i32 [ 1, %47 ], [ %46, %43 ], [ %26, %23 ], [ 0, %41 ], [ 0, %21 ]
ret i32 %51
}