#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 char *keystr;
typedef char *action;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int apply_keymap_line(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, char *);
char *malloc(int);
void read_keymap(char *filename) {
  FILE *f = fopen(filename, "r");
  char *keystr = malloc(22);
  char *_k = keystr;
  char *action = malloc(102);
  char *_a = action;
  if (!f)
    return;
  fscanf(f, "%20s%100s", keystr, action);
  while (!feof(f))
    apply_keymap_line(keystr, action), fscanf(f, "%20s%100s", keystr, action);
  fclose(f);
  free(_k);
  free(_a);
}


x86 assembly (clang, -O0):
<read_keymap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x16,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x66,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cc <read_keymap+0x5c>
jmp    1247 <read_keymap+0xd7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe23(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1202 <read_keymap+0x92>
jmp    122c <read_keymap+0xbc>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <apply_keymap_line@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xde0(%rip),%rsi
call   1050 <fscanf@plt>
jmp    11e4 <read_keymap+0x74>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_keymap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    $0x16,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x66,%edi
call   1070 <malloc@plt>
test   %rbx,%rbx
je     121b <read_keymap+0xab>
mov    %rax,%r15
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11f8 <read_keymap+0x88>
lea    0xe34(%rip),%r12
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <apply_keymap_line@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d0 <read_keymap+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"%20s%100s\00"
define void @read_keymap(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = call i8* @malloc(i32 22)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
store i8* %11, i8** %5
%12 = call i8* @malloc(i32 102)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
br label %42
17: ; preds = %1
%18 = load i32*, i32** %3
%19 = load i8*, i8** %4
%20 = load i8*, i8** %6
%21 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
br label %22
22: ; preds = %27, %17
%23 = load i32*, i32** %3
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i8*, i8** %6
%30 = call i32 @apply_keymap_line(i8* %28, i8* %29)
%31 = load i32*, i32** %3
%32 = load i8*, i8** %4
%33 = load i8*, i8** %6
%34 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33)
br label %22
35: ; preds = %22
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
%38 = load i8*, i8** %5
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %7
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %35, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"%20s%100s\00"
define void @read_keymap(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 = tail call dereferenceable_or_null(22) i8* @malloc(i32 22)
%4 = tail call dereferenceable_or_null(102) i8* @malloc(i32 102)
%5 = icmp eq i32* %2, null
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4)
%8 = tail call i32 @feof(i32* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6, %10
%11 = tail call i32 @apply_keymap_line(i8* %3, i8* %4)
%12 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4)
%13 = tail call i32 @feof(i32* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %10, label %15
15: ; preds = %10, %6
%16 = tail call i32 @fclose(i32* %2)
%17 = tail call i32 @free(i8* %3)
%18 = tail call i32 @free(i8* %4)
br label %19
19: ; preds = %1, %15
ret void
}