#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 uid_t;
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 atoi(char const *);
int /*<<< orphan*/ exit(int);
struct passwd *getpwuid(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  uid_t uid = 0;
  struct passwd *ptr;
  if (argc != 2) {
    printf("wrong argument\n");
    exit(-1);
  }
  uid = atoi(argv[1]);
  if ((ptr = getpwuid(uid)) != NULL) {
    printf("name = %s\tpasswd = %s\tuid = %d, gid = %d\n", ptr->pw_name,
           ptr->pw_passwd, ptr->pw_uid, ptr->pw_gid);
    printf("comment = %s\tdir = %s\tshell = %s\n", ptr->pw_gecos, ptr->pw_dir,
           ptr->pw_shell);
  } else {
    printf("there is no uid %d\n", uid);
    exit(-1);
  }
  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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117f <main+0x3f>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fc <main+0xbc>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%r8d
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x20(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x28(%rax),%rcx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1217 <main+0xd7>
mov    -0x14(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11b1 <main+0x61>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     11c7 <main+0x77>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%ecx
mov    0x14(%rax),%r8d
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%rsi
mov    0x20(%rbx),%rdx
mov    0x28(%rbx),%rcx
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe7e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@.str = [16 x i8] c"wrong argument\0A\00"
@.str.1 = [42 x i8] c"name = %s\09passwd = %s\09uid = %d, gid = %d\0A\00"
@.str.2 = [34 x i8] c"comment = %s\09dir = %s\09shell = %s\0A\00"
@.str.3 = [20 x i8] c"there is no uid %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call %struct.passwd* @getpwuid(i32 %18)
store %struct.passwd* %19, %struct.passwd** %7
%20 = icmp ne %struct.passwd* %19, null
br i1 %20, label %21, label %45
21: ; preds = %13
%22 = load %struct.passwd*, %struct.passwd** %7
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = load %struct.passwd*, %struct.passwd** %7
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i32 0, i32 1
%27 = load i8*, i8** %26
%28 = load %struct.passwd*, %struct.passwd** %7
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %28, i32 0, i32 2
%30 = load i32, i32* %29
%31 = load %struct.passwd*, %struct.passwd** %7
%32 = getelementptr inbounds %struct.passwd, %struct.passwd* %31, i32 0, i32 3
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %27, i32 %30, i32 %33)
%35 = load %struct.passwd*, %struct.passwd** %7
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 4
%37 = load i8*, i8** %36
%38 = load %struct.passwd*, %struct.passwd** %7
%39 = getelementptr inbounds %struct.passwd, %struct.passwd* %38, i32 0, i32 5
%40 = load i8*, i8** %39
%41 = load %struct.passwd*, %struct.passwd** %7
%42 = getelementptr inbounds %struct.passwd, %struct.passwd* %41, i32 0, i32 6
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %40, i8* %43)
br label %49
45: ; preds = %13
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@.str.1 = [42 x i8] c"name = %s\09passwd = %s\09uid = %d, gid = %d\0A\00"
@.str.2 = [34 x i8] c"comment = %s\09dir = %s\09shell = %s\0A\00"
@.str.3 = [20 x i8] c"there is no uid %d\0A\00"
@str = [15 x i8] c"wrong argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = tail call %struct.passwd* @getpwuid(i32 %10)
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %30, label %13
13: ; preds = %7
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 2
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 3
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17, i32 %19, i32 %21)
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 4
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 5
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 6
%28 = load i8*, i8** %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %26, i8* %28)
ret i32 0
30: ; preds = %7
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%32 = tail call i32 @exit(i32 -1)
unreachable
}