#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
main(int argc, char **argv) {
  int i;
  char *p;
  if ((argc < 2) || (argc > 3)) {
    fprintf(stderr, "Usage is: %s <path> [ <suffix> ]\n", argv[0]);
    return (1);
  }
  p = strrchr(argv[1], '/');
  if (!p) {
    p = argv[1];
  } else {
    ++p;
  }
  if (argc == 3) {
    int len = strlen(argv[2]), len2 = strlen(p);
    if ((len <= len2) && !strcmp(p + len2 - len, argv[2])) {
      fwrite(p, len2 - len, sizeof(char), stdout);
      putchar('\n');
      return (0);
    }
  }
  puts(p);
  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)
jl     119a <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11c2 <main+0x52>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4f(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <main+0x137>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f4 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1200 <main+0x90>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1297 <main+0x127>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     1292 <main+0x122>
mov    -0x20(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
movslq -0x24(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1292 <main+0x122>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
sub    -0x24(%rbp),%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a7 <main+0x137>
jmp    1297 <main+0x127>
mov    -0x20(%rbp),%rdi
call   1040 <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   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    -0x4(%rbp),%eax
cmp    $0xfffffffd,%eax
ja     11a4 <main+0x34>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe68(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    1203 <main+0x93>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%r12
test   %rax,%rax
cmove  %rbx,%r12
cmp    $0x3,%ebp
jne    11f9 <main+0x89>
mov    0x10(%r14),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
sub    %ebp,%r15d
jl     11f9 <main+0x89>
movslq %eax,%rdi
add    %r12,%rdi
movslq %ebp,%rax
sub    %rax,%rdi
mov    0x10(%r14),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     120c <main+0x9c>
mov    %r12,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc5(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1201 <main+0x91>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Usage is: %s <path> [ <suffix> ]\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 3
br i1 %14, label %15, label %21
15: ; preds = %12, %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %74
21: ; preds = %12
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i8* @strrchr(i8* %24, i8 signext 47)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %7
br label %35
32: ; preds = %21
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
br label %35
35: ; preds = %32, %28
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 3
br i1 %37, label %38, label %71
38: ; preds = %35
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @strlen(i8* %41)
store i32 %42, i32* %8
%43 = load i8*, i8** %7
%44 = call i32 @strlen(i8* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = icmp sle i32 %45, %46
br i1 %47, label %48, label %70
48: ; preds = %38
%49 = load i8*, i8** %7
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = sub i64 0, %54
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i32 @strcmp(i8* %56, i8* %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %70, label %62
62: ; preds = %48
%63 = load i8*, i8** %7
%64 = load i32, i32* %9
%65 = load i32, i32* %8
%66 = sub nsw i32 %64, %65
%67 = load i32, i32* @stdout
%68 = call i32 @fwrite(i8* %63, i32 %66, i32 1, i32 %67)
%69 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %3
br label %74
70: ; preds = %48, %38
br label %71
71: ; preds = %70, %35
%72 = load i8*, i8** %7
%73 = call i32 @puts(i8* %72)
store i32 0, i32* %3
br label %74
74: ; preds = %71, %62, %15
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Usage is: %s <path> [ <suffix> ]\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %39
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %11, i8 signext 47)
%13 = icmp eq i8* %12, null
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = select i1 %13, i8* %11, i8* %14
%16 = icmp eq i32 %0, 3
br i1 %16, label %17, label %37
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @strlen(i8* %19)
%21 = tail call i32 @strlen(i8* %15)
%22 = icmp slt i32 %21, %20
br i1 %22, label %37, label %23
23: ; preds = %17
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds i8, i8* %15, i64 %24
%26 = sext i32 %20 to i64
%27 = sub nsw i64 0, %26
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8*, i8** %18
%30 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(1) %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %23
%33 = sub nsw i32 %21, %20
%34 = load i32, i32* @stdout
%35 = tail call i32 @fwrite(i8* %15, i32 %33, i32 1, i32 %34)
%36 = tail call i32 @putchar(i8 signext 10)
br label %39
37: ; preds = %23, %17, %9
%38 = tail call i32 @puts(i8* dereferenceable(1) %15)
br label %39
39: ; preds = %32, %37, %5
%40 = phi i32 [ 1, %5 ], [ 0, %37 ], [ 0, %32 ]
ret i32 %40
}