#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) {
  if (!path)
    return NULL;
  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)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <getSuffix+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11ce <getSuffix+0xae>
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    11a3 <getSuffix+0x83>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    118d <getSuffix+0x6d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x14(%rbp)
jmp    11a3 <getSuffix+0x83>
jmp    1192 <getSuffix+0x72>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <getSuffix+0x3d>
cmpl   $0x0,-0x14(%rbp)
jle    11c6 <getSuffix+0xa6>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1040 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <getSuffix+0xae>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSuffix>:
push   %rbx
test   %rdi,%rdi
je     116b <getSuffix+0x4b>
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    $0xffffffff,%eax
je     116b <getSuffix+0x4b>
movslq %eax,%rcx
add    $0x1,%rcx
nopw   0x0(%rax,%rax,1)
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
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* null, i8** %2
br label %42
9: ; preds = %1
store i32 -1, i32* %4
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
br label %14
14: ; preds = %29, %9
%15 = load i64, i64* %5
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = load i64, i64* %5
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i64, i64* %5
%26 = add i64 %25, 1
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
br label %32
28: ; preds = %17
br label %29
29: ; preds = %28
%30 = load i64, i64* %5
%31 = add i64 %30, -1
store i64 %31, i64* %5
br label %14
32: ; preds = %24, %14
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i8*, i8** %3
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = call i8* @strdup(i8* %39)
store i8* %40, i8** %2
br label %42
41: ; preds = %32
store i8* null, i8** %2
br label %42
42: ; preds = %41, %35, %8
%43 = load i8*, i8** %2
ret i8* %43
}

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