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


x86 assembly (clang, -O0):
<tag_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     11c9 <tag_dir+0x89>
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)
je     119b <tag_dir+0x5b>
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <tag_dir+0x66>
lea    0xe5e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%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    11d1 <tag_dir+0x91>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_dir>:
test   %edi,%edi
jle    116e <tag_dir+0x2e>
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
je     1171 <tag_dir+0x31>
movb   $0x0,0x1(%rax)
mov    %rbx,%rdi
jmp    1178 <tag_dir+0x38>
xor    %eax,%eax
ret
lea    0xe88(%rip),%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

LLVM IR (-O0):
@.str = [3 x i8] c"./\00"
define i8* @tag_dir(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 %30
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 %19, label %23
19: ; preds = %10
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8 0, i8* %21
%22 = load i8*, i8** %7
store i8* %22, i8** %6
br label %24
23: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
br label %24
24: ; preds = %23, %19
%25 = load i8*, i8** %6
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %6
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %6
store i8* %29, i8** %3
br label %31
30: ; preds = %2
store i8* null, i8** %3
br label %31
31: ; preds = %30, %24
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"./\00"
define noalias i8* @tag_dir(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %15
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
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %7, i64 1
store i8 0, i8* %10
br label %11
11: ; preds = %4, %9
%12 = phi i8* [ %6, %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %4 ]
%13 = tail call i8* @strdup(i8* %12)
%14 = tail call i32 @free(i8* %6)
br label %15
15: ; preds = %2, %11
%16 = phi i8* [ %13, %11 ], [ null, %2 ]
ret i8* %16
}