#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 *);
const char *split_pathname(char *fullpath, int len) {
  int ptr;
  ptr = strlen(fullpath);
  while (1) {
    if (ptr == 0)
      break;
    if (fullpath[ptr] == '/') {
      fullpath[ptr] = 0;
      return &fullpath[ptr + 1];
    }
    ptr--;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<split_pathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    113a <split_pathname+0x2a>
jmp    1182 <split_pathname+0x72>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1174 <split_pathname+0x64>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    118a <split_pathname+0x7a>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    112b <split_pathname+0x1b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_pathname>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     1161 <split_pathname+0x51>
movslq %eax,%rsi
lea    (%rbx,%rsi,1),%rdx
shl    $0x20,%rsi
movabs $0x100000000,%rcx
add    %rsi,%rcx
neg    %eax
movabs $0xffffffff00000000,%rsi
ff ff ff
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x2f,(%rdx,%rdi,1)
je     1165 <split_pathname+0x55>
add    $0xffffffffffffffff,%rdi
add    %rsi,%rcx
cmp    %edi,%eax
jne    1150 <split_pathname+0x40>
xor    %ebx,%ebx
jmp    1170 <split_pathname+0x60>
movb   $0x0,(%rdi,%rdx,1)
sar    $0x20,%rcx
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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