#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ inputeventnewname(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strdup(char *);
int strtoinputevent(char *, int *);
char *strtok(char *, char *);
int strtoul(char *, char **, int /*<<< orphan*/);
int inputeventloadmap(const char *file) {
  FILE *fp;
  char *line = NULL, *tok, *endp;
  size_t linesize = 0;
  int ret, type, code;
  fp = fopen(file, "r");
  if (!fp)
    goto fail_open;
  while (1) {
    ret = getline(&line, &linesize, fp);
    if (ret == 0 || (ret < 0 && feof(fp)))
      break;
    else if (ret < 0)
      goto failed;
    if (*line == '#')
      continue;
    tok = strtok(line, "\t \r\n\v\f");
    code = strtoul(tok, &endp, 0);
    type = 0x01;
    if (endp > tok) {
      if (*endp == ':') {
        type = code;
        code = strtoul(endp + 1, NULL, 0);
      }
    } else {
      code = strtoinputevent(tok, &type);
      if (code < 0) {
        fprintf(stderr, "input event code '%s' unknown", tok);
        continue;
      }
    }
    inputeventnewname(type, code, strdup(strtok(NULL, "\t \r\n\v\f") ?: ""));
  }
  fclose(fp);
  return 0;
failed:
  if (line)
    free(line);
  fclose(fp);
fail_open:
  return -1;
}


