#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 const *, char const *);
int strlen(char const *);
int discover_format(const char *filename) {
  static struct {
    const char *suffix;
    int format;
  } formats[] = {{0, 0}};
  int filename_len = strlen(filename);
  int i;
  for (i = 0; formats[i].suffix != 0; ++i) {
    int suffix_len = strlen(formats[i].suffix);
    if (filename_len >= suffix_len &&
        strcasecmp(formats[i].suffix, filename + filename_len - suffix_len) ==
            0)
      return formats[i].format;
  }
  return 0;
}


x86 assembly (clang, -O0):
<discover_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rcx
lea    0x2ef6(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
je     11ef <discover_format+0xcf>
movslq -0x18(%rbp),%rcx
lea    0x2eda(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11dc <discover_format+0xbc>
movslq -0x18(%rbp),%rcx
lea    0x2eb1(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
movslq -0x1c(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11dc <discover_format+0xbc>
movslq -0x18(%rbp),%rcx
lea    0x2e76(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <discover_format+0xd6>
jmp    11e1 <discover_format+0xc1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <discover_format+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<discover_format>:
push   %rax
call   1030 <strlen@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i32 }
@discover_format.formats = internal global [1 x %struct.anon] zeroinitializer
define i32 @discover_format(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %49, %1
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* @discover_format.formats, i64 0, i64 %11
%13 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %52
16: ; preds = %9
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* @discover_format.formats, i64 0, i64 %18
%20 = getelementptr inbounds %struct.anon, %struct.anon* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %4
%24 = load i32, i32* %6
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %48
26: ; preds = %16
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* @discover_format.formats, i64 0, i64 %28
%30 = getelementptr inbounds %struct.anon, %struct.anon* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = load i8*, i8** %3
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = sub i64 0, %37
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = call i64 @strcasecmp(i8* %31, i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %26
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* @discover_format.formats, i64 0, i64 %44
%46 = getelementptr inbounds %struct.anon, %struct.anon* %45, i32 0, i32 1
%47 = load i32, i32* %46
store i32 %47, i32* %2
br label %53
48: ; preds = %26, %16
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %9
52: ; preds = %9
store i32 0, i32* %2
br label %53
53: ; preds = %52, %42
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
define i32 @discover_format(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
ret i32 0
}