#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_key(int, char *, char *);
int /*<<< orphan*/ clear_default_keys(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ keymap_parse_error(int, char *);
char *read_line(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strtok(char *, char *);
void load_key_map(const char *file_name) {
  FILE *file;
  char *line;
  int line_num = 0;
  if (!(file = fopen(file_name, "r")))
    fatal("Can't open keymap file: %s", strerror(errno));
  while ((line = read_line(file))) {
    char *command;
    char *tmp;
    char *key;
    line_num++;
    if (line[0] == '#' || !(command = strtok(line, " \t"))) {
      free(line);
      continue;
    }
    if (!(tmp = strtok(NULL, " \t")) || strcmp(tmp, "="))
      keymap_parse_error(line_num, "expected '='");
    if (!clear_default_keys(command))
      keymap_parse_error(line_num, "unknown command");
    while ((key = strtok(NULL, " \t"))) {
      add_key(line_num, command, key);
    }
    free(line);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<load_key_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11fd <load_key_map+0x4d>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %eax,%esi
lea    0xe0a(%rip),%rdi
call   10d0 <fatal@plt>
jmp    1202 <load_key_map+0x52>
mov    -0x10(%rbp),%rdi
call   1090 <read_line@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     130c <load_key_map+0x15c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1250 <load_key_map+0xa0>
mov    -0x18(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    125e <load_key_map+0xae>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1202 <load_key_map+0x52>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb4(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1296 <load_key_map+0xe6>
mov    -0x30(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12a5 <load_key_map+0xf5>
mov    -0x1c(%rbp),%edi
lea    0xd82(%rip),%rsi
call   1080 <keymap_parse_error@plt>
mov    -0x28(%rbp),%rdi
call   1050 <clear_default_keys@plt>
cmp    $0x0,%eax
jne    12c6 <load_key_map+0x116>
mov    -0x1c(%rbp),%edi
lea    0xd6e(%rip),%rsi
call   1080 <keymap_parse_error@plt>
jmp    12cb <load_key_map+0x11b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd47(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12fe <load_key_map+0x14e>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <add_key@plt>
jmp    12cb <load_key_map+0x11b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1202 <load_key_map+0x52>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_key_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe3e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11eb <load_key_map+0x3b>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xe1e(%rip),%rdi
mov    %eax,%esi
call   10d0 <fatal@plt>
mov    %r14,%rdi
call   1090 <read_line@plt>
test   %rax,%rax
je     12d1 <load_key_map+0x121>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe15(%rip),%r15
lea    0xe13(%rip),%r13
jmp    123c <load_key_map+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1090 <read_line@plt>
mov    %rax,%r12
test   %rax,%rax
je     12d1 <load_key_map+0x121>
add    $0x1,%ebx
cmpb   $0x23,(%r12)
je     1220 <load_key_map+0x70>
mov    %r12,%rdi
mov    %r15,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
je     1220 <load_key_map+0x70>
mov    %rax,%rbp
xor    %edi,%edi
mov    %r15,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
je     127c <load_key_map+0xcc>
mov    %rax,%rdi
lea    0xdae(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1286 <load_key_map+0xd6>
mov    %ebx,%edi
mov    %r13,%rsi
call   1080 <keymap_parse_error@plt>
mov    %rbp,%rdi
call   1050 <clear_default_keys@plt>
test   %eax,%eax
jne    12bd <load_key_map+0x10d>
mov    %ebx,%edi
lea    0xd94(%rip),%rsi
call   1080 <keymap_parse_error@plt>
jmp    12bd <load_key_map+0x10d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1060 <add_key@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
jne    12b0 <load_key_map+0x100>
jmp    1220 <load_key_map+0x70>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Can't open keymap file: %s\00"
@errno = global i32 0
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [13 x i8] c"expected '='\00"
@.str.5 = [16 x i8] c"unknown command\00"
define void @load_key_map(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %5
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %1
br label %17
17: ; preds = %62, %33, %16
%18 = load i32*, i32** %3
%19 = call i8* @read_line(i32* %18)
store i8* %19, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %65
21: ; preds = %17
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 35
br i1 %28, label %33, label %29
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %31, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %36, label %33
33: ; preds = %29, %21
%34 = load i8*, i8** %4
%35 = call i32 @free(i8* %34)
br label %17
36: ; preds = %29
%37 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %37, i8** %7
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i8*, i8** %7
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39, %36
%44 = load i32, i32* %5
%45 = call i32 @keymap_parse_error(i32 %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %43, %39
%47 = load i8*, i8** %6
%48 = call i32 @clear_default_keys(i8* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = load i32, i32* %5
%52 = call i32 @keymap_parse_error(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %50, %46
br label %54
54: ; preds = %57, %53
%55 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %55, i8** %8
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* %5
%59 = load i8*, i8** %6
%60 = load i8*, i8** %8
%61 = call i32 @add_key(i32 %58, i8* %59, i8* %60)
br label %54
62: ; preds = %54
%63 = load i8*, i8** %4
%64 = call i32 @free(i8* %63)
br label %17
65: ; preds = %17
%66 = load i32*, i32** %3
%67 = call i32 @fclose(i32* %66)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Can't open keymap file: %s\00"
@errno = global i32 0
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [13 x i8] c"expected '='\00"
@.str.5 = [16 x i8] c"unknown command\00"
define void @load_key_map(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = tail call i32 @strerror(i32 %5)
%7 = tail call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %4, %1
%9 = tail call i8* @read_line(i32* %2)
%10 = icmp eq i8* %9, null
br i1 %10, label %45, label %11
11: ; preds = %8, %41
%12 = phi i8* [ %43, %41 ], [ %9, %8 ]
%13 = phi i32 [ %14, %41 ], [ 0, %8 ]
%14 = add nuw nsw i32 %13, 1
%15 = load i8, i8* %12
%16 = icmp eq i8 %15, 35
br i1 %16, label %41, label %17
17: ; preds = %11
%18 = tail call i8* @strtok(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %41, label %20
20: ; preds = %17
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23, %20
%27 = tail call i32 @keymap_parse_error(i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = tail call i32 @clear_default_keys(i8* %18)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @keymap_parse_error(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %41, label %36
36: ; preds = %33, %36
%37 = phi i8* [ %39, %36 ], [ %34, %33 ]
%38 = tail call i32 @add_key(i32 %14, i8* %18, i8* %37)
%39 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %36
41: ; preds = %36, %33, %11, %17
%42 = tail call i32 @free(i8* %12)
%43 = tail call i8* @read_line(i32* %2)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %11
45: ; preds = %41, %8
%46 = tail call i32 @fclose(i32* %2)
ret void
}