#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 */
long strlen(char *);
char *lastpart(char *fname) {
  long i, n = strlen(fname);
  for (i = n - 1; i >= 0; i--)
    if (fname[i] == '/')
      return (&fname[i]);
  return (fname);
}


x86 assembly (clang, -O0):
<lastpart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     117c <lastpart+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1166 <lastpart+0x56>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1184 <lastpart+0x74>
jmp    116b <lastpart+0x5b>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <lastpart+0x25>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lastpart>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
nopl   0x0(%rax)
test   %rax,%rax
jle    1136 <lastpart+0x26>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1120 <lastpart+0x10>
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @lastpart(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* %5
%8 = load i64, i64* %5
%9 = sub nsw i64 %8, 1
store i64 %9, i64* %4
br label %10
10: ; preds = %25, %1
%11 = load i64, i64* %4
%12 = icmp sge i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i64, i64* %4
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %2
br label %30
24: ; preds = %13
br label %25
25: ; preds = %24
%26 = load i64, i64* %4
%27 = add nsw i64 %26, -1
store i64 %27, i64* %4
br label %10
28: ; preds = %10
%29 = load i8*, i8** %3
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %20
%31 = load i8*, i8** %2
ret i8* %31
}

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