#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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
char *getfilename(char *buff, int size, char *url) {
  if (strrchr(url, '/')) {
    if (strlen(buff) + strlen(strrchr(url, '/') + 1) < size)
      strcpy(buff, strrchr(url, '/') + 1);
  } else if (strlen(buff) + strlen(url) < size)
    strcpy(buff, url);
  return buff;
}


x86 assembly (clang, -O0):
<getfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
cmp    $0x0,%rax
je     11bc <getfilename+0x8c>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cmp    -0xc(%rbp),%eax
jge    11b7 <getfilename+0x87>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
jmp    11f3 <getfilename+0xc3>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
cmp    -0xc(%rbp),%eax
jge    11ee <getfilename+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11f3 <getfilename+0xc3>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfilename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rdx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
test   %rbp,%rbp
je     1195 <getfilename+0x65>
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rdi
call   1040 <strlen@plt>
add    %r12d,%eax
cmp    %r15d,%eax
jge    11ad <getfilename+0x7d>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
jmp    11a8 <getfilename+0x78>
call   1040 <strlen@plt>
add    %r12d,%eax
cmp    %r15d,%eax
jge    11ad <getfilename+0x7d>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @getfilename(i8* returned %0, i32 %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = tail call i32 @strlen(i8* %0)
br i1 %5, label %17, label %7
7: ; preds = %3
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, %6
%12 = icmp slt i32 %11, %1
br i1 %12, label %13, label %23
13: ; preds = %7
%14 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = tail call i32 @strcpy(i8* %0, i8* %15)
br label %23
17: ; preds = %3
%18 = tail call i32 @strlen(i8* %2)
%19 = add nsw i32 %18, %6
%20 = icmp slt i32 %19, %1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @strcpy(i8* %0, i8* %2)
br label %23
23: ; preds = %17, %21, %7, %13
ret i8* %0
}