x86 assembly (clang, -O0):
<inputeventloadmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <inputeventloadmap+0x40>
jmp    139b <inputeventloadmap+0x1eb>
jmp    11f5 <inputeventloadmap+0x45>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1230 <inputeventloadmap+0x80>
cmpl   $0x0,-0x3c(%rbp)
jge    1235 <inputeventloadmap+0x85>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1235 <inputeventloadmap+0x85>
jmp    1369 <inputeventloadmap+0x1b9>
cmpl   $0x0,-0x3c(%rbp)
jge    1244 <inputeventloadmap+0x94>
jmp    137e <inputeventloadmap+0x1ce>
jmp    1249 <inputeventloadmap+0x99>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    125e <inputeventloadmap+0xae>
jmp    11f5 <inputeventloadmap+0x45>
mov    -0x20(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x44(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    12ca <inputeventloadmap+0x11a>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    12c5 <inputeventloadmap+0x115>
mov    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x44(%rbp)
jmp    1307 <inputeventloadmap+0x157>
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10c0 <strtoinputevent@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1302 <inputeventloadmap+0x152>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd11(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11f5 <inputeventloadmap+0x45>
jmp    1307 <inputeventloadmap+0x157>
mov    -0x40(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x54(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xce4(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     133e <inputeventloadmap+0x18e>
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    134e <inputeventloadmap+0x19e>
lea    0xcc3(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    134e <inputeventloadmap+0x19e>
mov    -0x60(%rbp),%rdi
call   10d0 <strdup@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    %eax,%edx
call   1050 <inputeventnewname@plt>
jmp    11f5 <inputeventloadmap+0x45>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a2 <inputeventloadmap+0x1f2>
cmpq   $0x0,-0x20(%rbp)
je     1392 <inputeventloadmap+0x1e2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputeventloadmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe29(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12fa <inputeventloadmap+0x14a>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   10b0 <getline@plt>
test   %eax,%eax
je     12f6 <inputeventloadmap+0x146>
lea    0x10(%rsp),%r14
lea    0x18(%rsp),%r15
jmp    1270 <inputeventloadmap+0xc0>
xchg   %ax,%ax
mov    %r13,%rdi
lea    0xc(%rsp),%rsi
call   10c0 <strtoinputevent@plt>
mov    %eax,%ebp
test   %eax,%eax
js     12d9 <inputeventloadmap+0x129>
mov    0xc(%rsp),%ebx
xor    %edi,%edi
lea    0xdce(%rip),%rsi
call   1090 <strtok@plt>
test   %rax,%rax
lea    0xdc5(%rip),%rcx
cmove  %rcx,%rax
mov    %rax,%rdi
call   10d0 <strdup@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <inputeventnewname@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <getline@plt>
test   %eax,%eax
je     12f6 <inputeventloadmap+0x146>
test   %eax,%eax
js     1301 <inputeventloadmap+0x151>
mov    0x10(%rsp),%rdi
cmpb   $0x23,(%rdi)
je     125a <inputeventloadmap+0xaa>
lea    0xd79(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,%r13
mov    %rax,%rdi
lea    0x20(%rsp),%rsi
xor    %edx,%edx
call   10a0 <strtoul@plt>
movl   $0x1,0xc(%rsp)
mov    0x20(%rsp),%rdi
cmp    %r13,%rdi
jbe    1210 <inputeventloadmap+0x60>
mov    %eax,%ebp
cmpb   $0x3a,(%rdi)
jne    1227 <inputeventloadmap+0x77>
mov    %ebp,0xc(%rsp)
add    $0x1,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %eax,%ebp
jmp    1227 <inputeventloadmap+0x77>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
jmp    125a <inputeventloadmap+0xaa>
xor    %ebp,%ebp
jmp    1324 <inputeventloadmap+0x174>
mov    $0xffffffff,%ebp
jmp    132c <inputeventloadmap+0x17c>
mov    %r12,%rdi
call   1070 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1324 <inputeventloadmap+0x174>
mov    0x10(%rsp),%rdi
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1324 <inputeventloadmap+0x174>
call   1030 <free@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"\09 \0D\0A\0B\0C\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"input event code '%s' unknown\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @inputeventloadmap(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %5
store i64 0, i64* %8
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
br label %94
17: ; preds = %1
br label %18
18: ; preds = %17, %41, %66, %78
%19 = load i32*, i32** %4
%20 = call i32 @getline(i8** %5, i64* %8, i32* %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32*, i32** %4
%28 = call i64 @feof(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26, %18
br label %82
31: ; preds = %26, %23
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
br label %85
35: ; preds = %31
br label %36
36: ; preds = %35
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 35
br i1 %40, label %41, label %42
41: ; preds = %36
br label %18
42: ; preds = %36
%43 = load i8*, i8** %5
%44 = call i8* @strtok(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %44, i8** %6
%45 = load i8*, i8** %6
%46 = call i32 @strtoul(i8* %45, i8** %7, i32 0)
store i32 %46, i32* %11
store i32 1, i32* %10
%47 = load i8*, i8** %7
%48 = load i8*, i8** %6
%49 = icmp ugt i8* %47, %48
br i1 %49, label %50, label %61
50: ; preds = %42
%51 = load i8*, i8** %7
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 58
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = load i32, i32* %11
store i32 %56, i32* %10
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i32 @strtoul(i8* %58, i8** null, i32 0)
store i32 %59, i32* %11
br label %60
60: ; preds = %55, %50
br label %71
61: ; preds = %42
%62 = load i8*, i8** %6
%63 = call i32 @strtoinputevent(i8* %62, i32* %10)
store i32 %63, i32* %11
%64 = load i32, i32* %11
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %6
%69 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %68)
br label %18
70: ; preds = %61
br label %71
71: ; preds = %70, %60
%72 = load i32, i32* %10
%73 = load i32, i32* %11
%74 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %77
76: ; preds = %71
br label %78
77: ; preds = %71
br label %78
78: ; preds = %77, %76
%79 = phi i8* [ %74, %76 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), %77 ]
%80 = call i32 @strdup(i8* %79)
%81 = call i32 @inputeventnewname(i32 %72, i32 %73, i32 %80)
br label %18
82: ; preds = %30
%83 = load i32*, i32** %4
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %2
br label %95
85: ; preds = %34
%86 = load i8*, i8** %5
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8*, i8** %5
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %88, %85
%92 = load i32*, i32** %4
%93 = call i32 @fclose(i32* %92)
br label %94
94: ; preds = %91, %16
store i32 -1, i32* %2
br label %95
95: ; preds = %94, %82
%96 = load i32, i32* %2
ret i32 %96
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"\09 \0D\0A\0B\0C\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"input event code '%s' unknown\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @inputeventloadmap(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%7 = bitcast i8** %3 to i8*
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = bitcast i32* %5 to i8*
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %61, label %12
12: ; preds = %1
%13 = call i32 @getline(i8** %2, i64* %4, i32* %10)
%14 = icmp eq i32 %13, 0
br i1 %14, label %58, label %15
15: ; preds = %12, %42
%16 = phi i32 [ %43, %42 ], [ %13, %12 ]
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i64 @feof(i32* %10)
%20 = icmp eq i64 %19, 0
br i1 %20, label %53, label %58
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 35
br i1 %24, label %42, label %25
25: ; preds = %21
%26 = call i8* @strtok(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @strtoul(i8* %26, i8** %3, i32 0)
store i32 1, i32* %5
%28 = load i8*, i8** %3
%29 = icmp ugt i8* %28, %26
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i8, i8* %28
%32 = icmp eq i8 %31, 58
br i1 %32, label %33, label %45
33: ; preds = %30
store i32 %27, i32* %5
%34 = getelementptr inbounds i8, i8* %28, i64 1
%35 = call i32 @strtoul(i8* nocapture %34, i8** null, i32 0)
br label %45
36: ; preds = %25
%37 = call i32 @strtoinputevent(i8* %26, i32* %5)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %42
42: ; preds = %39, %45, %21
%43 = call i32 @getline(i8** %2, i64* %4, i32* %10)
%44 = icmp eq i32 %43, 0
br i1 %44, label %58, label %15
45: ; preds = %36, %30, %33
%46 = phi i32 [ %35, %33 ], [ %27, %30 ], [ %37, %36 ]
%47 = load i32, i32* %5
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%49 = icmp eq i8* %48, null
%50 = select i1 %49, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* %48
%51 = call i32 @strdup(i8* %50)
%52 = call i32 @inputeventnewname(i32 %47, i32 %46, i32 %51)
br label %42
53: ; preds = %18
%54 = load i8*, i8** %2
%55 = icmp eq i8* %54, null
br i1 %55, label %58, label %56
56: ; preds = %53
%57 = call i32 @free(i8* %54)
br label %58
58: ; preds = %42, %53, %56, %18, %12
%59 = phi i32 [ 0, %12 ], [ 0, %18 ], [ -1, %56 ], [ -1, %53 ], [ 0, %42 ]
%60 = call i32 @fclose(i32* %10)
br label %61
61: ; preds = %58, %1
%62 = phi i32 [ -1, %1 ], [ %59, %58 ]
ret i32 %62
}