#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int format(const char *filename) {
  size_t len = strlen(filename);
  if (len < sizeof(".dta") - 1)
    return 0x00;
  if (strncmp(filename + len - 4, ".dta", 4) == 0)
    return 0x01;
  if (strncmp(filename + len - 4, ".sav", 4) == 0)
    return 0x02;
  if (strncmp(filename + len - 4, ".por", 4) == 0)
    return 0x04;
  if (strncmp(filename + len - 4, ".xpt", 4) == 0)
    return 0x20;
  if (len < sizeof(".json") - 1)
    return 0x00;
  if (strncmp(filename + len - 5, ".json", 5) == 0)
    return 0x80;
  if (len < sizeof(".sas7bdat") - 1)
    return 0x00;
  if (strncmp(filename + len - 9, ".sas7bdat", 9) == 0)
    return 0x08;
  if (strncmp(filename + len - 9, ".sas7bcat", 9) == 0)
    return 0x10;
  return 0x00;
}


x86 assembly (clang, -O0):
<format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x4,-0x18(%rbp)
jae    1150 <format+0x30>
movl   $0x0,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe9d(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1183 <format+0x63>
movl   $0x1,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe6f(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b6 <format+0x96>
movl   $0x2,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe41(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e9 <format+0xc9>
movl   $0x4,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe13(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121c <format+0xfc>
movl   $0x20,-0x4(%rbp)
jmp    12ea <format+0x1ca>
cmpq   $0x5,-0x18(%rbp)
jae    1233 <format+0x113>
movl   $0x0,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xdce(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1266 <format+0x146>
movl   $0x80,-0x4(%rbp)
jmp    12ea <format+0x1ca>
cmpq   $0x9,-0x18(%rbp)
jae    127d <format+0x15d>
movl   $0x0,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffff7,%rdi
lea    0xd8a(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12b0 <format+0x190>
movl   $0x8,-0x4(%rbp)
jmp    12ea <format+0x1ca>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffff7,%rdi
lea    0xd61(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12e3 <format+0x1c3>
movl   $0x10,-0x4(%rbp)
jmp    12ea <format+0x1ca>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x4,%rax
jae    113c <format+0x1c>
xor    %ebp,%ebp
jmp    124e <format+0x12e>
mov    %rax,%rbx
lea    (%r14,%rax,1),%r15
add    $0xfffffffffffffffc,%r15
lea    0xeb2(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     122d <format+0x10d>
lea    0xe9a(%rip),%rsi
mov    $0x4,%ebp
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1234 <format+0x114>
lea    0xe7d(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     124e <format+0x12e>
lea    0xe65(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     123b <format+0x11b>
cmp    $0x5,%rbx
jb     1135 <format+0x15>
add    %rbx,%r14
lea    -0x5(%r14),%rdi
lea    0xe40(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1242 <format+0x122>
mov    $0x0,%ebp
cmp    $0x9,%rbx
jb     124e <format+0x12e>
add    $0xfffffffffffffff7,%r14
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1249 <format+0x129>
lea    0xe12(%rip),%rsi
mov    %r14,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
shl    $0x4,%ebp
jmp    124e <format+0x12e>
mov    $0x1,%ebp
jmp    124e <format+0x12e>
mov    $0x2,%ebp
jmp    124e <format+0x12e>
mov    $0x20,%ebp
jmp    124e <format+0x12e>
mov    $0x80,%ebp
jmp    124e <format+0x12e>
mov    $0x8,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c".dta\00"
@.str.1 = [5 x i8] c".sav\00"
@.str.2 = [5 x i8] c".por\00"
@.str.3 = [5 x i8] c".xpt\00"
@.str.4 = [6 x i8] c".json\00"
@.str.5 = [10 x i8] c".sas7bdat\00"
@.str.6 = [10 x i8] c".sas7bcat\00"
define i32 @format(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp ult i64 %2, 4
br i1 %3, label %34, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 %2
%6 = getelementptr inbounds i8, i8* %5, i64 -4
%7 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %34, label %9
9: ; preds = %4
%10 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %34, label %12
12: ; preds = %9
%13 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %34, label %15
15: ; preds = %12
%16 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %34, label %18
18: ; preds = %15
%19 = icmp ult i64 %2, 5
br i1 %19, label %34, label %20
20: ; preds = %18
%21 = getelementptr inbounds i8, i8* %5, i64 -5
%22 = tail call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %20
%25 = icmp ult i64 %2, 9
br i1 %25, label %34, label %26
26: ; preds = %24
%27 = getelementptr inbounds i8, i8* %5, i64 -9
%28 = tail call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 9)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = tail call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 9)
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 16, i32 0
br label %34
34: ; preds = %30, %26, %24, %20, %18, %15, %12, %9, %4, %1
%35 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 2, %9 ], [ 4, %12 ], [ 32, %15 ], [ 0, %18 ], [ 128, %20 ], [ 0, %24 ], [ 8, %26 ], [ %33, %30 ]
ret i32 %35
}