#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*/ memset(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strrchr(char *, char);
char *qfits_get_root_name(const char *filename) {
  static char path[4096 + 1];
  char *lastdot;
  if (strlen(filename) > 4096)
    return NULL;
  memset(path, 4096, 0);
  strcpy(path, filename);
  lastdot = strrchr(path, '.');
  if (lastdot == NULL)
    return path;
  if ((!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".FITS")) ||
      (!strcmp(lastdot, ".paf")) || (!strcmp(lastdot, ".PAF")) ||
      (!strcmp(lastdot, ".dat")) || (!strcmp(lastdot, ".DAT")) ||
      (!strcmp(lastdot, ".txt")) || (!strcmp(lastdot, ".TXT")) ||
      (!strcmp(lastdot, ".tfits")) || (!strcmp(lastdot, ".TFITS")) ||
      (!strcmp(lastdot, ".ascii")) || (!strcmp(lastdot, ".ASCII"))) {
    lastdot[0] = (char)0;
  }
  return path;
}


x86 assembly (clang, -O0):
<qfits_get_root_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1000,%eax
jle    117d <qfits_get_root_name+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    130e <qfits_get_root_name+0x1be>
lea    0x2edc(%rip),%rdi
mov    $0x1000,%esi
xor    %edx,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rsi
lea    0x2ec5(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2eb9(%rip),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <qfits_get_root_name+0x80>
lea    0x2e99(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    130e <qfits_get_root_name+0x1be>
mov    -0x18(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xd75(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12fc <qfits_get_root_name+0x1ac>
mov    -0x18(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1303 <qfits_get_root_name+0x1b3>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2d56(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfits_get_root_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x1000,%eax
jle    116c <qfits_get_root_name+0x1c>
xor    %r15d,%r15d
jmp    12a2 <qfits_get_root_name+0x152>
lea    0x2eed(%rip),%r15
mov    %r15,%rdi
mov    $0x1000,%esi
xor    %edx,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     12a2 <qfits_get_root_name+0x152>
mov    %rax,%r14
lea    0xe53(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xe31(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xe1f(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xe0d(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xdfb(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xded(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xddf(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xdd1(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xdc5(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xdb9(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     129e <qfits_get_root_name+0x14e>
lea    0xdad(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    12a2 <qfits_get_root_name+0x152>
movb   $0x0,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@qfits_get_root_name.path = internal global [4097 x i8] zeroinitializer
@.str = [6 x i8] c".fits\00"
@.str.1 = [6 x i8] c".FITS\00"
@.str.2 = [5 x i8] c".paf\00"
@.str.3 = [5 x i8] c".PAF\00"
@.str.4 = [5 x i8] c".dat\00"
@.str.5 = [5 x i8] c".DAT\00"
@.str.6 = [5 x i8] c".txt\00"
@.str.7 = [5 x i8] c".TXT\00"
@.str.8 = [7 x i8] c".tfits\00"
@.str.9 = [7 x i8] c".TFITS\00"
@.str.10 = [7 x i8] c".ascii\00"
@.str.11 = [7 x i8] c".ASCII\00"
define i8* @qfits_get_root_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = icmp sgt i32 %6, 4096
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %69
9: ; preds = %1
%10 = call i32 @memset(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i32 4096, i32 0)
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i8* %11)
%13 = call i8* @strrchr(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i8 signext 46)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %9
store i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i8** %2
br label %69
17: ; preds = %9
%18 = load i8*, i8** %4
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %65
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %65
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %65
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %65
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %65
37: ; preds = %33
%38 = load i8*, i8** %4
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %65
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %65
45: ; preds = %41
%46 = load i8*, i8** %4
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %65
49: ; preds = %45
%50 = load i8*, i8** %4
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = load i8*, i8** %4
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %53
%58 = load i8*, i8** %4
%59 = call i32 @strcmp(i8* %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i8*, i8** %4
%63 = call i32 @strcmp(i8* %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%64 = icmp ne i32 %63, 0
br i1 %64, label %68, label %65
65: ; preds = %61, %57, %53, %49, %45, %41, %37, %33, %29, %25, %21, %17
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i64 0
store i8 0, i8* %67
br label %68
68: ; preds = %65, %61
store i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i8** %2
br label %69
69: ; preds = %68, %16, %8
%70 = load i8*, i8** %2
ret i8* %70
}

LLVM IR (-O2):
@qfits_get_root_name.path = internal global [4097 x i8] zeroinitializer
@.str = [6 x i8] c".fits\00"
@.str.1 = [6 x i8] c".FITS\00"
@.str.2 = [5 x i8] c".paf\00"
@.str.3 = [5 x i8] c".PAF\00"
@.str.4 = [5 x i8] c".dat\00"
@.str.5 = [5 x i8] c".DAT\00"
@.str.6 = [5 x i8] c".txt\00"
@.str.7 = [5 x i8] c".TXT\00"
@.str.8 = [7 x i8] c".tfits\00"
@.str.9 = [7 x i8] c".TFITS\00"
@.str.10 = [7 x i8] c".ascii\00"
@.str.11 = [7 x i8] c".ASCII\00"
define i8* @qfits_get_root_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 4096
br i1 %3, label %46, label %4
4: ; preds = %1
%5 = tail call i32 @memset(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i32 4096, i32 0)
%6 = tail call i32 @strcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i8* %0)
%7 = tail call i8* @strrchr(i8* dereferenceable(1) getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %46, label %9
9: ; preds = %4
%10 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %45, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %45, label %15
15: ; preds = %12
%16 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %45, label %18
18: ; preds = %15
%19 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %45, label %21
21: ; preds = %18
%22 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %45, label %24
24: ; preds = %21
%25 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %45, label %27
27: ; preds = %24
%28 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %45, label %30
30: ; preds = %27
%31 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %45, label %33
33: ; preds = %30
%34 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%35 = icmp eq i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %33
%37 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42, %39, %36, %33, %30, %27, %24, %21, %18, %15, %12, %9
store i8 0, i8* %7
br label %46
46: ; preds = %42, %45, %4, %1
%47 = phi i8* [ null, %1 ], [ getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), %45 ], [ getelementptr inbounds ([4097 x i8], [4097 x i8]* @qfits_get_root_name.path, i64 0, i64 0), %42 ]
ret i8* %47
}