#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*/ dirp;

/* Variables and functions */
scalar_t__ chdir(char *);
int /*<<< orphan*/ die(char *);
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
void get_dir(char *dir) {
  char *dirp[100];
  *dirp = dir;
  if (!snprintf(*dirp, sizeof(dirp), "%s%s", getenv("HOME"), "/notes/"))
    die("Couldn't create path to ~/notes directory.");
  if (chdir(*dirp) != 0)
    die("Couldn't change into ~/home directory.");
}


x86 assembly (clang, -O0):
<get_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x330(%rbp)
mov    -0x330(%rbp),%rax
mov    %rax,-0x338(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x338(%rbp),%rdi
mov    %rax,%rcx
mov    $0x320,%esi
lea    0xe76(%rip),%rdx
lea    0xe79(%rip),%r8
call   1050 <snprintf@plt>
cmp    $0x0,%eax
jne    11ab <get_dir+0x6b>
lea    0xe6c(%rip),%rdi
call   1060 <die@plt>
mov    -0x330(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     11cd <get_dir+0x8d>
lea    0xe75(%rip),%rdi
call   1060 <die@plt>
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir>:
push   %rbx
mov    %rdi,%rbx
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
lea    0xea9(%rip),%rdx
lea    0xeac(%rip),%r8
mov    %rbx,%rdi
mov    $0x320,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
test   %eax,%eax
jne    117e <get_dir+0x3e>
lea    0xe99(%rip),%rdi
call   1060 <die@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     1198 <get_dir+0x58>
lea    0xeab(%rip),%rdi
pop    %rbx
jmp    1060 <die@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [8 x i8] c"/notes/\00"
@.str.3 = [43 x i8] c"Couldn't create path to ~/notes directory.\00"
@.str.4 = [39 x i8] c"Couldn't change into ~/home directory.\00"
define void @get_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8*]
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 0
store i8* %4, i8** %5
%6 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 0
%7 = load i8*, i8** %6
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @snprintf(i8* %7, i32 800, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 0
%15 = load i8*, i8** %14
%16 = call i64 @chdir(i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @die(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [8 x i8] c"/notes/\00"
@.str.3 = [43 x i8] c"Couldn't create path to ~/notes directory.\00"
@.str.4 = [39 x i8] c"Couldn't change into ~/home directory.\00"
define void @get_dir(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @snprintf(i8* %0, i32 800, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i64 @chdir(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @die(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
ret void
}