#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 strlen(char *);
char *basename_simple(char *x) {
  int i;
  for (i = strlen(x) - 1; (i >= 0) && (x[i] != '/'); i--)
    ;
  return ((i == strlen(x) - 1) ? NULL : &x[i + 1]);
}


x86 assembly (clang, -O0):
<basename_simple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jl     114f <basename_simple+0x3f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    115f <basename_simple+0x4f>
jmp    1172 <basename_simple+0x62>
jmp    1164 <basename_simple+0x54>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    112b <basename_simple+0x1b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    119c <basename_simple+0x8c>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    11b0 <basename_simple+0xa0>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename_simple>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %ebp,%ebp
test   %eax,%eax
cmovs  %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %ecx,%ecx
jle    1147 <basename_simple+0x37>
lea    -0x1(%rcx),%rax
cmpb   $0x2f,-0x1(%rbx,%rcx,1)
mov    %rax,%rcx
jne    1130 <basename_simple+0x20>
add    $0x1,%eax
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %ebp,%rdx
add    %rdx,%rbx
xor    %ecx,%ecx
cmp    %eax,%edx
cmovne %rbx,%rcx
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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