#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;
  char *pw_dir;
};

/* Variables and functions */
char *getlogin();
int getpid();
int getppid();
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  printf("pid = %d, ppid = %d\n", getpid(), getppid());
  char *login = NULL;
  struct passwd *pwd = NULL;
  login = getlogin();
  pwd = getpwnam("lennon");
  printf("login:%s\tpw_name:%s\tpw_passwd:%s\tpw_dir:%s\n", login, pwd->pw_name,
         pwd->pw_passwd, pwd->pw_dir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getlogin@plt>
mov    %rax,-0x10(%rbp)
lea    0xe70(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getlogin@plt>
mov    %rax,%rbx
lea    0xe91(%rip),%rdi
call   1050 <getpwnam@plt>
mov    (%rax),%rdx
mov    0x8(%rax),%rcx
mov    0x10(%rax),%r8
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8* }
@.str = [21 x i8] c"pid = %d, ppid = %d\0A\00"
@.str.1 = [7 x i8] c"lennon\00"
@.str.2 = [44 x i8] c"login:%s\09pw_name:%s\09pw_passwd:%s\09pw_dir:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.passwd*
store i32 0, i32* %1
%4 = call i32 (...) @getpid()
%5 = call i32 (...) @getppid()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
store i8* null, i8** %2
store %struct.passwd* null, %struct.passwd** %3
%7 = call i8* (...) @getlogin()
store i8* %7, i8** %2
%8 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store %struct.passwd* %8, %struct.passwd** %3
%9 = load i8*, i8** %2
%10 = load %struct.passwd*, %struct.passwd** %3
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = load %struct.passwd*, %struct.passwd** %3
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 1
%15 = load i8*, i8** %14
%16 = load %struct.passwd*, %struct.passwd** %3
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i32 0, i32 2
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %12, i8* %15, i8* %18)
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8* }
@.str = [21 x i8] c"pid = %d, ppid = %d\0A\00"
@.str.1 = [7 x i8] c"lennon\00"
@.str.2 = [44 x i8] c"login:%s\09pw_name:%s\09pw_passwd:%s\09pw_dir:%s\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (...) @getppid()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%4 = tail call i8* (...) @getlogin()
%5 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 2
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %7, i8* %9, i8* %11)
ret i32 0
}