#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 */
int strlen(char *);
char *strrchr(char *, char);
int path_split(char *path, char **dirname, char **basename) {
  char *slash;
  int relative;
  relative = (path[0] != '/');
  slash = strrchr(path, '/');
  if (slash == NULL) {
    *basename = path;
    *dirname = path + strlen(path);
  } else {
    slash[0] = '\0';
    *dirname = path;
    *basename = slash + 1;
  }
  return relative;
}


x86 assembly (clang, -O0):
<path_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <path_split+0x77>
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rcx
cltq
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11b8 <path_split+0x98>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_split>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%bpl
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1151 <path_split+0x31>
movb   $0x0,(%rax)
mov    %rbx,(%r14)
add    $0x1,%rax
mov    %rax,(%r15)
jmp    1164 <path_split+0x44>
mov    %rbx,(%r15)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
mov    %rax,(%r14)
xor    %eax,%eax
cmp    $0x2f,%bpl
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @path_split(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = load i8, i8* %0
%5 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %3
store i8* %0, i8** %2
%8 = tail call i32 @strlen(i8* %0)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8* %10, i8** %1
br label %13
11: ; preds = %3
store i8 0, i8* %5
store i8* %0, i8** %1
%12 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %12, i8** %2
br label %13
13: ; preds = %11, %7
%14 = icmp ne i8 %4, 47
%15 = zext i1 %14 to i32
ret i32 %15
}