#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*/ cctools_debug(long long, char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int sscanf(char *, char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void clean_up_path(char *path) {
  char temp[1024];
  char prefix[1024];
  char rest[1024];
  while (1) {
    if (!strncmp(path, "buffer:", 7)) {
      strcpy(temp, path + 7);
      strcpy(path, temp);
    } else {
      if (sscanf(path, "%[^:/]:%s", prefix, rest) == 2) {
        int plen = strlen(prefix);
        if (!strcmp(prefix, "remote")) {
          strcpy(prefix, "chirp/CONDOR");
        }
        sprintf(temp, "/%s/%s", prefix, path + plen + 2);
        cctools_debug((1LL << 7), "%s -> %s", path, temp);
        strcpy(path, temp);
      } else {
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<clean_up_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c6 <clean_up_path+0x56>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x7,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1295 <clean_up_path+0x125>
mov    -0x8(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    -0xc10(%rbp),%rcx
lea    0xe29(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x2,%eax
jne    128b <clean_up_path+0x11b>
lea    -0x810(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc14(%rbp)
lea    -0x810(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    122e <clean_up_path+0xbe>
lea    -0x810(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rdx
mov    -0x8(%rbp),%rcx
movslq -0xc14(%rbp),%rax
add    %rax,%rcx
add    $0x2,%rcx
lea    0xdd1(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdx
lea    -0x410(%rbp),%rcx
mov    $0x80,%edi
lea    0xdbc(%rip),%rsi
call   1070 <cctools_debug@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1290 <clean_up_path+0x120>
jmp    129a <clean_up_path+0x12a>
jmp    1295 <clean_up_path+0x125>
jmp    117f <clean_up_path+0xf>
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_up_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc18,%rsp
mov    %rdi,%rbx
lea    0x7(%rdi),%rax
mov    %rax,0x8(%rsp)
lea    0x2(%rdi),%r14
lea    0xe78(%rip),%r15
lea    0x810(%rsp),%r12
lea    0x10(%rsp),%rbp
jmp    11da <clean_up_path+0x7a>
nopw   0x0(%rax,%rax,1)
movslq %r13d,%rcx
add    %r14,%rcx
mov    %r12,%rdi
lea    0xe76(%rip),%rsi
mov    %rbp,%rdx
call   1080 <sprintf@plt>
mov    $0x80,%edi
lea    0xe69(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1060 <cctools_debug@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1250 <clean_up_path+0xf0>
mov    %rbx,%rdi
lea    0xe10(%rip),%rsi
mov    %rbp,%rdx
lea    0x410(%rsp),%rcx
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    1262 <clean_up_path+0x102>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%eax
mov    $0x6f6d6572,%ecx
xor    %ecx,%eax
mov    0x13(%rsp),%ecx
mov    $0x65746f,%edx
xor    %edx,%ecx
or     %eax,%ecx
jne    11a0 <clean_up_path+0x40>
mov    %rbp,%rdi
lea    0xdd9(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11a0 <clean_up_path+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
call   1040 <strcpy@plt>
jmp    11cf <clean_up_path+0x6f>
add    $0xc18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"buffer:\00"
@.str.1 = [10 x i8] c"%[^:/]:%s\00"
@.str.2 = [7 x i8] c"remote\00"
@.str.3 = [13 x i8] c"chirp/CONDOR\00"
@.str.4 = [7 x i8] c"/%s/%s\00"
@.str.5 = [9 x i8] c"%s -> %s\00"
define void @clean_up_path(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
store i8* %0, i8** %2
br label %7
7: ; preds = %1, %51
%8 = load i8*, i8** %2
%9 = call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = icmp ne i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 7
%15 = call i32 @strcpy(i8* %12, i8* %14)
%16 = load i8*, i8** %2
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = call i32 @strcpy(i8* %16, i8* %17)
br label %51
19: ; preds = %7
%20 = load i8*, i8** %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %49
25: ; preds = %19
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %6
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %31, %25
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%37 = load i8*, i8** %2
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %36, i8* %41)
%43 = load i8*, i8** %2
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%45 = call i32 @cctools_debug(i64 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %43, i8* %44)
%46 = load i8*, i8** %2
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%48 = call i32 @strcpy(i8* %46, i8* %47)
br label %50
49: ; preds = %19
br label %52
50: ; preds = %34
br label %51
51: ; preds = %50, %11
br label %7
52: ; preds = %49
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"buffer:\00"
@.str.1 = [10 x i8] c"%[^:/]:%s\00"
@.str.2 = [7 x i8] c"remote\00"
@.str.3 = [13 x i8] c"chirp/CONDOR\00"
@.str.4 = [7 x i8] c"/%s/%s\00"
@.str.5 = [9 x i8] c"%s -> %s\00"
define void @clean_up_path(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %0, i64 7
%9 = getelementptr inbounds i8, i8* %0, i64 2
br label %10
10: ; preds = %29, %1
%11 = call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @strcpy(i8* %5, i8* %8)
br label %29
15: ; preds = %10
%16 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %7)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = call i32 @strlen(i8* %6)
%20 = call i32 @bcmp(i8* dereferenceable(7) %6, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 7)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = sext i32 %19 to i64
%26 = getelementptr inbounds i8, i8* %9, i64 %25
%27 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %6, i8* %26)
%28 = call i32 @cctools_debug(i64 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %5)
br label %29
29: ; preds = %24, %13
%30 = call i32 @strcpy(i8* %0, i8* %5)
br label %10
31: ; preds = %15
ret void
}