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

/* Variables and functions */
int /*<<< orphan*/ errno;
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *, char *, ...);
char *strerror(int /*<<< orphan*/);
int main() {
  if (getpwuid(getuid()) == NULL) {
    printf("errno: %s\n", strerror(errno));
    return 1;
  }
  uid_t id = 0;
  struct passwd *pwd;
  pwd = getpwuid(id);
  printf("name: %s\ndir: %s\n", pwd->pw_name, pwd->pw_dir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
cmp    $0x0,%rax
jne    1192 <main+0x52>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <main+0x89>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1174 <main+0x34>
xor    %edi,%edi
call   1030 <getpwuid@plt>
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1198 <main+0x58>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe77(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8* }
@.str = [11 x i8] c"errno: %s\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"name: %s\0Adir: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.passwd*
store i32 0, i32* %1
%4 = call i32 (...) @getuid()
%5 = call %struct.passwd* @getpwuid(i32 %4)
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 1, i32* %1
br label %21
11: ; preds = %0
store i32 0, i32* %2
%12 = load i32, i32* %2
%13 = call %struct.passwd* @getpwuid(i32 %12)
store %struct.passwd* %13, %struct.passwd** %3
%14 = load %struct.passwd*, %struct.passwd** %3
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %19)
store i32 0, i32* %1
br label %21
21: ; preds = %11, %7
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8* }
@.str = [11 x i8] c"errno: %s\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"name: %s\0Adir: %s\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getuid()
%2 = tail call %struct.passwd* @getpwuid(i32 %1)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i8* @strerror(i32 %5)
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %15
8: ; preds = %0
%9 = tail call %struct.passwd* @getpwuid(i32 0)
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %13)
br label %15
15: ; preds = %8, %4
%16 = phi i32 [ 1, %4 ], [ 0, %8 ]
ret i32 %16
}