#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 *getenv(char *);
char *malloc(int);
char *realpath(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strstr(char *, char *);
char *get_full_path(char *name, bool is_path) {
  char *path = malloc(4096);
  if (path == NULL)
    return path;
  strcpy(path, name);
  char *home = getenv("HOME");
  if (home == NULL) {
    ;
  }
  char *home_pos;
  while ((home_pos = strstr(path, "~")) != NULL) {
    size_t n_home = strlen(home);
    strncpy(home_pos, home, n_home);
    home = name + (home_pos - path) + 1;
    strncpy(home_pos + n_home, home, strlen(home));
  }
  char *full_path = malloc(4096);
  if ((full_path = realpath(path, full_path)) == NULL)
    return full_path;
  if (is_path) {
    ;
  } else {
    ;
  }
  return full_path;
}


x86 assembly (clang, -O0):
<get_full_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a5 <get_full_path+0x35>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b1 <get_full_path+0x141>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
lea    0xe47(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d2 <get_full_path+0x62>
jmp    11d2 <get_full_path+0x62>
jmp    11d7 <get_full_path+0x67>
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     125f <get_full_path+0xef>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
jmp    11d7 <get_full_path+0x67>
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1070 <realpath@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1295 <get_full_path+0x125>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b1 <get_full_path+0x141>
cmpl   $0x0,-0x14(%rbp)
je     12a4 <get_full_path+0x134>
jmp    12a9 <get_full_path+0x139>
jmp    12a9 <get_full_path+0x139>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_full_path>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x1000,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     123e <get_full_path+0xce>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x7e,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1220 <get_full_path+0xb0>
mov    %rax,%r12
add    $0x1,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
mov    %r12,%rbx
sub    %r15,%rbx
add    %r14,%rbx
add    %r13,%r12
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
mov    %r15,%rdi
mov    $0x7e,%esi
call   1070 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11d0 <get_full_path+0x60>
mov    $0x1000,%edi
call   1090 <malloc@plt>
mov    %r15,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1080 <realpath@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"~\00"
define i8* @get_full_path(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = call i8* @malloc(i32 4096)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i8*, i8** %6
store i8* %15, i8** %3
br label %66
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %16
br label %24
24: ; preds = %23, %16
br label %25
25: ; preds = %29, %24
%26 = load i8*, i8** %6
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = call i64 @strlen(i8* %30)
store i64 %31, i64* %9
%32 = load i8*, i8** %8
%33 = load i8*, i8** %7
%34 = load i64, i64* %9
%35 = call i32 @strncpy(i8* %32, i8* %33, i64 %34)
%36 = load i8*, i8** %4
%37 = load i8*, i8** %8
%38 = load i8*, i8** %6
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = getelementptr inbounds i8, i8* %36, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %7
%44 = load i8*, i8** %8
%45 = load i64, i64* %9
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = load i8*, i8** %7
%48 = load i8*, i8** %7
%49 = call i64 @strlen(i8* %48)
%50 = call i32 @strncpy(i8* %46, i8* %47, i64 %49)
br label %25
51: ; preds = %25
%52 = call i8* @malloc(i32 4096)
store i8* %52, i8** %10
%53 = load i8*, i8** %6
%54 = load i8*, i8** %10
%55 = call i8* @realpath(i8* %53, i8* %54)
store i8* %55, i8** %10
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = load i8*, i8** %10
store i8* %58, i8** %3
br label %66
59: ; preds = %51
%60 = load i32, i32* %5
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
br label %64
63: ; preds = %59
br label %64
64: ; preds = %63, %62
%65 = load i8*, i8** %10
store i8* %65, i8** %3
br label %66
66: ; preds = %64, %57, %14
%67 = load i8*, i8** %3
ret i8* %67
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
define i8* @get_full_path(i8* %0, i32 %1) {
%3 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%4 = icmp eq i8* %3, null
br i1 %4, label %29, label %5
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %3, i8* %0)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8* @strchr(i8* %3, i32 126)
%9 = icmp eq i8* %8, null
br i1 %9, label %26, label %10
10: ; preds = %5
%11 = ptrtoint i8* %3 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 1
br label %13
13: ; preds = %10, %13
%14 = phi i8* [ %8, %10 ], [ %24, %13 ]
%15 = phi i8* [ %7, %10 ], [ %20, %13 ]
%16 = tail call i64 @strlen(i8* dereferenceable(1) %15)
%17 = tail call i32 @strncpy(i8* %14, i8* %15, i64 %16)
%18 = ptrtoint i8* %14 to i64
%19 = sub i64 %18, %11
%20 = getelementptr inbounds i8, i8* %12, i64 %19
%21 = getelementptr inbounds i8, i8* %14, i64 %16
%22 = tail call i64 @strlen(i8* %20)
%23 = tail call i32 @strncpy(i8* %21, i8* %20, i64 %22)
%24 = tail call i8* @strchr(i8* %3, i32 126)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %13
26: ; preds = %13, %5
%27 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%28 = tail call i8* @realpath(i8* %3, i8* %27)
br label %29
29: ; preds = %2, %26
%30 = phi i8* [ %28, %26 ], [ null, %2 ]
ret i8* %30
}