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

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct passwd *my_getpwnam(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
void print_passwd(const char *name) {
  errno = 0;
  struct passwd *pwd;
  pwd = my_getpwnam(name);
  if (pwd != NULL) {
    printf("User: %s\n", pwd->pw_name);
    printf("Home directory: %s\n", pwd->pw_dir);
    printf("Default shell: %s\n", pwd->pw_shell);
  } else {
    fprintf(stderr, "getpwnam error for %s", name);
    if (errno != 0) {
      perror("Error info: ");
    }
    putchar('\n');
  }
}


x86 assembly (clang, -O0):
<print_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <my_getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c2 <print_passwd+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
jmp    1202 <print_passwd+0xb2>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2df6(%rip),%rax
cmpq   $0x0,(%rax)
je     11f8 <print_passwd+0xa8>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_passwd>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e79(%rip),%r15
movq   $0x0,(%r15)
call   1050 <my_getpwnam@plt>
test   %rax,%rax
je     11a7 <print_passwd+0x57>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xe81(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
cmpq   $0x0,(%r15)
jne    11d4 <print_passwd+0x84>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
lea    0xe6c(%rip),%rdi
call   1070 <perror@plt>
jmp    11c5 <print_passwd+0x75>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8* }
@errno = global i64 0
@.str = [10 x i8] c"User: %s\0A\00"
@.str.1 = [20 x i8] c"Home directory: %s\0A\00"
@.str.2 = [19 x i8] c"Default shell: %s\0A\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"getpwnam error for %s\00"
@.str.4 = [13 x i8] c"Error info: \00"
define void @print_passwd(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call %struct.passwd* @my_getpwnam(i8* %4)
store %struct.passwd* %5, %struct.passwd** %3
%6 = load %struct.passwd*, %struct.passwd** %3
%7 = icmp ne %struct.passwd* %6, null
br i1 %7, label %8, label %21
8: ; preds = %1
%9 = load %struct.passwd*, %struct.passwd** %3
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 0
%11 = load i8*, i8** %10
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), 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 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 2
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %31
21: ; preds = %1
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i64, i64* @errno
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = call i32 @putchar(i8 signext 10)
br label %31
31: ; preds = %29, %8
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8* }
@errno = global i64 0
@.str = [10 x i8] c"User: %s\0A\00"
@.str.1 = [20 x i8] c"Home directory: %s\0A\00"
@.str.2 = [19 x i8] c"Default shell: %s\0A\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"getpwnam error for %s\00"
@.str.4 = [13 x i8] c"Error info: \00"
define void @print_passwd(i8* %0) {
store i64 0, i64* @errno
%2 = tail call %struct.passwd* @my_getpwnam(i8* %0)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 1
%9 = load i8*, i8** %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 2
%12 = load i8*, i8** %11
%13 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %23
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = tail call i32 @putchar(i8 signext 10)
br label %23
23: ; preds = %21, %4
ret void
}