#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 const *);
int strlen(char const *);
char *getSuffix(const char *path) {
  int found = -1;
  for (size_t i = strlen(path) - 1; i > 0; i--) {
    if (path[i] == '/') {
      found = i + 1;
      break;
    }
  }
  if (found > 0) {
    return strdup(path + found);
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<getSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    118b <getSuffix+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1175 <getSuffix+0x55>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x14(%rbp)
jmp    118b <getSuffix+0x6b>
jmp    117a <getSuffix+0x5a>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1145 <getSuffix+0x25>
cmpl   $0x0,-0x14(%rbp)
jle    11ae <getSuffix+0x8e>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1040 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11b6 <getSuffix+0x96>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSuffix>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    $0xffffffff,%eax
je     116b <getSuffix+0x4b>
movslq %eax,%rcx
add    $0x1,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x2f,-0x1(%rbx,%rcx,1)
je     1156 <getSuffix+0x36>
add    $0xffffffffffffffff,%rcx
add    $0xffffffff,%eax
cmp    $0x1,%rcx
jne    1140 <getSuffix+0x20>
jmp    116b <getSuffix+0x4b>
cmp    $0x7ffffffe,%eax
ja     116b <getSuffix+0x4b>
mov    %ecx,%eax
add    %rax,%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <strdup@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @getSuffix(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 -1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
%9 = sext i32 %8 to i64
store i64 %9, i64* %5
br label %10
10: ; preds = %25, %1
%11 = load i64, i64* %5
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i64, i64* %5
%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 i64, i64* %5
%22 = add i64 %21, 1
%23 = trunc i64 %22 to i32
store i32 %23, i32* %4
br label %28
24: ; preds = %13
br label %25
25: ; preds = %24
%26 = load i64, i64* %5
%27 = add i64 %26, -1
store i64 %27, i64* %5
br label %10
28: ; preds = %20, %10
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %2
br label %38
37: ; preds = %28
store i8* null, i8** %2
br label %38
38: ; preds = %37, %31
%39 = load i8*, i8** %2
ret i8* %39
}

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