#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 */
struct keymap {
  int dummy;
};
typedef int /*<<< orphan*/ error_t;

/* Variables and functions */
int /*<<< orphan*/ parse_plain_keymap(char *, struct keymap **, int);
int /*<<< orphan*/ parse_toml_keymap(char *, struct keymap **, int);
scalar_t__ strcasecmp(char *, char *);
size_t strlen(char *);
error_t parse_keymap(char *fname, struct keymap **keymap, bool verbose) {
  size_t len = strlen(fname);
  if (len >= 5 && strcasecmp(fname + len - 5, ".toml") == 0)
    return parse_toml_keymap(fname, keymap, verbose);
  return parse_plain_keymap(fname, keymap, verbose);
}


x86 assembly (clang, -O0):
<parse_keymap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
jb     11a5 <parse_keymap+0x65>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe82(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11a5 <parse_keymap+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <parse_toml_keymap@plt>
mov    %eax,-0x4(%rbp)
jmp    11b8 <parse_keymap+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <parse_plain_keymap@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_keymap>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1050 <strlen@plt>
cmp    $0x5,%rax
jb     1171 <parse_keymap+0x31>
lea    (%rax,%rbp,1),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1183 <parse_keymap+0x43>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <parse_plain_keymap@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <parse_toml_keymap@plt>

LLVM IR (-O0):
%struct.keymap = type { i32 }
@.str = [6 x i8] c".toml\00"
define i32 @parse_keymap(i8* %0, %struct.keymap** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.keymap**
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %5
store %struct.keymap** %1, %struct.keymap*** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
%11 = load i64, i64* %8
%12 = icmp uge i64 %11, 5
br i1 %12, label %13, label %25
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %8
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -5
%18 = call i64 @strcasecmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load %struct.keymap**, %struct.keymap*** %6
%23 = load i32, i32* %7
%24 = call i32 @parse_toml_keymap(i8* %21, %struct.keymap** %22, i32 %23)
store i32 %24, i32* %4
br label %30
25: ; preds = %13, %3
%26 = load i8*, i8** %5
%27 = load %struct.keymap**, %struct.keymap*** %6
%28 = load i32, i32* %7
%29 = call i32 @parse_plain_keymap(i8* %26, %struct.keymap** %27, i32 %28)
store i32 %29, i32* %4
br label %30
30: ; preds = %25, %20
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.keymap = type { i32 }
@.str = [6 x i8] c".toml\00"
define i32 @parse_keymap(i8* %0, %struct.keymap** %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ugt i64 %4, 4
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 %4
%8 = getelementptr inbounds i8, i8* %7, i64 -5
%9 = tail call i64 @strcasecmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @parse_toml_keymap(i8* %0, %struct.keymap** %1, i32 %2)
br label %15
13: ; preds = %6, %3
%14 = tail call i32 @parse_plain_keymap(i8* %0, %struct.keymap** %1, i32 %2)
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
ret i32 %16
}