#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 spwd {
  char *sp_namp;
  char *sp_pwdp;
};
struct passwd {
  char *pw_name;
  char *pw_passwd;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
  int pw_uid;
  int pw_gid;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct passwd *getpwent();
struct passwd *getpwnam(char *);
struct spwd *getspent();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct passwd *pwd;
  struct spwd *spw;
  if (argc < 2) {
    printf("Usage: %s username\n", argv[0]);
    exit(1);
  }
  pwd = getpwnam(argv[1]);
  if (pwd == NULL) {
    perror("get user information error");
    exit(1);
  }
  printf("pw_name: %s\n", pwd->pw_name);
  printf("pw_passwd: %s\n", pwd->pw_passwd);
  printf("pw_gecos: %s\n", pwd->pw_gecos);
  printf("pw_dir: %s\n", pwd->pw_dir);
  printf("pw_shell: %s\n", pwd->pw_shell);
  printf("pw_uid: %d\n", pwd->pw_uid);
  printf("pw_gid: %d\n", pwd->pw_gid);
  printf("===================================\n");
  while ((pwd = getpwent()) != NULL) {
    printf("%20s : %32s : %32s : %6d : %6d\n", pwd->pw_name, pwd->pw_dir,
           pwd->pw_shell, pwd->pw_uid, pwd->pw_gid);
  }
  printf("shadow===================================\n");
  while ((spw = getspent()) != NULL) {
    printf("[%s] : [%s]\n", spw->sp_namp, spw->sp_pwdp);
  }
  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)
