#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*/ EXIT_FAILURE;
char *basename(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int opt;
  while ((opt = getopt(argc, argv, "")) != -1) {
    switch (opt) {
    default:
      fprintf(stderr, "Usage: %s string [suffix]\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (optind == argc || argc - optind > 2) {
    fprintf(stderr, "Usage: %s string [suffix]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  char *base = basename(argv[optind]), *suffix;
  suffix = (char *)malloc(strlen(base));
  memcpy(suffix, base, strlen(base));
  if (argv[optind + 1] && strlen(argv[optind + 1]) < strlen(base)) {
    suffix += strlen(base) - strlen(argv[optind + 1]);
    if (strcmp(suffix, argv[optind + 1]) == 0)
      base[strlen(suffix) + 1] = 0;
  }
  printf("%s\n", base);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe66(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11ef <main+0x5f>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe24(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     1216 <main+0x86>
mov    -0x8(%rbp),%eax
mov    0x2ddd(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
jle    1240 <main+0xb0>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd3(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d9d(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <basename@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x2d46(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1375 <main+0x1e5>
mov    -0x10(%rbp),%rax
mov    0x2d28(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    1375 <main+0x1e5>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ce7(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%ecx
sub    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2cb4(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1370 <main+0x1e0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1375 <main+0x1e5>
mov    -0x20(%rbp),%rsi
lea    0xc9b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe76(%rip),%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
jne    1281 <main+0xf1>
mov    0x2e2f(%rip),%r12
movslq (%r12),%rax
sub    %eax,%ebx
je     1281 <main+0xf1>
cmp    $0x3,%ebx
jge    1281 <main+0xf1>
mov    (%r14,%rax,8),%rdi
call   1070 <basename@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
movslq (%r12),%rax
mov    0x8(%r14,%rax,8),%rdi
test   %rdi,%rdi
je     1267 <main+0xd7>
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jge    1267 <main+0xd7>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
movslq (%r12),%rax
mov    0x8(%r14,%rax,8),%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
movslq %ebp,%rax
add    %rax,%r15
movslq (%r12),%rax
mov    0x8(%r14,%rax,8),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1267 <main+0xd7>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%rbx,1)
lea    0xdad(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd6c(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [27 x i8] c"Usage: %s string [suffix]\0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %16 [
]
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %9
%25 = load i32, i32* @optind
%26 = load i32, i32* %4
%27 = icmp eq i32 %25, %26
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i32, i32* %4
%30 = load i32, i32* @optind
%31 = sub nsw i32 %29, %30
%32 = icmp sgt i32 %31, 2
br i1 %32, label %33, label %41
33: ; preds = %28, %24
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %28
%42 = load i8**, i8*** %5
%43 = load i32, i32* @optind
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i8* @basename(i8* %46)
store i8* %47, i8** %7
%48 = load i8*, i8** %7
%49 = call i32 @strlen(i8* %48)
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = load i8*, i8** %7
%54 = load i8*, i8** %7
%55 = call i32 @strlen(i8* %54)
%56 = call i32 @memcpy(i8* %52, i8* %53, i32 %55)
%57 = load i8**, i8*** %5
%58 = load i32, i32* @optind
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %106
64: ; preds = %41
%65 = load i8**, i8*** %5
%66 = load i32, i32* @optind
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %65, i64 %68
%70 = load i8*, i8** %69
%71 = call i32 @strlen(i8* %70)
%72 = load i8*, i8** %7
%73 = call i32 @strlen(i8* %72)
%74 = icmp slt i32 %71, %73
br i1 %74, label %75, label %106
75: ; preds = %64
%76 = load i8*, i8** %7
%77 = call i32 @strlen(i8* %76)
%78 = load i8**, i8*** %5
%79 = load i32, i32* @optind
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %78, i64 %81
%83 = load i8*, i8** %82
%84 = call i32 @strlen(i8* %83)
%85 = sub nsw i32 %77, %84
%86 = load i8*, i8** %8
%87 = sext i32 %85 to i64
%88 = getelementptr inbounds i8, i8* %86, i64 %87
store i8* %88, i8** %8
%89 = load i8*, i8** %8
%90 = load i8**, i8*** %5
%91 = load i32, i32* @optind
%92 = add nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %90, i64 %93
%95 = load i8*, i8** %94
%96 = call i64 @strcmp(i8* %89, i8* %95)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %105
98: ; preds = %75
%99 = load i8*, i8** %7
%100 = load i8*, i8** %8
%101 = call i32 @strlen(i8* %100)
%102 = add nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %99, i64 %103
store i8 0, i8* %104
br label %105
105: ; preds = %98, %75
br label %106
106: ; preds = %105, %64, %41
%107 = load i8*, i8** %7
%108 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %107)
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [27 x i8] c"Usage: %s string [suffix]\0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = load i32, i32* @optind
%13 = icmp eq i32 %12, %0
%14 = sub nsw i32 %0, %12
%15 = icmp sgt i32 %14, 2
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %11
%24 = sext i32 %12 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i8* @basename(i8* %26)
%28 = tail call i32 @strlen(i8* %27)
%29 = tail call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
%31 = tail call i32 @strlen(i8* %27)
%32 = tail call i32 @memcpy(i8* %30, i8* %27, i32 %31)
%33 = load i32, i32* @optind
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %66, label %39
39: ; preds = %23
%40 = tail call i32 @strlen(i8* %37)
%41 = tail call i32 @strlen(i8* %27)
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %66
43: ; preds = %39
%44 = tail call i32 @strlen(i8* %27)
%45 = load i32, i32* @optind
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = tail call i32 @strlen(i8* %49)
%51 = sub nsw i32 %44, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %30, i64 %52
%54 = load i32, i32* @optind
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %1, i64 %56
%58 = load i8*, i8** %57
%59 = tail call i64 @strcmp(i8* %53, i8* %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %43
%62 = tail call i32 @strlen(i8* %53)
%63 = add nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %27, i64 %64
store i8 0, i8* %65
br label %66
66: ; preds = %43, %61, %39, %23
%67 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
ret i32 0
}