#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 *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ *strstr(char *, char *);
char *stripChoicePathOut(char *choicepath, char *path) {
  char dataset[512];
  char *ret = malloc(strlen(path) + 1);
  ret[0] = 0;
  strcpy(dataset, choicepath);
  if (strstr(dataset, ":"))
    *strstr(dataset, ":") = 0;
  else
    dataset[0] = 0;
  if (strstr(choicepath, ":")) {
    char t[512];
    strcpy(t, choicepath);
    *strstr(t, ":") = 0;
    choicepath += strlen(t) + 2;
  }
  if (strstr(path, choicepath)) {
    path += strlen(choicepath);
  }
  if (*path == '/')
    path++;
  strcat(ret, path);
  return ret;
}


x86 assembly (clang, -O0):
<stripChoicePathOut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11d5 <stripChoicePathOut+0x85>
lea    -0x210(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <strstr@plt>
movq   $0x0,(%rax)
jmp    11dc <stripChoicePathOut+0x8c>
movb   $0x0,-0x210(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1238 <stripChoicePathOut+0xe8>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1070 <strstr@plt>
movq   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1260 <stripChoicePathOut+0x110>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    127c <stripChoicePathOut+0x12c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x218(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x218(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripChoicePathOut>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b4 <stripChoicePathOut+0x54>
movq   $0x0,(%rax)
jmp    11b8 <stripChoicePathOut+0x58>
movb   $0x0,(%rsp)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1200 <stripChoicePathOut+0xa0>
lea    0x200(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
movq   $0x0,(%rax)
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
add    $0x2,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     121b <stripChoicePathOut+0xbb>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rax,%r15
xor    %esi,%esi
cmpb   $0x2f,(%r15)
sete   %sil
add    %r15,%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @stripChoicePathOut(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = add nsw i64 %6, 1
%8 = tail call i8* @malloc(i64 %7)
store i8 0, i8* %8
%9 = call i32 @strcpy(i8* %5, i8* %0)
%10 = call i8* @strchr(i8* %5, i32 58)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = bitcast i8* %10 to i64*
store i64 0, i64* %13
br label %15
14: ; preds = %2
store i8 0, i8* %5
br label %15
15: ; preds = %14, %12
%16 = call i8* @strchr(i8* dereferenceable(1) %0, i32 58)
%17 = icmp eq i8* %16, null
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%20 = call i32 @strcpy(i8* %19, i8* %0)
%21 = call i8* @strchr(i8* %19, i32 58)
%22 = bitcast i8* %21 to i64*
store i64 0, i64* %22
%23 = call i64 @strlen(i8* %19)
%24 = add nsw i64 %23, 2
%25 = getelementptr inbounds i8, i8* %0, i64 %24
br label %26
26: ; preds = %18, %15
%27 = phi i8* [ %25, %18 ], [ %0, %15 ]
%28 = call i64* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) %27)
%29 = icmp eq i64* %28, null
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = call i64 @strlen(i8* dereferenceable(1) %27)
%32 = getelementptr inbounds i8, i8* %1, i64 %31
br label %33
33: ; preds = %30, %26
%34 = phi i8* [ %32, %30 ], [ %1, %26 ]
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 47
%37 = zext i1 %36 to i64
%38 = getelementptr i8, i8* %34, i64 %37
%39 = call i32 @strcat(i8* %8, i8* %38)
ret i8* %8
}