jge    119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <main+0x71>
lea    0xe52(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x2c(%rax),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12c5 <main+0x165>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x2c(%rax),%r9d
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1276 <main+0x116>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getspent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     130a <main+0x1aa>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d3 <main+0x173>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jle    12a1 <main+0x131>
mov    0x8(%rsi),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     12bc <main+0x14c>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%rsi
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rbx),%esi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c(%rbx),%esi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getpwent@plt>
test   %rax,%rax
je     1259 <main+0xe9>
lea    0xe62(%rip),%rbx
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    0x18(%rax),%rdx
mov    0x20(%rax),%rcx
mov    0x28(%rax),%r8d
mov    0x2c(%rax),%r9d
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getpwent@plt>
test   %rax,%rax
jne    1230 <main+0xc0>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <getspent@plt>
test   %rax,%rax
je     129d <main+0x12d>
lea    0xe33(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <getspent@plt>
test   %rax,%rax
jne    1280 <main+0x110>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xd55(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd51(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8*, i32, i32 }
%struct.spwd = type { i8*, i8* }
@.str = [20 x i8] c"Usage: %s username\0A\00"
@.str.1 = [27 x i8] c"get user information error\00"
@.str.2 = [13 x i8] c"pw_name: %s\0A\00"
@.str.3 = [15 x i8] c"pw_passwd: %s\0A\00"
@.str.4 = [14 x i8] c"pw_gecos: %s\0A\00"
@.str.5 = [12 x i8] c"pw_dir: %s\0A\00"
@.str.6 = [14 x i8] c"pw_shell: %s\0A\00"
@.str.7 = [12 x i8] c"pw_uid: %d\0A\00"
@.str.8 = [12 x i8] c"pw_gid: %d\0A\00"
@.str.9 = [37 x i8] c"===================================\0A\00"
@.str.10 = [32 x i8] c"%20s : %32s : %32s : %6d : %6d\0A\00"
@.str.11 = [43 x i8] c"shadow===================================\0A\00"
@.str.12 = [13 x i8] c"[%s] : [%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
%7 = alloca %struct.spwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call %struct.passwd* @getpwnam(i8* %19)
store %struct.passwd* %20, %struct.passwd** %6
%21 = load %struct.passwd*, %struct.passwd** %6
%22 = icmp eq %struct.passwd* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = load %struct.passwd*, %struct.passwd** %6
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load %struct.passwd*, %struct.passwd** %6
%32 = getelementptr inbounds %struct.passwd, %struct.passwd* %31, i32 0, i32 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load %struct.passwd*, %struct.passwd** %6
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 2
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = load %struct.passwd*, %struct.passwd** %6
%40 = getelementptr inbounds %struct.passwd, %struct.passwd* %39, i32 0, i32 3
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = load %struct.passwd*, %struct.passwd** %6
%44 = getelementptr inbounds %struct.passwd, %struct.passwd* %43, i32 0, i32 4
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %45)
%47 = load %struct.passwd*, %struct.passwd** %6
%48 = getelementptr inbounds %struct.passwd, %struct.passwd* %47, i32 0, i32 5
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = load %struct.passwd*, %struct.passwd** %6
%52 = getelementptr inbounds %struct.passwd, %struct.passwd* %51, i32 0, i32 6
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0))
br label %56
56: ; preds = %59, %26
%57 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %57, %struct.passwd** %6
%58 = icmp ne %struct.passwd* %57, null
br i1 %58, label %59, label %76
59: ; preds = %56
%60 = load %struct.passwd*, %struct.passwd** %6
%61 = getelementptr inbounds %struct.passwd, %struct.passwd* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = load %struct.passwd*, %struct.passwd** %6
%64 = getelementptr inbounds %struct.passwd, %struct.passwd* %63, i32 0, i32 3
%65 = load i8*, i8** %64
%66 = load %struct.passwd*, %struct.passwd** %6
%67 = getelementptr inbounds %struct.passwd, %struct.passwd* %66, i32 0, i32 4
%68 = load i8*, i8** %67
%69 = load %struct.passwd*, %struct.passwd** %6
%70 = getelementptr inbounds %struct.passwd, %struct.passwd* %69, i32 0, i32 5
%71 = load i32, i32* %70
%72 = load %struct.passwd*, %struct.passwd** %6
%73 = getelementptr inbounds %struct.passwd, %struct.passwd* %72, i32 0, i32 6
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %62, i8* %65, i8* %68, i32 %71, i32 %74)
br label %56
76: ; preds = %56
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0))
br label %78
78: ; preds = %81, %76
%79 = call %struct.spwd* (...) @getspent()
store %struct.spwd* %79, %struct.spwd** %7
%80 = icmp ne %struct.spwd* %79, null
br i1 %80, label %81, label %89
81: ; preds = %78
%82 = load %struct.spwd*, %struct.spwd** %7
%83 = getelementptr inbounds %struct.spwd, %struct.spwd* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = load %struct.spwd*, %struct.spwd** %7
%86 = getelementptr inbounds %struct.spwd, %struct.spwd* %85, i32 0, i32 1
%87 = load i8*, i8** %86
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i8* %84, i8* %87)
br label %78
89: ; preds = %78
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8*, i32, i32 }
%struct.spwd = type { i8*, i8* }
@.str = [20 x i8] c"Usage: %s username\0A\00"
@.str.1 = [27 x i8] c"get user information error\00"
@.str.2 = [13 x i8] c"pw_name: %s\0A\00"
@.str.3 = [15 x i8] c"pw_passwd: %s\0A\00"
@.str.4 = [14 x i8] c"pw_gecos: %s\0A\00"
@.str.5 = [12 x i8] c"pw_dir: %s\0A\00"
@.str.6 = [14 x i8] c"pw_shell: %s\0A\00"
@.str.7 = [12 x i8] c"pw_uid: %d\0A\00"
@.str.8 = [12 x i8] c"pw_gid: %d\0A\00"
@.str.10 = [32 x i8] c"%20s : %32s : %32s : %6d : %6d\0A\00"
@.str.12 = [13 x i8] c"[%s] : [%s]\0A\00"
@str = [36 x i8] c"===================================\00"
@str.13 = [42 x i8] c"shadow===================================\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call %struct.passwd* @getpwnam(i8* %10)
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 1
%21 = load i8*, i8** %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 2
%24 = load i8*, i8** %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 3
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 4
%30 = load i8*, i8** %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 5
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 6
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %36)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%39 = tail call %struct.passwd* (...) @getpwent()
%40 = icmp eq %struct.passwd* %39, null
br i1 %40, label %56, label %41
41: ; preds = %16, %41
%42 = phi %struct.passwd* [ %54, %41 ], [ %39, %16 ]
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 0
%44 = load i8*, i8** %43
%45 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 3
%46 = load i8*, i8** %45
%47 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 4
%48 = load i8*, i8** %47
%49 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 5
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 6
%52 = load i32, i32* %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %44, i8* %46, i8* %48, i32 %50, i32 %52)
%54 = tail call %struct.passwd* (...) @getpwent()
%55 = icmp eq %struct.passwd* %54, null
br i1 %55, label %56, label %41
56: ; preds = %41, %16
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.13, i64 0, i64 0))
%58 = tail call %struct.spwd* (...) @getspent()
%59 = icmp eq %struct.spwd* %58, null
br i1 %59, label %69, label %60
60: ; preds = %56, %60
%61 = phi %struct.spwd* [ %67, %60 ], [ %58, %56 ]
%62 = getelementptr inbounds %struct.spwd, %struct.spwd* %61, i64 0, i32 0
%63 = load i8*, i8** %62
%64 = getelementptr inbounds %struct.spwd, %struct.spwd* %61, i64 0, i32 1
%65 = load i8*, i8** %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i8* %63, i8* %65)
%67 = tail call %struct.spwd* (...) @getspent()
%68 = icmp eq %struct.spwd* %67, null
br i1 %68, label %69, label %60
69: ; preds = %60, %56
ret i32 0
}