#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
unsigned char *arikkei_build_file_url(const unsigned char *path) {
  char *c, *p;
  if (!path)
    return NULL;
  c = (char *)malloc(strlen((const char *)path) + 6);
  strcpy(c, "file:");
  strcpy(c + 5, (const char *)path);
  for (p = c + 5; *p; p++) {
    if (*p == '\\')
      *p = '/';
  }
  return (unsigned char *)c;
}


x86 assembly (clang, -O0):
<arikkei_build_file_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <arikkei_build_file_url+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11dc <arikkei_build_file_url+0xac>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x6,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
add    $0x5,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d4 <arikkei_build_file_url+0xa4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11be <arikkei_build_file_url+0x8e>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
jmp    11c3 <arikkei_build_file_url+0x93>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119a <arikkei_build_file_url+0x6a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arikkei_build_file_url>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1194 <arikkei_build_file_url+0x64>
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    0x6(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xeab(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rbx
add    $0x5,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    1187 <arikkei_build_file_url+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x2f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1180 <arikkei_build_file_url+0x50>
test   %al,%al
jne    1183 <arikkei_build_file_url+0x53>
jmp    1197 <arikkei_build_file_url+0x67>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file:\00"
define i8* @arikkei_build_file_url(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* null, i8** %2
br label %40
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 6
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 5
%19 = load i8*, i8** %3
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 5
store i8* %22, i8** %5
br label %23
23: ; preds = %35, %9
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 92
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = load i8*, i8** %5
store i8 47, i8* %33
br label %34
34: ; preds = %32, %27
br label %35
35: ; preds = %34
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
br label %23
38: ; preds = %23
%39 = load i8*, i8** %4
store i8* %39, i8** %2
br label %40
40: ; preds = %38, %8
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [6 x i8] c"file:\00"
define i8* @arikkei_build_file_url(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add nsw i64 %4, 6
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds i8, i8* %7, i64 5
%10 = tail call i32 @strcpy(i8* %9, i8* %0)
br label %11
11: ; preds = %15, %3
%12 = phi i8* [ %9, %3 ], [ %16, %15 ]
%13 = load i8, i8* %12
switch i8 %13, label %15 [
i8 0, label %17
i8 92, label %14
]
14: ; preds = %11
store i8 47, i8* %12
br label %15
15: ; preds = %11, %14
%16 = getelementptr inbounds i8, i8* %12, i64 1
br label %11
17: ; preds = %11, %1
%18 = phi i8* [ null, %1 ], [ %7, %11 ]
ret i8* %18
}