#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 /*<<< orphan*/, char const *);
int /*<<< orphan*/ getenv(char *);
char *strdup(char const *);
char *fi_process_path(const char *path) {
  if (path == NULL) {
    return NULL;
  }
  int home_dir_path = (path[0] == '~');
  if (home_dir_path) {
    return concat(getenv("HOME"), path + 1);
  }
  return strdup(path);
}


x86 assembly (clang, -O0):
<fi_process_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <fi_process_path+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <fi_process_path+0x74>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1197 <fi_process_path+0x67>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1040 <concat@plt>
mov    %rax,-0x8(%rbp)
jmp    11a4 <fi_process_path+0x74>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fi_process_path>:
push   %rbx
test   %rdi,%rdi
je     1159 <fi_process_path+0x29>
mov    %rdi,%rbx
cmpb   $0x7e,(%rdi)
jne    115d <fi_process_path+0x2d>
lea    0xebb(%rip),%rdi
call   1030 <getenv@plt>
add    $0x1,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1040 <concat@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <strdup@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
define i8* @fi_process_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %25
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 126
%14 = zext i1 %13 to i32
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i8* @concat(i32 %18, i8* %20)
store i8* %21, i8** %2
br label %25
22: ; preds = %8
%23 = load i8*, i8** %3
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %2
br label %25
25: ; preds = %22, %17, %7
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
define i8* @fi_process_path(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 126
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = tail call i8* @concat(i32 %7, i8* %8)
br label %12
10: ; preds = %3
%11 = tail call i8* @strdup(i8* %0)
br label %12
12: ; preds = %6, %10, %1
%13 = phi i8* [ null, %1 ], [ %9, %6 ], [ %11, %10 ]
ret i8* %13
}