#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*/ free(char *);
char *process_text(char *);
char *strdup(char *);
char *strrchr(char *, char);
char *tag_basename(int argc, char *argv[]) {
  if (argc >= 1) {
    char *s, *filename = process_text(argv[0]);
    s = strrchr(filename, '/');
    if (!s)
      s = filename;
    s = strrchr(s, '.');
    if (s)
      *s = 0;
    s = strdup(filename);
    free(filename);
    return s;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<tag_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     11d5 <tag_basename+0x95>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <process_text@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <tag_basename+0x4e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b2 <tag_basename+0x72>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dd <tag_basename+0x9d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_basename>:
test   %edi,%edi
jle    119a <tag_basename+0x5a>
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rdi
call   1050 <process_text@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
mov    %rbx,%rdi
cmovne %rax,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     117c <tag_basename+0x3c>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define noalias i8* @tag_basename(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i8* @process_text(i8* %5)
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 47)
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i8* %6, i8* %7
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %9, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %4
store i8 0, i8* %10
br label %13
13: ; preds = %12, %4
%14 = tail call i8* @strdup(i8* %6)
%15 = tail call i32 @free(i8* %6)
br label %16
16: ; preds = %2, %13
%17 = phi i8* [ %14, %13 ], [ null, %2 ]
ret i8* %17
}