#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__ strcasecmp(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int fits_filename(char *fn, int fnl) {
  int len;
  len = strlen(fn);
  if (len + 5 >= fnl)
    return 0;
  if (strcasecmp(fn + len - 5, ".fits") == 0)
    return 0;
  if (strcasecmp(fn + len - 4, ".fit") == 0)
    return 0;
  if (strcasecmp(fn + len - 4, ".fts") == 0)
    return 0;
  if (strcasecmp(fn + len - 3, ".gz") == 0) {
    return -1;
  }
  if (strcasecmp(fn + len - 2, ".z") == 0)
    return -1;
  if (strcasecmp(fn + len - 4, ".zip") == 0)
    return -1;
  strcat(fn, ".fits");
  return 1;
}


x86 assembly (clang, -O0):
<fits_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x5,%eax
cmp    -0x14(%rbp),%eax
jl     1166 <fits_filename+0x36>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe84(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1197 <fits_filename+0x67>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe59(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11c8 <fits_filename+0x98>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe2d(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11f9 <fits_filename+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe01(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    122a <fits_filename+0xfa>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xdd4(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    125b <fits_filename+0x12b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xda6(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    128c <fits_filename+0x15c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <fits_filename+0x173>
mov    -0x10(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1050 <strcat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fits_filename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x5(%rax),%ecx
xor    %r14d,%r14d
cmp    %ebp,%ecx
jge    11fa <fits_filename+0xca>
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe9f(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11fa <fits_filename+0xca>
add    %rbx,%rbp
lea    -0x4(%rbp),%r15
lea    0xe89(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11fa <fits_filename+0xca>
lea    0xe7a(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11fa <fits_filename+0xca>
lea    -0x3(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1030 <strcasecmp@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11fa <fits_filename+0xca>
add    $0xfffffffffffffffe,%rbp
lea    0xe50(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11fa <fits_filename+0xca>
lea    0xe3f(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11fa <fits_filename+0xca>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c".fits\00"
@.str.1 = [5 x i8] c".fit\00"
@.str.2 = [5 x i8] c".fts\00"
@.str.3 = [4 x i8] c".gz\00"
@.str.4 = [3 x i8] c".z\00"
@.str.5 = [5 x i8] c".zip\00"
define i32 @fits_filename(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 5
%5 = icmp slt i32 %4, %1
br i1 %5, label %6, label %32
6: ; preds = %2
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -5
%10 = tail call i64 @strcasecmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %8, i64 -4
%14 = tail call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %32, label %16
16: ; preds = %12
%17 = tail call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %8, i64 -3
%21 = tail call i64 @strcasecmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %8, i64 -2
%25 = tail call i64 @strcasecmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = tail call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %27, %23, %19, %16, %12, %6, %2, %30
%33 = phi i32 [ 1, %30 ], [ 0, %2 ], [ 0, %6 ], [ 0, %12 ], [ 0, %16 ], [ -1, %19 ], [ -1, %23 ], [ -1, %27 ]
ret i32 %33
}