#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 */
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
char *strrchr(char const *, char);
const char *arg_basename(const char *filename) {
  const char *result = NULL, *result1, *result2;
  result1 = (filename ? strrchr(filename, '/') : NULL);
  result2 = (filename ? strrchr(filename, '/') : NULL);
  if (result2)
    result = result2 + 1;
  if (result1)
    result = result1 + 1;
  if (!result)
    result = filename;
  if (result && (strcmp(".", result) == 0 || strcmp("..", result) == 0))
    result = filename + strlen(filename);
  return result;
}


x86 assembly (clang, -O0):
<arg_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1166 <arg_basename+0x36>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
jmp    1171 <arg_basename+0x41>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    1171 <arg_basename+0x41>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119b <arg_basename+0x6b>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x30(%rbp)
jmp    11a6 <arg_basename+0x76>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11a6 <arg_basename+0x76>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c5 <arg_basename+0x95>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dc <arg_basename+0xac>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ef <arg_basename+0xbf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     124f <arg_basename+0x11f>
mov    -0x10(%rbp),%rsi
lea    0xdfc(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     122e <arg_basename+0xfe>
mov    -0x10(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    124f <arg_basename+0x11f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_basename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     114b <arg_basename+0x1b>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
jmp    114d <arg_basename+0x1d>
xor    %eax,%eax
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r14,%rbx
test   %rbx,%rbx
je     1195 <arg_basename+0x65>
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1185 <arg_basename+0x55>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1197 <arg_basename+0x67>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
jmp    1197 <arg_basename+0x67>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i8* @arg_basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
br label %12
11: ; preds = %1
br label %12
12: ; preds = %11, %8
%13 = phi i8* [ %10, %8 ], [ null, %11 ]
store i8* %13, i8** %4
%14 = load i8*, i8** %2
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i8* @strrchr(i8* %17, i8 signext 47)
br label %20
19: ; preds = %12
br label %20
20: ; preds = %19, %16
%21 = phi i8* [ %18, %16 ], [ null, %19 ]
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %3
br label %27
27: ; preds = %24, %20
%28 = load i8*, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %3
br label %33
33: ; preds = %30, %27
%34 = load i8*, i8** %3
%35 = icmp ne i8* %34, null
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = load i8*, i8** %2
store i8* %37, i8** %3
br label %38
38: ; preds = %36, %33
%39 = load i8*, i8** %3
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %55
41: ; preds = %38
%42 = load i8*, i8** %3
%43 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = load i8*, i8** %3
%47 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %45, %41
%50 = load i8*, i8** %2
%51 = load i8*, i8** %2
%52 = call i32 @strlen(i8* %51)
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %50, i64 %53
store i8* %54, i8** %3
br label %55
55: ; preds = %49, %45, %38
%56 = load i8*, i8** %3
ret i8* %56
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i8* @arg_basename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i8* @strrchr(i8* %0, i8 signext 47)
br label %5
5: ; preds = %1, %3
%6 = phi i8* [ %4, %3 ], [ null, %1 ]
%7 = icmp eq i8* %6, null
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = select i1 %7, i8* %0, i8* %8
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %5
%12 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14, %11
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
br label %21
21: ; preds = %17, %14, %5
%22 = phi i8* [ %20, %17 ], [ %9, %14 ], [ null, %5 ]
ret i8* %22
}