#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 */
typedef char u_int8_t;

/* Variables and functions */
char *calloc(int, int);
int strlen(char *);
u_int8_t *path_unix_mac_root(char *path) {
  char *mac_path;
  int i;
  if (*path == '/')
    path++;
  mac_path = calloc(strlen(path) + 2, 1);
  mac_path[0] = ':';
  for (i = 0; i < strlen(path); i++)
    if (path[i] == '/')
      mac_path[i + 1] = ':';
    else
      mac_path[i + 1] = path[i];
  mac_path[i + 1] = '\0';
  return mac_path;
}


x86 assembly (clang, -O0):
<path_unix_mac_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1148 <path_unix_mac_root+0x28>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x3a,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11e7 <path_unix_mac_root+0xc7>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11b9 <path_unix_mac_root+0x99>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x3a,(%rax,%rcx,1)
jmp    11d4 <path_unix_mac_root+0xb4>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d9 <path_unix_mac_root+0xb9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <path_unix_mac_root+0x52>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_unix_mac_root>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
cmpb   $0x2f,(%rdi)
sete   %r15b
add    %rdi,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x2(%rax),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
movb   $0x3a,(%rax)
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1198 <path_unix_mac_root+0x78>
xor    %ebx,%ebx
mov    $0x3a,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
cmp    $0x2f,%al
cmove  %ebp,%eax
mov    %al,0x1(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1170 <path_unix_mac_root+0x50>
add    $0x1,%rbx
jmp    119d <path_unix_mac_root+0x7d>
mov    $0x1,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @path_unix_mac_root(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
%4 = zext i1 %3 to i64
%5 = getelementptr i8, i8* %0, i64 %4
%6 = tail call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 2
%8 = tail call i8* @calloc(i32 %7, i32 1)
store i8 58, i8* %8
%9 = tail call i32 @strlen(i8* %5)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %1, %11
%12 = phi i64 [ %16, %11 ], [ 0, %1 ]
%13 = getelementptr inbounds i8, i8* %5, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
%16 = add nuw nsw i64 %12, 1
%17 = getelementptr inbounds i8, i8* %8, i64 %16
%18 = select i1 %15, i8 58, i8 %14
store i8 %18, i8* %17
%19 = tail call i32 @strlen(i8* %5)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %16, %20
br i1 %21, label %11, label %22
22: ; preds = %11
%23 = add nuw i64 %12, 2
%24 = and i64 %23, 4294967295
br label %25
25: ; preds = %22, %1
%26 = phi i64 [ 1, %1 ], [ %24, %22 ]
%27 = getelementptr inbounds i8, i8* %8, i64 %26
store i8 0, i8* %27
ret i8* %8
}