#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;
  int pw_uid;
  int pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <passwd|group> <name>\n", argv[0]);
    return 1;
  }
  if (strcmp(argv[1], "passwd") == 0) {
    struct passwd *pw = getpwnam(argv[2]);
    if (!pw) {
      fprintf(stderr, "Unable to find %s\n", argv[2]);
      return 2;
    }
    printf("%s:%s:%d:%d:%s:%s:%s\n", pw->pw_name, pw->pw_passwd, pw->pw_uid,
           pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
    return 0;
  }
  if (strcmp(argv[1], "group") == 0) {
    printf("Not implemented\n");
    return 2;
  }
  fprintf(stderr, "Usage: %s <passwd|group> <name>\n", argv[0]);
  return 1;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     1188 <main+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1244 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11eb <main+0xab>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe4e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129f <main+0x15f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r9
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%r10
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xe13(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfe(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    127c <main+0x13c>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129f <main+0x15f>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd6d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1187 <main+0x37>
mov    0x8(%rbx),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ac <main+0x5c>
mov    0x8(%rbx),%rdi
lea    0xed4(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e6 <main+0x96>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe66(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x10(%rbx),%rdi
call   1060 <getpwnam@plt>
test   %rax,%rax
je     11f9 <main+0xa9>
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%ecx
mov    0x14(%rax),%r8d
mov    0x18(%rax),%r9
movups 0x20(%rax),%xmm0
movups %xmm0,(%rsp)
lea    0xe60(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a4 <main+0x54>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebx
jmp    11a4 <main+0x54>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xe1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%ebx
jmp    11a4 <main+0x54>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <passwd|group> <name>\0A\00"
@.str.1 = [7 x i8] c"passwd\00"
@.str.2 = [19 x i8] c"Unable to find %s\0A\00"
@.str.3 = [22 x i8] c"%s:%s:%d:%d:%s:%s:%s\0A\00"
@.str.4 = [6 x i8] c"group\00"
@.str.5 = [17 x i8] c"Not implemented\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %71
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %57
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call %struct.passwd* @getpwnam(i8* %24)
store %struct.passwd* %25, %struct.passwd** %6
%26 = load %struct.passwd*, %struct.passwd** %6
%27 = icmp ne %struct.passwd* %26, null
br i1 %27, label %34, label %28
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 2, i32* %3
br label %71
34: ; preds = %21
%35 = load %struct.passwd*, %struct.passwd** %6
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = load %struct.passwd*, %struct.passwd** %6
%39 = getelementptr inbounds %struct.passwd, %struct.passwd* %38, i32 0, i32 1
%40 = load i8*, i8** %39
%41 = load %struct.passwd*, %struct.passwd** %6
%42 = getelementptr inbounds %struct.passwd, %struct.passwd* %41, i32 0, i32 2
%43 = load i32, i32* %42
%44 = load %struct.passwd*, %struct.passwd** %6
%45 = getelementptr inbounds %struct.passwd, %struct.passwd* %44, i32 0, i32 3
%46 = load i32, i32* %45
%47 = load %struct.passwd*, %struct.passwd** %6
%48 = getelementptr inbounds %struct.passwd, %struct.passwd* %47, i32 0, i32 4
%49 = load i8*, i8** %48
%50 = load %struct.passwd*, %struct.passwd** %6
%51 = getelementptr inbounds %struct.passwd, %struct.passwd* %50, i32 0, i32 5
%52 = load i8*, i8** %51
%53 = load %struct.passwd*, %struct.passwd** %6
%54 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i32 0, i32 6
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %40, i32 %43, i32 %46, i8* %49, i8* %52, i8* %55)
store i32 0, i32* %3
br label %71
57: ; preds = %15
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %71
65: ; preds = %57
%66 = load i32, i32* @stderr
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 0
%69 = load i8*, i8** %68
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %69)
store i32 1, i32* %3
br label %71
71: ; preds = %65, %63, %34, %28, %9
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <passwd|group> <name>\0A\00"
@.str.1 = [7 x i8] c"passwd\00"
@.str.2 = [19 x i8] c"Unable to find %s\0A\00"
@.str.3 = [22 x i8] c"%s:%s:%d:%d:%s:%s:%s\0A\00"
@.str.4 = [6 x i8] c"group\00"
@str = [16 x i8] c"Not implemented\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %48
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %38
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call %struct.passwd* @getpwnam(i8* %15)
%17 = icmp eq %struct.passwd* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %14
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %48
22: ; preds = %13
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 2
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 4
%32 = load i8*, i8** %31
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 5
%34 = load i8*, i8** %33
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 6
%36 = load i8*, i8** %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %26, i32 %28, i32 %30, i8* %32, i8* %34, i8* %36)
br label %48
38: ; preds = %8
%39 = load i8*, i8** %9
%40 = tail call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %48
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %1
%47 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %18, %22, %44, %42, %4
%49 = phi i32 [ 1, %4 ], [ 2, %42 ], [ 1, %44 ], [ 0, %22 ], [ 2, %18 ]
ret i32 %49
}