#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "basename: invalid number of arguments\n");
    return 1;
  }
  char *base = basename(argv[1]);
  if (argc > 2) {
    char *suffix = argv[2];
    int off = strlen(base) - strlen(suffix);
    if (off >= 0 && !strcmp(base + off, suffix))
      base[off] = '\0';
  }
  puts(base);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1191 <main+0x41>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <basename@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    120f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     120a <main+0xba>
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    120a <main+0xba>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    120f <main+0xbf>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1178 <main+0x28>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    11cc <main+0x7c>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1070 <basename@plt>
mov    %rax,%r15
cmp    $0x2,%ebp
je     11c2 <main+0x72>
mov    0x10(%rbx),%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
js     11c2 <main+0x72>
mov    %ebx,%eax
mov    %r15,%rbx
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11c2 <main+0x72>
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"basename: invalid number of arguments\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %49
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i8* @basename(i8* %17)
store i8* %18, i8** %6
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %46
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = load i8*, i8** %7
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %26, %28
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %21
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8*, i8** %7
%38 = call i32 @strcmp(i8* %36, i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %32
%41 = load i8*, i8** %6
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %40, %32, %21
br label %46
46: ; preds = %45, %14
%47 = load i8*, i8** %6
%48 = call i32 @puts(i8* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %46, %11
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"basename: invalid number of arguments\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %27
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @basename(i8* %9)
%11 = icmp eq i32 %0, 2
br i1 %11, label %25, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %10)
%16 = tail call i32 @strlen(i8* %14)
%17 = sub nsw i32 %15, %16
%18 = icmp sgt i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = zext i32 %17 to i64
%21 = getelementptr inbounds i8, i8* %10, i64 %20
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(1) %14)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i8 0, i8* %21
br label %25
25: ; preds = %12, %19, %24, %7
%26 = tail call i32 @puts(i8* dereferenceable(1) %10)
br label %27
27: ; preds = %25, %4
%28 = phi i32 [ 1, %4 ], [ 0, %25 ]
ret i32 %28
}