#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 /*<<< orphan*/ uid_t;
struct passwd {
  char *pw_name;
  int pw_uid;
  int pw_gid;
  char *pw_passwd;
};

/* Variables and functions */
struct passwd *getpwnam(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int uid;
  char name[64];
  char *endptr;
  char *nptr;
  struct passwd *pwd;
  if (argc < 2) {
    printf("Usage : passwd.out <UserName|uid>");
    return 1;
  }
  nptr = argv[1];
  endptr = name;
  uid = strtol(nptr, &endptr, 10);
  printf("endptr: %s \t uid:%d \t nptr:%s\n", endptr, uid, nptr);
  if (0 != strlen(endptr)) {
    printf("getpwnam\n");
    pwd = getpwnam(nptr);
  } else {
    printf("getpwuid\n");
    pwd = getpwuid((uid_t)uid);
  }
  if (NULL != pwd) {
    printf("%12s \t %10s \t %10s \t %10s\n", "User", "uid", "gid", "pwd");
    printf("%12s \t %10d \t %10d \t %10s\n", pwd->pw_name, pwd->pw_uid,
           pwd->pw_gid, pwd->pw_passwd);
    return 0;
  } else {
    printf("Cannot find user: %s\n", nptr);
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118d <main+0x3d>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <main+0x156>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x70(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
lea    -0x68(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x70(%rbp),%rcx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1206 <main+0xb6>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x70(%rbp),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x78(%rbp)
jmp    1220 <main+0xd0>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x78(%rbp)
xor    %eax,%eax
cmp    -0x78(%rbp),%rax
je     128d <main+0x13d>
lea    0xe22(%rip),%rdi
lea    0xe36(%rip),%rsi
lea    0xe34(%rip),%rdx
lea    0xe31(%rip),%rcx
lea    0xe2e(%rip),%r8
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%rax
mov    (%rax),%rsi
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%edx
mov    -0x78(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x78(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <main+0x156>
mov    -0x70(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
cmp    $0x1,%edi
jg     1170 <main+0x20>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    123e <main+0xee>
mov    0x8(%rsi),%r14
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rbp
lea    0xe84(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x0,0x0(%rbp)
je     11c9 <main+0x79>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <getpwnam@plt>
jmp    11dc <main+0x8c>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <getpwuid@plt>
mov    %rax,%rbx
test   %rax,%rax
je     122d <main+0xdd>
lea    0xe56(%rip),%rdi
lea    0xe6a(%rip),%rsi
lea    0xea6(%rip),%rdx
lea    0xe61(%rip),%rcx
lea    0xe5e(%rip),%r8
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%ecx
mov    0x10(%rbx),%r8
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1243 <main+0xf3>
lea    0xe50(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i32, i32, i8* }
@.str = [34 x i8] c"Usage : passwd.out <UserName|uid>\00"
@.str.1 = [31 x i8] c"endptr: %s \09 uid:%d \09 nptr:%s\0A\00"
@.str.2 = [10 x i8] c"getpwnam\0A\00"
@.str.3 = [10 x i8] c"getpwuid\0A\00"
@.str.4 = [27 x i8] c"%12s \09 %10s \09 %10s \09 %10s\0A\00"
@.str.5 = [5 x i8] c"User\00"
@.str.6 = [4 x i8] c"uid\00"
@.str.7 = [4 x i8] c"gid\00"
@.str.8 = [4 x i8] c"pwd\00"
@.str.9 = [27 x i8] c"%12s \09 %10d \09 %10d \09 %10s\0A\00"
@.str.10 = [22 x i8] c"Cannot find user: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %58
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %9
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
store i8* %19, i8** %8
%20 = load i8*, i8** %9
%21 = call i32 @strtol(i8* %20, i8** %8, i32 10)
store i32 %21, i32* %6
%22 = load i8*, i8** %8
%23 = load i32, i32* %6
%24 = load i8*, i8** %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %23, i8* %24)
%26 = load i8*, i8** %8
%27 = call i64 @strlen(i8* %26)
%28 = icmp ne i64 0, %27
br i1 %28, label %29, label %33
29: ; preds = %15
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%31 = load i8*, i8** %9
%32 = call %struct.passwd* @getpwnam(i8* %31)
store %struct.passwd* %32, %struct.passwd** %10
br label %37
33: ; preds = %15
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* %6
%36 = call %struct.passwd* @getpwuid(i32 %35)
store %struct.passwd* %36, %struct.passwd** %10
br label %37
37: ; preds = %33, %29
%38 = load %struct.passwd*, %struct.passwd** %10
%39 = icmp ne %struct.passwd* null, %38
br i1 %39, label %40, label %55
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%42 = load %struct.passwd*, %struct.passwd** %10
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = load %struct.passwd*, %struct.passwd** %10
%46 = getelementptr inbounds %struct.passwd, %struct.passwd* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load %struct.passwd*, %struct.passwd** %10
%49 = getelementptr inbounds %struct.passwd, %struct.passwd* %48, i32 0, i32 2
%50 = load i32, i32* %49
%51 = load %struct.passwd*, %struct.passwd** %10
%52 = getelementptr inbounds %struct.passwd, %struct.passwd* %51, i32 0, i32 3
%53 = load i8*, i8** %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %44, i32 %47, i32 %50, i8* %53)
store i32 0, i32* %3
br label %58
55: ; preds = %37
%56 = load i8*, i8** %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %56)
store i32 1, i32* %3
br label %58
58: ; preds = %55, %40, %13
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i32, i32, i8* }
@.str = [34 x i8] c"Usage : passwd.out <UserName|uid>\00"
@.str.1 = [31 x i8] c"endptr: %s \09 uid:%d \09 nptr:%s\0A\00"
@.str.4 = [27 x i8] c"%12s \09 %10s \09 %10s \09 %10s\0A\00"
@.str.5 = [5 x i8] c"User\00"
@.str.6 = [4 x i8] c"uid\00"
@.str.7 = [4 x i8] c"gid\00"
@.str.8 = [4 x i8] c"pwd\00"
@.str.9 = [27 x i8] c"%12s \09 %10d \09 %10d \09 %10s\0A\00"
@.str.10 = [22 x i8] c"Cannot find user: %s\0A\00"
@str = [9 x i8] c"getpwuid\00"
@str.11 = [9 x i8] c"getpwnam\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %40
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
store i8* %5, i8** %4
%13 = call i32 @strtol(i8* %12, i8** %4, i32 10)
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %13, i8* %12)
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.11, i64 0, i64 0))
%20 = call %struct.passwd* @getpwnam(i8* %12)
br label %24
21: ; preds = %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%23 = call %struct.passwd* @getpwuid(i32 %13)
br label %24
24: ; preds = %21, %18
%25 = phi %struct.passwd* [ %20, %18 ], [ %23, %21 ]
%26 = icmp eq %struct.passwd* %25, null
br i1 %26, label %38, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 2
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 3
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %30, i32 %32, i32 %34, i8* %36)
br label %40
38: ; preds = %24
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %12)
br label %40
40: ; preds = %38, %27, %8
%41 = phi i32 [ 1, %8 ], [ 0, %27 ], [ 1, %38 ]
ret i32 %41
}