#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 *Strdup(char *, char *);
char *rindex(char *, char);
char *PathTo(char *name) {
  char *path, *find;
  if (name == NULL)
    return (NULL);
  if ((find = rindex(name, '/')) != NULL) {
    *find = '\0';
    path = Strdup(name, "Extracting path from");
    *find = '/';
  } else
    path = Strdup(".", "Allocating default path");
  return (path);
}


x86 assembly (clang, -O0):
<PathTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <PathTo+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <PathTo+0x86>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <rindex@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1187 <PathTo+0x67>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1030 <Strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
jmp    119e <PathTo+0x7e>
lea    0xe87(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1030 <Strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PathTo>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1156 <PathTo+0x36>
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1040 <rindex@plt>
test   %rax,%rax
je     1160 <PathTo+0x40>
mov    %rax,%r14
movb   $0x0,(%rax)
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
call   1030 <Strdup@plt>
movb   $0x2f,(%r14)
jmp    1158 <PathTo+0x38>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xeae(%rip),%rdi
lea    0xea9(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <Strdup@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Extracting path from\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [24 x i8] c"Allocating default path\00"
define i8* @PathTo(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 eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %22
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @rindex(i8* %10, i8 signext 47)
store i8* %11, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i8*, i8** %5
store i8 0, i8* %14
%15 = load i8*, i8** %3
%16 = call i8* @Strdup(i8* %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %4
%17 = load i8*, i8** %5
store i8 47, i8* %17
br label %20
18: ; preds = %9
%19 = call i8* @Strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i8* %19, i8** %4
br label %20
20: ; preds = %18, %13
%21 = load i8*, i8** %4
store i8* %21, i8** %2
br label %22
22: ; preds = %20, %8
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [21 x i8] c"Extracting path from\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [24 x i8] c"Allocating default path\00"
define i8* @PathTo(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i8* @rindex(i8* %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = tail call i8* @Strdup(i8* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8 47, i8* %4
br label %10
8: ; preds = %3
%9 = tail call i8* @Strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %6, %8, %1
%11 = phi i8* [ null, %1 ], [ %7, %6 ], [ %9, %8 ]
ret i8* %11
}