#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 */
size_t strlen(char *);
char *after_last_slash(char *string) {
  size_t pos = strlen(string);
  for (size_t i = 0; i < strlen(string); i++) {
    pos--;
    if (string[pos] == '/') {
      return (string + pos + 1);
    }
  }
  return string;
}


x86 assembly (clang, -O0):
<after_last_slash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    119e <after_last_slash+0x8e>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1188 <after_last_slash+0x78>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <after_last_slash+0x96>
jmp    118d <after_last_slash+0x7d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1131 <after_last_slash+0x21>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<after_last_slash>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     1132 <after_last_slash+0x22>
xchg   %ax,%ax
cmpb   $0x2f,-0x1(%rbx,%rax,1)
je     112f <after_last_slash+0x1f>
add    $0xffffffffffffffff,%rax
jne    1120 <after_last_slash+0x10>
jmp    1132 <after_last_slash+0x22>
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @after_last_slash(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %16, label %6
4: ; preds = %6
%5 = icmp eq i64 %13, %2
br i1 %5, label %16, label %6
6: ; preds = %1, %4
%7 = phi i64 [ %13, %4 ], [ 0, %1 ]
%8 = phi i64 [ %9, %4 ], [ %2, %1 ]
%9 = add i64 %8, -1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
%13 = add nuw i64 %7, 1
br i1 %12, label %14, label %4
14: ; preds = %6
%15 = getelementptr inbounds i8, i8* %0, i64 %8
br label %16
16: ; preds = %4, %1, %14
%17 = phi i8* [ %15, %14 ], [ %0, %1 ], [ %0, %4 ]
ret i8* %17
}