#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 */
char *concat(int, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_relpath(char const *);
char *getenv(char *);
scalar_t__ is_absolute(char *);
int /*<<< orphan*/ mkpath(char *, int);
char *get_dep_path(const char *target) {
  char *root = getenv("REDO_ROOT");
  char *dep_path;
  char *reltarget = get_relpath(target);
  if (!reltarget)
    return NULL;
  char *redodir = is_absolute(reltarget) ? "/.redo/abs/" : "/.redo/rel/";
  dep_path = concat(3, root, redodir, reltarget);
  mkpath(dep_path, 0755);
  free(reltarget);
  return dep_path;
}


x86 assembly (clang, -O0):
<get_dep_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <get_relpath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a1 <get_dep_path+0x41>
movq   $0x0,-0x8(%rbp)
jmp    1200 <get_dep_path+0xa0>
mov    -0x28(%rbp),%rdi
call   1060 <is_absolute@plt>
mov    %rax,%rdx
lea    0xe62(%rip),%rax
lea    0xe4f(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x3,%edi
call   1050 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1ed,%esi
call   1070 <mkpath@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dep_path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <get_relpath@plt>
test   %rax,%rax
je     11cd <get_dep_path+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <is_absolute@plt>
test   %rax,%rax
lea    0xe7e(%rip),%rax
lea    0xe6b(%rip),%rdx
cmove  %rax,%rdx
mov    $0x3,%edi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1050 <concat@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1ed,%esi
call   1070 <mkpath@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
jmp    11d0 <get_dep_path+0x70>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"REDO_ROOT\00"
@.str.1 = [12 x i8] c"/.redo/abs/\00"
@.str.2 = [12 x i8] c"/.redo/rel/\00"
define i8* @get_dep_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %3
%10 = call i8* @get_relpath(i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %1
store i8* null, i8** %2
br label %29
14: ; preds = %1
%15 = load i8*, i8** %6
%16 = call i64 @is_absolute(i8* %15)
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0)
store i8* %19, i8** %7
%20 = load i8*, i8** %4
%21 = load i8*, i8** %7
%22 = load i8*, i8** %6
%23 = call i8* @concat(i32 3, i8* %20, i8* %21, i8* %22)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = call i32 @mkpath(i8* %24, i32 493)
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %5
store i8* %28, i8** %2
br label %29
29: ; preds = %14, %13
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [10 x i8] c"REDO_ROOT\00"
@.str.1 = [12 x i8] c"/.redo/abs/\00"
@.str.2 = [12 x i8] c"/.redo/rel/\00"
define i8* @get_dep_path(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @get_relpath(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = tail call i64 @is_absolute(i8* %3)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i8* @concat(i32 3, i8* %2, i8* %8, i8* %3)
%10 = tail call i32 @mkpath(i8* %9, i32 493)
%11 = tail call i32 @free(i8* %3)
br label %12
12: ; preds = %1, %5
%13 = phi i8* [ %9, %5 ], [ null, %1 ]
ret i8* %13
}