#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 {
  int /*<<< orphan*/ pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ chdir(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void initdir(void) {
  struct passwd *pw;
  pw = getpwuid(getuid());
  if (pw == NULL) {
    fprintf(stderr, "Who are you?\n");
    exit(EXIT_FAILURE);
  }
  if (chdir(pw->pw_dir) != 0) {
    perror(pw->pw_dir);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<initdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a8 <initdir+0x48>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     11d6 <initdir+0x76>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <perror@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initdir>:
push   %rbx
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1185 <initdir+0x25>
mov    %rax,%rbx
mov    (%rax),%edi
call   1040 <chdir@plt>
test   %rax,%rax
jne    119c <initdir+0x3c>
pop    %rbx
ret
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11a3 <initdir+0x43>
mov    (%rbx),%edi
call   1070 <perror@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [14 x i8] c"Who are you?\0A\00"
@EXIT_FAILURE = global i32 0
define void @initdir() {
%1 = alloca %struct.passwd*
%2 = call i32 (...) @getuid()
%3 = call %struct.passwd* @getpwuid(i32 %2)
store %struct.passwd* %3, %struct.passwd** %1
%4 = load %struct.passwd*, %struct.passwd** %1
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load %struct.passwd*, %struct.passwd** %1
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @chdir(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load %struct.passwd*, %struct.passwd** %1
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @perror(i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [14 x i8] c"Who are you?\0A\00"
@EXIT_FAILURE = global i32 0
define void @initdir() {
%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 %9
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i64 @chdir(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i32, i32* %10
%16 = tail call i32 @perror(i32 %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %9
ret void
}