#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 /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
u_int8_t *path_mac_unix(char *mac_path, char *ipod_prefix) {
  char *path;
  int i;
  if (ipod_prefix == NULL || mac_path == NULL)
    return NULL;
  if (*mac_path == ':')
    mac_path++;
  path = calloc(strlen(mac_path) + strlen(ipod_prefix) + 2, 1);
  sprintf(path, "%s/", ipod_prefix);
  for (i = 0; i < strlen(mac_path); i++)
    if (mac_path[i] == ':')
      path[i + strlen(ipod_prefix) + 1] = '/';
    else
      path[i + strlen(ipod_prefix) + 1] = mac_path[i];
  path[i + strlen(ipod_prefix) + 1] = '\0';
  return path;
}


x86 assembly (clang, -O0):
<path_mac_unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1156 <path_mac_unix+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    1163 <path_mac_unix+0x33>
movq   $0x0,-0x8(%rbp)
jmp    12aa <path_mac_unix+0x17a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    117f <path_mac_unix+0x4f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe47(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    1276 <path_mac_unix+0x146>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1227 <path_mac_unix+0xf7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    -0x38(%rbp),%rax
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    1263 <path_mac_unix+0x133>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x49(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%ecx
mov    -0x49(%rbp),%dl
mov    %eax,%esi
mov    -0x48(%rbp),%rax
add    %esi,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1268 <path_mac_unix+0x138>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c5 <path_mac_unix+0x95>
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x5c(%rbp),%ecx
mov    %eax,%edx
mov    -0x58(%rbp),%rax
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_mac_unix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     11fe <path_mac_unix+0xce>
mov    %rsi,%r14
test   %rsi,%rsi
je     11fe <path_mac_unix+0xce>
xor    %r12d,%r12d
cmpb   $0x3a,(%rdi)
sete   %r12b
add    %rdi,%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11ed <path_mac_unix+0xbd>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbp,%rbx
movzbl (%r12,%rbp,1),%r13d
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%rbp
cmp    $0x3a,%r13b
lea    0x1(%rbx,%rax,1),%eax
cltq
mov    $0x2f,%ecx
cmove  %ecx,%r13d
mov    %r13b,(%r15,%rax,1)
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11b0 <path_mac_unix+0x80>
add    $0x1,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cltq
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s/\00"
define i8* @path_mac_unix(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i8* null, i8** %3
br label %83
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 58
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %4
%24 = call i32 @strlen(i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %24, %26
%28 = add nsw i32 %27, 2
%29 = call i8* @calloc(i32 %28, i32 1)
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = load i8*, i8** %5
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 0, i32* %7
br label %33
33: ; preds = %70, %22
%34 = load i32, i32* %7
%35 = load i8*, i8** %4
%36 = call i32 @strlen(i8* %35)
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %73
38: ; preds = %33
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 58
br i1 %45, label %46, label %55
46: ; preds = %38
%47 = load i8*, i8** %6
%48 = load i32, i32* %7
%49 = load i8*, i8** %5
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %48, %50
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %47, i64 %53
store i8 47, i8* %54
br label %69
55: ; preds = %38
%56 = load i8*, i8** %4
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = load i8*, i8** %6
%62 = load i32, i32* %7
%63 = load i8*, i8** %5
%64 = call i32 @strlen(i8* %63)
%65 = add nsw i32 %62, %64
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %61, i64 %67
store i8 %60, i8* %68
br label %69
69: ; preds = %55, %46
br label %70
70: ; preds = %69
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %33
73: ; preds = %33
%74 = load i8*, i8** %6
%75 = load i32, i32* %7
%76 = load i8*, i8** %5
%77 = call i32 @strlen(i8* %76)
%78 = add nsw i32 %75, %77
%79 = add nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %74, i64 %80
store i8 0, i8* %81
%82 = load i8*, i8** %6
store i8* %82, i8** %3
br label %83
83: ; preds = %73, %13
%84 = load i8*, i8** %3
ret i8* %84
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s/\00"
define noalias i8* @path_mac_unix(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
%4 = icmp eq i8* %0, null
%5 = or i1 %4, %3
br i1 %5, label %43, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 58
%9 = zext i1 %8 to i64
%10 = getelementptr i8, i8* %0, i64 %9
%11 = tail call i32 @strlen(i8* %10)
%12 = tail call i32 @strlen(i8* %1)
%13 = add i32 %11, 2
%14 = add i32 %13, %12
%15 = tail call i8* @calloc(i32 %14, i32 1)
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%17 = tail call i32 @strlen(i8* %10)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %6, %19
%20 = phi i64 [ %25, %19 ], [ 0, %6 ]
%21 = getelementptr inbounds i8, i8* %10, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 58
%24 = tail call i32 @strlen(i8* %1)
%25 = add nuw nsw i64 %20, 1
%26 = trunc i64 %25 to i32
%27 = add i32 %24, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %15, i64 %28
%30 = select i1 %23, i8 47, i8 %22
store i8 %30, i8* %29
%31 = tail call i32 @strlen(i8* %10)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %25, %32
br i1 %33, label %19, label %34
34: ; preds = %19
%35 = trunc i64 %25 to i32
%36 = add i32 %35, 1
br label %37
37: ; preds = %34, %6
%38 = phi i32 [ 1, %6 ], [ %36, %34 ]
%39 = tail call i32 @strlen(i8* %1)
%40 = add i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %15, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %2, %37
%44 = phi i8* [ %15, %37 ], [ null, %2 ]
ret i8* %44
}