#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 */
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *short_progname(char *pname) {
  char *p;
  int len;
  p = pname;
  while (*p != '/' && *p != '\\' && *p != ':' && *p != '\0')
    ++p;
  if (*p == '\0') {
    len = strlen(pname);
    if (len > 4) {
      if ((0 == strcmp(pname + len - 4, ".EXE") ||
           0 == strcmp(pname + len - 4, ".exe")))
        pname[len - 4] = '\0';
    }
    return (pname);
  } else
    return (short_progname(++p));
}


x86 assembly (clang, -O0):
<short_progname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x1d(%rbp)
je     1193 <short_progname+0x63>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x5c,%ecx
mov    %al,-0x1d(%rbp)
je     1193 <short_progname+0x63>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x3a,%ecx
mov    %al,-0x1d(%rbp)
je     1193 <short_progname+0x63>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a3 <short_progname+0x73>
jmp    11b4 <short_progname+0x84>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <short_progname+0x14>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    124f <short_progname+0x11f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jle    1242 <short_progname+0x112>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe10(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     122c <short_progname+0xfc>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xdec(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    123d <short_progname+0x10d>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1242 <short_progname+0x112>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1264 <short_progname+0x134>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x18(%rbp)
call   1030 <short_progname@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<short_progname>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
movabs $0x200000000801,%rax
jmp    1143 <short_progname+0x23>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbx
lea    0x1(%rbx),%rcx
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%rcx),%edx
lea    -0x2f(%rdx),%esi
cmp    $0x2d,%sil
ja     1167 <short_progname+0x47>
movzbl %sil,%esi
bt     %rsi,%rax
jb     1140 <short_progname+0x20>
test   %dl,%dl
je     1171 <short_progname+0x51>
add    $0x1,%rcx
jmp    1150 <short_progname+0x30>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
jl     11bc <short_progname+0x9c>
mov    %eax,%r14d
mov    %eax,%eax
lea    (%rbx,%rax,1),%r15
add    $0xfffffffffffffffc,%r15
lea    0xe6e(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b3 <short_progname+0x93>
lea    0xe5f(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11bc <short_progname+0x9c>
add    $0xfffffffc,%r14d
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c".EXE\00"
@.str.1 = [5 x i8] c".exe\00"
define i8* @short_progname(i8* %0) {
br label %2
2: ; preds = %25, %1
%3 = phi i8* [ %0, %1 ], [ %26, %25 ]
br label %4
4: ; preds = %7, %2
%5 = phi i8* [ %3, %2 ], [ %8, %7 ]
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 0, label %9
i8 47, label %25
i8 58, label %25
i8 92, label %25
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
9: ; preds = %4
%10 = tail call i32 @strlen(i8* %3)
%11 = icmp sgt i32 %10, 4
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = zext i32 %10 to i64
%14 = getelementptr inbounds i8, i8* %3, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -4
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18, %12
%22 = add nsw i32 %10, -4
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %3, i64 %23
store i8 0, i8* %24
br label %27
25: ; preds = %4, %4, %4
%26 = getelementptr inbounds i8, i8* %5, i64 1
br label %2
27: ; preds = %9, %21, %18
ret i8* %3
}