#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(int);
int strlen(char const *);
const char *hash_path(const char *path) {
  char *rv = malloc(strlen(path) * 2 + 1);
  const char *s = path;
  char *d = rv;
  do {
    switch (*s) {
    case '/':
      *d++ = '$';
      break;
    case '$':
      *d++ = *s;
    default:
      *d++ = *s;
      break;
    }
  } while (*s++);
  return rv;
}


x86 assembly (clang, -O0):
<hash_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x24,%eax
je     1196 <hash_path+0x76>
jmp    116e <hash_path+0x4e>
mov    -0x24(%rbp),%eax
sub    $0x2f,%eax
jne    11ad <hash_path+0x8d>
jmp    117f <hash_path+0x5f>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x24,(%rax)
jmp    11c4 <hash_path+0xa4>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11c9 <hash_path+0xa9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    1156 <hash_path+0x36>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_path>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
jmp    1158 <hash_path+0x38>
nopl   0x0(%rax)
mov    %dl,(%rcx)
add    $0x1,%rcx
movzbl (%rbx),%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
je     116d <hash_path+0x4d>
movzbl (%rbx),%edx
movsbl %dl,%esi
cmp    $0x24,%esi
je     1140 <hash_path+0x20>
cmp    $0x2f,%esi
jne    1149 <hash_path+0x29>
movb   $0x24,(%rcx)
jmp    114b <hash_path+0x2b>
pop    %rbx
ret

LLVM IR (-O0):
define i8* @hash_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = mul nsw i32 %7, 2
%9 = add nsw i32 %8, 1
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %2
store i8* %11, i8** %4
%12 = load i8*, i8** %3
store i8* %12, i8** %5
br label %13
13: ; preds = %31, %1
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %25 [
i32 47, label %17
i32 36, label %20
]
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
store i8 36, i8* %18
br label %30
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 %22, i8* %23
br label %25
25: ; preds = %13, %20
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 %27, i8* %28
br label %30
30: ; preds = %25, %17
br label %31
31: ; preds = %30
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
%34 = load i8, i8* %32
%35 = icmp ne i8 %34, 0
br i1 %35, label %13, label %36
36: ; preds = %31
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
define noalias i8* @hash_path(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
br label %6
6: ; preds = %18, %1
%7 = phi i8* [ %0, %1 ], [ %21, %18 ]
%8 = phi i8* [ %5, %1 ], [ %20, %18 ]
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
switch i32 %10, label %15 [
i32 47, label %11
i32 36, label %12
]
11: ; preds = %6
store i8 36, i8* %8
br label %18
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %9, i8* %8
%14 = load i8, i8* %7
br label %15
15: ; preds = %6, %12
%16 = phi i8 [ %9, %6 ], [ %14, %12 ]
%17 = phi i8* [ %8, %6 ], [ %13, %12 ]
store i8 %16, i8* %17
br label %18
18: ; preds = %11, %15
%19 = phi i8* [ %17, %15 ], [ %8, %11 ]
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = getelementptr inbounds i8, i8* %7, i64 1
%22 = load i8, i8* %7
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %6
24: ; preds = %18
ret i8* %5
}