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

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
char *get_ifiction(char *, char *);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *get_dir(char *ifid, char *from) {
  char cwd[512];
  char buff[520];
  char *md;
  if (!ifid)
    return NULL;
  getcwd(cwd, 512);
  sprintf(buff, "%s.iFiction", ifid);
  chdir(from);
  md = get_ifiction(ifid, buff);
  chdir(cwd);
  return md;
}


x86 assembly (clang, -O0):
<get_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <get_dir+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11ca <get_dir+0x8a>
lea    -0x220(%rbp),%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe72(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1030 <get_ifiction@plt>
mov    %rax,-0x438(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x438(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
test   %rdi,%rdi
je     11a3 <get_dir+0x63>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
lea    0xe90(%rip),%rsi
lea    0x200(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1040 <chdir@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <get_ifiction@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <chdir@plt>
jmp    11a5 <get_dir+0x65>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s.iFiction\00"
define i8* @get_dir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca [520 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8* null, i8** %3
br label %26
12: ; preds = %2
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%14 = call i32 @getcwd(i8* %13, i32 512)
%15 = getelementptr inbounds [520 x i8], [520 x i8]* %7, i64 0, i64 0
%16 = load i8*, i8** %4
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %5
%19 = call i32 @chdir(i8* %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds [520 x i8], [520 x i8]* %7, i64 0, i64 0
%22 = call i8* @get_ifiction(i8* %20, i8* %21)
store i8* %22, i8** %8
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%24 = call i32 @chdir(i8* %23)
%25 = load i8*, i8** %8
store i8* %25, i8** %3
br label %26
26: ; preds = %12, %11
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s.iFiction\00"
define i8* @get_dir(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = alloca [520 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [520 x i8], [520 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %0, null
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = call i32 @getcwd(i8* %5, i32 512)
%10 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call i32 @chdir(i8* %1)
%12 = call i8* @get_ifiction(i8* %0, i8* %6)
%13 = call i32 @chdir(i8* %5)
br label %14
14: ; preds = %2, %8
%15 = phi i8* [ %12, %8 ], [ null, %2 ]
ret i8* %15
}