#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 *);
int /*<<< orphan*/ printf(char *);
char *resolve_addrs(char *);
int safe_cat(char **, int *, int, char *);
char *strdup(char const *);
int strlen(char *);
char *strstr(char *, char *);
char *mount_resolve_src(const char *orig_str) {
  int len, pos;
  char *mount_path;
  char *src;
  char *buf = strdup(orig_str);
  mount_path = strstr(buf, ":/");
  if (!mount_path) {
    printf("source mount path was not specified\n");
    free(buf);
    return NULL;
  }
  if (mount_path == buf) {
    printf("server address expected\n");
    free(buf);
    return NULL;
  }
  *mount_path = '\0';
  mount_path++;
  if (!*mount_path) {
    printf("incorrect source mount path\n");
    free(buf);
    return NULL;
  }
  src = resolve_addrs(buf);
  if (!src)
    return NULL;
  len = strlen(src);
  pos = safe_cat(&src, &len, len, ":");
  safe_cat(&src, &len, pos, mount_path);
  free(buf);
  return src;
}


x86 assembly (clang, -O0):
<mount_resolve_src>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ca <mount_resolve_src+0x5a>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ac <mount_resolve_src+0x13c>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    11fa <mount_resolve_src+0x8a>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ac <mount_resolve_src+0x13c>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    123c <mount_resolve_src+0xcc>
lea    0xe20(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ac <mount_resolve_src+0x13c>
mov    -0x30(%rbp),%rdi
call   1080 <resolve_addrs@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1261 <mount_resolve_src+0xf1>
movq   $0x0,-0x8(%rbp)
jmp    12ac <mount_resolve_src+0x13c>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    0xddf(%rip),%rcx
call   1060 <safe_cat@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <safe_cat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mount_resolve_src>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
call   1070 <strdup@plt>
mov    %rax,%r14
lea    0xe76(%rip),%rsi
mov    %rax,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1207 <mount_resolve_src+0x97>
mov    %rax,%rbx
cmp    %r14,%rax
je     1210 <mount_resolve_src+0xa0>
movb   $0x0,(%rbx)
cmpb   $0x0,0x1(%rbx)
je     1219 <mount_resolve_src+0xa9>
mov    %r14,%rdi
call   1080 <resolve_addrs@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     122d <mount_resolve_src+0xbd>
add    $0x1,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,0xc(%rsp)
lea    0xe32(%rip),%rcx
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <safe_cat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1060 <safe_cat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rax
jmp    122f <mount_resolve_src+0xbf>
lea    0xdf7(%rip),%rdi
jmp    1220 <mount_resolve_src+0xb0>
lea    0xe2e(%rip),%rdi
jmp    1220 <mount_resolve_src+0xb0>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c":/\00"
@.str.1 = [37 x i8] c"source mount path was not specified\0A\00"
@.str.2 = [25 x i8] c"server address expected\0A\00"
@.str.3 = [29 x i8] c"incorrect source mount path\0A\00"
@.str.4 = [2 x i8] c":\00"
define i8* @mount_resolve_src(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %8
%18 = call i32 @free(i8* %17)
store i8* null, i8** %2
br label %55
19: ; preds = %1
%20 = load i8*, i8** %6
%21 = load i8*, i8** %8
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%25 = load i8*, i8** %8
%26 = call i32 @free(i8* %25)
store i8* null, i8** %2
br label %55
27: ; preds = %19
%28 = load i8*, i8** %6
store i8 0, i8* %28
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
store i8* null, i8** %2
br label %55
38: ; preds = %27
%39 = load i8*, i8** %8
%40 = call i8* @resolve_addrs(i8* %39)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %38
store i8* null, i8** %2
br label %55
44: ; preds = %38
%45 = load i8*, i8** %7
%46 = call i32 @strlen(i8* %45)
store i32 %46, i32* %4
%47 = load i32, i32* %4
%48 = call i32 @safe_cat(i8** %7, i32* %4, i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 %48, i32* %5
%49 = load i32, i32* %5
%50 = load i8*, i8** %6
%51 = call i32 @safe_cat(i8** %7, i32* %4, i32 %49, i8* %50)
%52 = load i8*, i8** %8
%53 = call i32 @free(i8* %52)
%54 = load i8*, i8** %7
store i8* %54, i8** %2
br label %55
55: ; preds = %44, %43, %34, %23, %15
%56 = load i8*, i8** %2
ret i8* %56
}

LLVM IR (-O2):
@.str = [3 x i8] c":/\00"
@.str.4 = [2 x i8] c":\00"
@str = [36 x i8] c"source mount path was not specified\00"
@str.5 = [28 x i8] c"incorrect source mount path\00"
@str.6 = [24 x i8] c"server address expected\00"
define i8* @mount_resolve_src(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = tail call i8* @strdup(i8* %0)
%7 = tail call i8* @strstr(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @free(i8* %6)
br label %33
12: ; preds = %1
%13 = icmp eq i8* %7, %6
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
%16 = tail call i32 @free(i8* %6)
br label %33
17: ; preds = %12
store i8 0, i8* %7
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
%23 = tail call i32 @free(i8* %6)
br label %33
24: ; preds = %17
%25 = tail call i8* @resolve_addrs(i8* %6)
store i8* %25, i8** %3
%26 = icmp eq i8* %25, null
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = tail call i32 @strlen(i8* %25)
store i32 %28, i32* %2
%29 = call i32 @safe_cat(i8** %3, i32* %2, i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @safe_cat(i8** %3, i32* %2, i32 %29, i8* %18)
%31 = call i32 @free(i8* %6)
%32 = load i8*, i8** %3
br label %33
33: ; preds = %24, %27, %21, %14, %9
%34 = phi i8* [ null, %14 ], [ %32, %27 ], [ null, %21 ], [ null, %9 ], [ null, %24 ]
ret i8* %34
}