#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 */
typedef int /*<<< orphan*/ path;

/* Variables and functions */
char *create_file_name(char *);
int /*<<< orphan*/ fatal(char *);
char *options_get_str(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *find_keymap_file() {
  char *file;
  static char path[4096];
  if ((file = options_get_str("Keymap"))) {
    if (file[0] == '/') {
      strncpy(path, file, sizeof(path));
      if (path[sizeof(path) - 1])
        fatal("Keymap path too long!");
      return path;
    }
    strncpy(path, create_file_name(file), sizeof(path));
    if (path[sizeof(path) - 1])
      fatal("Keymap path too long!");
    return path;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_keymap_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1060 <options_get_str@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f6 <find_keymap_file+0xb6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b0 <find_keymap_file+0x70>
mov    -0x10(%rbp),%rsi
lea    0x2ed3(%rip),%rdi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0x3ec1(%rip)
je     11a0 <find_keymap_file+0x60>
lea    0xe6c(%rip),%rdi
call   1050 <fatal@plt>
lea    0x2ea9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fe <find_keymap_file+0xbe>
mov    -0x10(%rbp),%rdi
call   1040 <create_file_name@plt>
mov    %rax,%rsi
lea    0x2e8d(%rip),%rdi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0x3e7b(%rip)
je     11e6 <find_keymap_file+0xa6>
lea    0xe26(%rip),%rdi
call   1050 <fatal@plt>
lea    0x2e63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fe <find_keymap_file+0xbe>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_keymap_file>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1060 <options_get_str@plt>
test   %rax,%rax
je     1194 <find_keymap_file+0x54>
cmpb   $0x2f,(%rax)
je     115f <find_keymap_file+0x1f>
mov    %rax,%rdi
call   1040 <create_file_name@plt>
lea    0x2eea(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0x3ed2(%rip)
je     1196 <find_keymap_file+0x56>
lea    0xe81(%rip),%rdi
call   1050 <fatal@plt>
lea    0x2ebe(%rip),%rbx
jmp    1196 <find_keymap_file+0x56>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@find_keymap_file.path = internal global [4096 x i8] zeroinitializer
@.str = [7 x i8] c"Keymap\00"
@.str.1 = [22 x i8] c"Keymap path too long!\00"
define i8* @find_keymap_file() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @options_get_str(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %28
5: ; preds = %0
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 47
br i1 %10, label %11, label %19
11: ; preds = %5
%12 = load i8*, i8** %2
%13 = call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), i8* %12, i32 4096)
%14 = load i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 4095)
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @fatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
store i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), i8** %1
br label %29
19: ; preds = %5
%20 = load i8*, i8** %2
%21 = call i8* @create_file_name(i8* %20)
%22 = call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), i8* %21, i32 4096)
%23 = load i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 4095)
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @fatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
store i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), i8** %1
br label %29
28: ; preds = %0
store i8* null, i8** %1
br label %29
29: ; preds = %28, %27, %18
%30 = load i8*, i8** %1
ret i8* %30
}

LLVM IR (-O2):
@find_keymap_file.path = internal global [4096 x i8] zeroinitializer
@.str = [7 x i8] c"Keymap\00"
@.str.1 = [22 x i8] c"Keymap path too long!\00"
define i8* @find_keymap_file() {
%1 = tail call i8* @options_get_str(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %17, label %3
3: ; preds = %0
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 47
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), i8* %1, i32 4096)
%8 = load i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 4095)
%9 = icmp eq i8 %8, 0
br i1 %9, label %17, label %15
10: ; preds = %3
%11 = tail call i8* @create_file_name(i8* %1)
%12 = tail call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), i8* %11, i32 4096)
%13 = load i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 4095)
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10, %6
%16 = tail call i32 @fatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %0, %10, %6
%18 = phi i8* [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), %6 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), %10 ], [ null, %0 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_keymap_file.path, i64 0, i64 0), %15 ]
ret i8* %18
}