#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 *eatpath(char *fname) {
  register int n;
  char *s;
  if (!fname)
    return NULL;
  s = fname;
  n = strlen(s);
  while (n--) {
    if (fname[n] == '/') {
      n++;
      return s + n;
    }
  }
  return fname;
}


x86 assembly (clang, -O0):
<eatpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <eatpath+0x24>
movq   $0x0,-0x8(%rbp)
jmp    119b <eatpath+0x8b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1193 <eatpath+0x83>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    118e <eatpath+0x7e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    119b <eatpath+0x8b>
jmp    1148 <eatpath+0x38>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eatpath>:
push   %rbx
test   %rdi,%rdi
je     116c <eatpath+0x5c>
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
mov    %rcx,%rdx
shl    $0x20,%rdx
movabs $0x100000000,%rax
add    %rdx,%rax
movabs $0xffffffff00000000,%rdx
ff ff ff
mov    %rcx,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
sub    $0x1,%rsi
jb     116e <eatpath+0x5e>
add    %rdx,%rax
cmpb   $0x2f,-0x1(%rbx,%rcx,1)
mov    %rsi,%rcx
jne    1150 <eatpath+0x40>
sar    $0x20,%rax
add    %rax,%rbx
jmp    116e <eatpath+0x5e>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @eatpath(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
br label %6
6: ; preds = %10, %3
%7 = phi i64 [ %8, %10 ], [ %5, %3 ]
%8 = add nsw i64 %7, -1
%9 = icmp eq i64 %7, 0
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %0, i64 %8
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %6
14: ; preds = %10
%15 = shl i64 %7, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
br label %18
18: ; preds = %6, %1, %14
%19 = phi i8* [ %17, %14 ], [ null, %1 ], [ %0, %6 ]
ret i8* %19
}