#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*/ free(char *);
char *join_paths(char const *, char const *);
char *mountpoint_for_device(char const *);
char *parse_device_path(char *, char const *);
char *strchr(char const *, char);
char *strndup(char const *, int);
char *resolve_path(const char *path, const char *current_dev) {
  char *ret;
  const char *devpath, *sep;
  sep = strchr(path, ':');
  if (!sep) {
    devpath = mountpoint_for_device(current_dev);
    ret = join_paths(devpath, path);
  } else {
    char *tmp, *dev;
    tmp = strndup(path, sep - path);
    dev = parse_device_path(tmp, current_dev);
    devpath = mountpoint_for_device(dev);
    ret = join_paths(devpath, sep + 1);
    free(dev);
    free(tmp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<resolve_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b0 <resolve_path+0x50>
mov    -0x10(%rbp),%rdi
call   1070 <mountpoint_for_device@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <join_paths@plt>
mov    %rax,-0x18(%rbp)
jmp    120f <resolve_path+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <parse_device_path@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <mountpoint_for_device@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1080 <join_paths@plt>
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ce <resolve_path+0x6e>
mov    %rax,%rbx
mov    %ebx,%esi
sub    %r15d,%esi
mov    %r15,%rdi
call   1050 <strndup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <parse_device_path@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <mountpoint_for_device@plt>
add    $0x1,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1080 <join_paths@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1070 <mountpoint_for_device@plt>
mov    %rax,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <join_paths@plt>

LLVM IR (-O0):
define i8* @resolve_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 58)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i8* @mountpoint_for_device(i8* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i8*, i8** %3
%19 = call i8* @join_paths(i8* %17, i8* %18)
store i8* %19, i8** %5
br label %42
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load i8*, i8** %7
%23 = load i8*, i8** %3
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
%28 = call i8* @strndup(i8* %21, i32 %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = load i8*, i8** %4
%31 = call i8* @parse_device_path(i8* %29, i8* %30)
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = call i8* @mountpoint_for_device(i8* %32)
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = call i8* @join_paths(i8* %34, i8* %36)
store i8* %37, i8** %5
%38 = load i8*, i8** %9
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %20, %14
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
define i8* @resolve_path(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i8* @mountpoint_for_device(i8* %1)
%7 = tail call i8* @join_paths(i8* %6, i8* %0)
br label %20
8: ; preds = %2
%9 = ptrtoint i8* %3 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i8* @strndup(i8* %0, i32 %12)
%14 = tail call i8* @parse_device_path(i8* %13, i8* %1)
%15 = tail call i8* @mountpoint_for_device(i8* %14)
%16 = getelementptr inbounds i8, i8* %3, i64 1
%17 = tail call i8* @join_paths(i8* %15, i8* %16)
%18 = tail call i32 @free(i8* %14)
%19 = tail call i32 @free(i8* %13)
br label %20
20: ; preds = %8, %5
%21 = phi i8* [ %17, %8 ], [ %7, %5 ]
ret i8* %21
}