#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 *after_last_slash(char *);
int /*<<< orphan*/ bu_extra_argument(char *);
scalar_t__ bu_handle_version(int, char **);
int /*<<< orphan*/ bu_missing_argument(char *);
scalar_t__ consists_entirely_of(char *, char);
scalar_t__ has_arg(int, char **, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ remove_suffix(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ truncate_trailing_slashes(char *);
int main(int argc, char **argv) {
  if (has_arg(argc, argv, "-h") || has_arg(argc, argv, "--help")) {
    puts("Usage: basename FILE [SUFFIX]");
    puts("Strip the directory and SUFFIX from FILE.");
    return 1;
  }
  if (bu_handle_version(argc, argv)) {
    return 0;
  }
  if (argc < 2) {
    bu_missing_argument(argv[0]);
    return 1;
  }
  if (argc > 3) {
    bu_extra_argument(argv[0]);
    return 1;
  }
  char *string = argv[1];
  if (strlen(argv[1]) == 0) {
    puts("");
    return 0;
  }
  if (consists_entirely_of(string, '/')) {
    puts("/");
    return 0;
  }
  truncate_trailing_slashes(string);
  string = after_last_slash(string);
  if (argc > 2) {
    remove_suffix(string, argv[2]);
  }
  puts(string);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%rax
jne    11f0 <main+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe22(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%rax
je     1214 <main+0x74>
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x186>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10b0 <bu_handle_version@plt>
cmp    $0x0,%rax
je     1236 <main+0x96>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x186>
cmpl   $0x2,-0x8(%rbp)
jge    1258 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <bu_missing_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x186>
cmpl   $0x3,-0x8(%rbp)
jle    127a <main+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <bu_extra_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jne    12b5 <main+0x115>
lea    0xdad(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x186>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <consists_entirely_of@plt>
cmp    $0x0,%rax
je     12e5 <main+0x145>
lea    0xd7e(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x186>
mov    -0x18(%rbp),%rdi
call   1090 <truncate_trailing_slashes@plt>
mov    -0x18(%rbp),%rdi
call   1030 <after_last_slash@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1316 <main+0x176>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   10a0 <remove_suffix@plt>
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe4d(%rip),%rdx
call   1060 <has_arg@plt>
test   %rax,%rax
jne    11d3 <main+0x33>
lea    0xe3f(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <has_arg@plt>
test   %rax,%rax
je     11ff <main+0x5f>
lea    0xe30(%rip),%rdi
call   1050 <puts@plt>
lea    0xe42(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <bu_handle_version@plt>
xor    %r14d,%r14d
test   %rax,%rax
jne    11f1 <main+0x51>
cmp    $0x1,%ebp
jg     1220 <main+0x80>
mov    (%rbx),%rdi
call   10c0 <bu_missing_argument@plt>
jmp    11eb <main+0x4b>
cmp    $0x4,%ebp
jb     122f <main+0x8f>
mov    (%rbx),%rdi
call   1080 <bu_extra_argument@plt>
jmp    11eb <main+0x4b>
mov    0x8(%rbx),%r15
cmpb   $0x0,(%r15)
je     1254 <main+0xb4>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1070 <consists_entirely_of@plt>
test   %rax,%rax
je     1260 <main+0xc0>
lea    0xe00(%rip),%rdi
jmp    1287 <main+0xe7>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11f1 <main+0x51>
mov    %r15,%rdi
call   1090 <truncate_trailing_slashes@plt>
mov    %r15,%rdi
call   1040 <after_last_slash@plt>
mov    %rax,%r15
cmp    $0x3,%ebp
jb     1284 <main+0xe4>
mov    0x10(%rbx),%rsi
mov    %r15,%rdi
call   10a0 <remove_suffix@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
jmp    11f1 <main+0x51>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [30 x i8] c"Usage: basename FILE [SUFFIX]\00"
@.str.3 = [42 x i8] c"Strip the directory and SUFFIX from FILE.\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = call i64 @has_arg(i32 %7, i8** %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i64 @has_arg(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11, %2
%17 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %74
19: ; preds = %11
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i64 @bu_handle_version(i32 %20, i8** %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %3
br label %74
25: ; preds = %19
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 2
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @bu_missing_argument(i8* %31)
store i32 1, i32* %3
br label %74
33: ; preds = %25
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 3
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @bu_extra_argument(i8* %39)
store i32 1, i32* %3
br label %74
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
store i8* %44, i8** %6
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i64 @strlen(i8* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %74
52: ; preds = %41
%53 = load i8*, i8** %6
%54 = call i64 @consists_entirely_of(i8* %53, i8 signext 47)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %74
58: ; preds = %52
%59 = load i8*, i8** %6
%60 = call i32 @truncate_trailing_slashes(i8* %59)
%61 = load i8*, i8** %6
%62 = call i8* @after_last_slash(i8* %61)
store i8* %62, i8** %6
%63 = load i32, i32* %4
%64 = icmp sgt i32 %63, 2
br i1 %64, label %65, label %71
65: ; preds = %58
%66 = load i8*, i8** %6
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 @remove_suffix(i8* %66, i8* %69)
br label %71
71: ; preds = %65, %58
%72 = load i8*, i8** %6
%73 = call i32 @puts(i8* %72)
store i32 0, i32* %3
br label %74
74: ; preds = %71, %56, %50, %36, %28, %24, %16
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [30 x i8] c"Usage: basename FILE [SUFFIX]\00"
@.str.3 = [42 x i8] c"Strip the directory and SUFFIX from FILE.\00"
@.str.5 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %46
11: ; preds = %5
%12 = tail call i64 @bu_handle_version(i32 %0, i8** %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %46
14: ; preds = %11
%15 = icmp slt i32 %0, 2
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i8*, i8** %1
%18 = tail call i32 @bu_missing_argument(i8* %17)
br label %46
19: ; preds = %14
%20 = icmp ugt i32 %0, 3
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i8*, i8** %1
%23 = tail call i32 @bu_extra_argument(i8* %22)
br label %46
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @putchar(i32 10)
br label %46
31: ; preds = %24
%32 = tail call i64 @consists_entirely_of(i8* %26, i8 signext 47)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %46
36: ; preds = %31
%37 = tail call i32 @truncate_trailing_slashes(i8* %26)
%38 = tail call i8* @after_last_slash(i8* %26)
%39 = icmp ugt i32 %0, 2
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = tail call i32 @remove_suffix(i8* %38, i8* %42)
br label %44
44: ; preds = %40, %36
%45 = tail call i32 @puts(i8* dereferenceable(1) %38)
br label %46
46: ; preds = %29, %34, %44, %11, %21, %16, %8
%47 = phi i32 [ 1, %8 ], [ 1, %16 ], [ 1, %21 ], [ 0, %11 ], [ 0, %44 ], [ 0, %34 ], [ 0, %29 ]
ret i32 %47
}