#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 *basename(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
int _basename(char *arg, char const *suf) {
  char *str;
  int slen;
  int alen;
  str = basename(arg);
  if (suf != NULL) {
    slen = strlen(str);
    alen = strlen(suf);
    if (alen < slen && strcmp(suf, &str[slen - alen]) == 0)
      str[slen - alen] = '\0';
  }
  puts(str);
  return 0;
}


x86 assembly (clang, -O0):
<_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c4 <_basename+0x84>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bf <_basename+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
add    %rax,%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11bf <_basename+0x7f>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c4 <_basename+0x84>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_basename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1060 <basename@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     118a <_basename+0x4a>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
jle    118a <_basename+0x4a>
movslq %ebp,%rax
add    %rax,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    118a <_basename+0x4a>
movb   $0x0,(%r15)
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @_basename(i8* %0, i8* %1) {
%3 = tail call i8* @basename(i8* %0)
%4 = icmp eq i8* %1, null
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp sgt i32 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = sub nsw i32 %6, %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = tail call i64 @strcmp(i8* %1, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i8 0, i8* %12
br label %16
16: ; preds = %5, %9, %15, %2
%17 = tail call i32 @puts(i8* dereferenceable(1) %3)
ret i32 0
}