#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 MAXPATHLEN;
int /*<<< orphan*/ am_free(char *);
char *am_strdup(char const *);
int /*<<< orphan*/ assert(int);
char *get_home_folder();
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char *resolve_path(const char *path) {
  char new_dir[MAXPATHLEN];
  char *homedir = NULL;
  if (path && strlen(path) > 2) {
    if (path[0] == '~' && path[1] == '/') {
      homedir = get_home_folder();
      if (homedir) {
        assert((strlen(homedir) + strlen(path)) < MAXPATHLEN);
        strcpy(new_dir, homedir);
        strcat(new_dir, ++path);
        am_free(homedir);
        return am_strdup(new_dir);
      }
    }
    return am_strdup(path);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<resolve_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1298 <resolve_path+0x128>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jle    1298 <resolve_path+0x128>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    127f <resolve_path+0x10f>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    127f <resolve_path+0x10f>
mov    $0x0,%al
call   1030 <get_home_folder@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     127a <resolve_path+0x10a>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    %rsi,-0x10(%rbp)
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1080 <am_free@plt>
mov    -0x38(%rbp),%rdi
call   1050 <am_strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    12a7 <resolve_path+0x137>
jmp    127f <resolve_path+0x10f>
mov    -0x10(%rbp),%rdi
call   1050 <am_strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    12a7 <resolve_path+0x137>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e63(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
test   %rdi,%rdi
je     121c <resolve_path+0xac>
mov    %rdi,%rbx
call   1060 <strlen@plt>
cmp    $0x3,%eax
jl     121c <resolve_path+0xac>
cmpb   $0x7e,(%rbx)
jne    122d <resolve_path+0xbd>
cmpb   $0x2f,0x1(%rbx)
jne    122d <resolve_path+0xbd>
xor    %eax,%eax
call   1030 <get_home_folder@plt>
test   %rax,%rax
je     122d <resolve_path+0xbd>
mov    %rax,%r15
lea    0x1(%rbx),%rax
mov    %rax,-0x30(%rbp)
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r13d,%eax
xor    %edi,%edi
cmp    (%r12),%eax
setl   %dil
call   1070 <assert@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    -0x30(%rbp),%rsi
call   1090 <strcat@plt>
mov    %r15,%rdi
call   1080 <am_free@plt>
mov    %r14,%rdi
call   1050 <am_strdup@plt>
jmp    121e <resolve_path+0xae>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <am_strdup@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
define i8* @resolve_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @MAXPATHLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
store i8* null, i8** %6
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %56
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %56
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 126
br i1 %23, label %24, label %53
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %30, label %53
30: ; preds = %24
%31 = call i8* (...) @get_home_folder()
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load i8*, i8** %6
%36 = call i32 @strlen(i8* %35)
%37 = load i8*, i8** %3
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %36, %38
%40 = load i32, i32* @MAXPATHLEN
%41 = icmp slt i32 %39, %40
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8*, i8** %6
%45 = call i32 @strcpy(i8* %11, i8* %44)
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %3
%48 = call i32 @strcat(i8* %11, i8* %47)
%49 = load i8*, i8** %6
%50 = call i32 @am_free(i8* %49)
%51 = call i8* @am_strdup(i8* %11)
store i8* %51, i8** %2
store i32 1, i32* %7
br label %57
52: ; preds = %30
br label %53
53: ; preds = %52, %24, %18
%54 = load i8*, i8** %3
%55 = call i8* @am_strdup(i8* %54)
store i8* %55, i8** %2
store i32 1, i32* %7
br label %57
56: ; preds = %14, %1
store i8* null, i8** %2
store i32 1, i32* %7
br label %57
57: ; preds = %56, %53, %34
%58 = load i8*, i8** %4
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
define i8* @resolve_path(i8* %0) {
%2 = load i32, i32* @MAXPATHLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp eq i8* %0, null
br i1 %5, label %33, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 2
br i1 %8, label %9, label %33
9: ; preds = %6
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 126
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = tail call i8* (...) @get_home_folder()
%18 = icmp eq i8* %17, null
br i1 %18, label %31, label %19
19: ; preds = %16
%20 = tail call i32 @strlen(i8* %17)
%21 = tail call i32 @strlen(i8* %0)
%22 = add nsw i32 %21, %20
%23 = load i32, i32* @MAXPATHLEN
%24 = icmp slt i32 %22, %23
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = call i32 @strcpy(i8* %4, i8* %17)
%28 = call i32 @strcat(i8* %4, i8* %13)
%29 = call i32 @am_free(i8* %17)
%30 = call i8* @am_strdup(i8* %4)
br label %33
31: ; preds = %16, %12, %9
%32 = tail call i8* @am_strdup(i8* %0)
br label %33
33: ; preds = %1, %6, %31, %19
%34 = phi i8* [ %30, %19 ], [ %32, %31 ], [ null, %6 ], [ null, %1 ]
ret i8* %34
}