#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*/ canonize_path1(char *, int, char const *);
int /*<<< orphan*/ pstrcpy(char *, int, char const *);
char *strchr(char const *, char);
void canonize_path(char *buf, int buf_size, const char *path) {
  const char *p;
  p = strchr(path, ':');
  if (p) {
    if ((p - path) == 1) {
      buf[0] = p[0];
      buf[1] = p[1];
      canonize_path1(buf + 2, buf_size - 2, p);
    } else {
      pstrcpy(buf, buf_size, path);
    }
  } else {
    canonize_path1(buf, buf_size, path);
  }
}


x86 assembly (clang, -O0):
<canonize_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c0 <canonize_path+0x90>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1,%rax
jne    11ab <canonize_path+0x7b>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0xc(%rbp),%esi
sub    $0x2,%esi
mov    -0x20(%rbp),%rdx
call   1050 <canonize_path1@plt>
jmp    11bb <canonize_path+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <pstrcpy@plt>
jmp    11d0 <canonize_path+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <canonize_path1@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonize_path>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1178 <canonize_path+0x48>
mov    %rax,%rcx
sub    %rbp,%rcx
cmp    $0x1,%rcx
jne    118a <canonize_path+0x5a>
mov    (%rax),%cl
mov    %cl,(%rbx)
mov    0x1(%rax),%cl
mov    %cl,0x1(%rbx)
add    $0x2,%rbx
add    $0xfffffffe,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
jmp    1181 <canonize_path+0x51>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <canonize_path1@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <pstrcpy@plt>

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

LLVM IR (-O2):
define void @canonize_path(i8* %0, i32 %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %2 to i64
%9 = sub i64 %7, %8
%10 = icmp eq i64 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i8, i8* %4
store i8 %12, i8* %0
%13 = getelementptr inbounds i8, i8* %4, i64 1
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %14, i8* %15
%16 = getelementptr inbounds i8, i8* %0, i64 2
%17 = add nsw i32 %1, -2
%18 = tail call i32 @canonize_path1(i8* %16, i32 %17, i8* %4)
br label %23
19: ; preds = %6
%20 = tail call i32 @pstrcpy(i8* %0, i32 %1, i8* %2)
br label %23
21: ; preds = %3
%22 = tail call i32 @canonize_path1(i8* %0, i32 %1, i8* %2)
br label %23
23: ; preds = %11, %19, %21
ret void
}