#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ pedigree_load_keymap(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
void install(char *filename) {
  int len = strlen(filename);
  if (len < 4 || filename[len - 3] != 'k' || filename[len - 2] != 'm' ||
      filename[len - 1] != 'c') {
    printf("Warning: Filename does not end in '.kmc' - are you sure this is a "
           "compiled keymap file?\n");
    printf("*** If you load an invalid keymap your system will be rendered "
           "unusable without a manual reboot. ***\n");
    printf("\nContinue? [no] ");
    char input[64];
    scanf("%s", input);
    if (strcmp(input, "yes")) {
      printf("Aborted, no change took place.\n");
      exit(0);
    }
  }
  FILE *stream = fopen(filename, "r");
  if (!stream) {
    fprintf(stderr, "Error opening file `%s'.\n", filename);
    return;
  }
  fseek(stream, 0, SEEK_END);
  len = ftell(stream);
  fseek(stream, 0, SEEK_SET);
  char *buffer = (char *)malloc(len);
  fread(buffer, 1, len, stream);
  fclose(stream);
  if (pedigree_load_keymap(buffer, len))
    fprintf(stderr, "Error loading keymap.\n");
  else
    printf("Keymap loaded.\n");
  exit(0);
}


x86 assembly (clang, -O0):
<install>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jl     1240 <install+0x70>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6b,%eax
jne    1240 <install+0x70>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6d,%eax
jne    1240 <install+0x70>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x63,%eax
je     12a6 <install+0xd6>
lea    0xdb9(%rip),%rdi
call   1060 <printf@plt>
lea    0xe06(%rip),%rdi
call   1060 <printf@plt>
lea    0xe60(%rip),%rdi
call   1060 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   10d0 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12a1 <install+0xd1>
lea    0xe42(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    12a6 <install+0xd6>
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    12e6 <install+0x116>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret
mov    -0x58(%rbp),%rdi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x58(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0xc(%rbp)
mov    -0x58(%rbp),%rdi
mov    0x2cbf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0xc(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x58(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <pedigree_load_keymap@plt>
cmp    $0x0,%rax
je     1376 <install+0x1a6>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1382 <install+0x1b2>
lea    0xdad(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<install>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
call   1060 <strlen@plt>
cmp    $0x4,%eax
jl     1210 <install+0x30>
lea    -0x3(%rax),%ecx
cmpb   $0x6b,(%rbx,%rcx,1)
jne    1210 <install+0x30>
lea    -0x2(%rax),%ecx
cmpb   $0x6d,(%rbx,%rcx,1)
jne    1210 <install+0x30>
add    $0xffffffff,%eax
cmpb   $0x63,(%rbx,%rax,1)
je     125a <install+0x7a>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd1(%rip),%rdi
call   1070 <printf@plt>
lea    0xdd6(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   10e0 <scanf@plt>
lea    0xdc7(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1291 <install+0xb1>
lea    0xdb7(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    129a <install+0xba>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe7f(%rip),%rdi
jmp    1307 <install+0x127>
mov    %rax,%r14
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %r14,%rdi
call   10b0 <ftell@plt>
mov    %eax,%ebp
mov    0x2d0f(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %ebp,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <pedigree_load_keymap@plt>
test   %rax,%rax
jne    1313 <install+0x133>
lea    0xd44(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xd11(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [89 x i8] c"Warning: Filename does not end in '.kmc' - are you sure this is a compiled keymap file?\0A\00"
@.str.1 = [102 x i8] c"*** If you load an invalid keymap your system will be rendered unusable without a manual reboot. ***\0A\00"
@.str.2 = [17 x i8] c"\0AContinue? [no] \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"yes\00"
@.str.5 = [32 x i8] c"Aborted, no change took place.\0A\00"
@.str.6 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.7 = [26 x i8] c"Error opening file `%s'.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [23 x i8] c"Error loading keymap.\0A\00"
@.str.9 = [16 x i8] c"Keymap loaded.\0A\00"
define void @install(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 4
br i1 %10, label %38, label %11
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 107
br i1 %19, label %38, label %20
20: ; preds = %11
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 109
br i1 %28, label %38, label %29
29: ; preds = %20
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 99
br i1 %37, label %38, label %51
38: ; preds = %29, %20, %11, %1
%39 = call i32 @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %38
%48 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %38
br label %51
51: ; preds = %50, %29
%52 = load i8*, i8** %2
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %53, i32** %5
%54 = load i32*, i32** %5
%55 = icmp ne i32* %54, null
br i1 %55, label %60, label %56
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %2
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %58)
ret void
60: ; preds = %51
%61 = load i32*, i32** %5
%62 = load i32, i32* @SEEK_END
%63 = call i32 @fseek(i32* %61, i32 0, i32 %62)
%64 = load i32*, i32** %5
%65 = call i32 @ftell(i32* %64)
store i32 %65, i32* %3
%66 = load i32*, i32** %5
%67 = load i32, i32* @SEEK_SET
%68 = call i32 @fseek(i32* %66, i32 0, i32 %67)
%69 = load i32, i32* %3
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to i8*
store i8* %71, i8** %6
%72 = load i8*, i8** %6
%73 = load i32, i32* %3
%74 = load i32*, i32** %5
%75 = call i32 @fread(i8* %72, i32 1, i32 %73, i32* %74)
%76 = load i32*, i32** %5
%77 = call i32 @fclose(i32* %76)
%78 = load i8*, i8** %6
%79 = load i32, i32* %3
%80 = call i64 @pedigree_load_keymap(i8* %78, i32 %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %60
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %87
85: ; preds = %60
%86 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.2 = [17 x i8] c"\0AContinue? [no] \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"yes\00"
@.str.6 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.7 = [26 x i8] c"Error opening file `%s'.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [23 x i8] c"Error loading keymap.\0A\00"
@str = [15 x i8] c"Keymap loaded.\00"
@str.10 = [88 x i8] c"Warning: Filename does not end in '.kmc' - are you sure this is a compiled keymap file?\00"
@str.11 = [101 x i8] c"*** If you load an invalid keymap your system will be rendered unusable without a manual reboot. ***\00"
@str.12 = [31 x i8] c"Aborted, no change took place.\00"
define void @install(i8* %0) {
%2 = alloca [64 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, 4
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = add nsw i32 %3, -3
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 107
br i1 %10, label %11, label %23
11: ; preds = %5
%12 = add nsw i32 %3, -2
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 109
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = add nsw i32 %3, -1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 99
br i1 %22, label %35, label %23
23: ; preds = %17, %11, %5, %1
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.10, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([101 x i8], [101 x i8]* @str.11, i64 0, i64 0))
%26 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %23
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.12, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %23
br label %35
35: ; preds = %34, %17
%36 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %0)
ret void
41: ; preds = %35
%42 = load i32, i32* @SEEK_END
%43 = call i32 @fseek(i32* %36, i32 0, i32 %42)
%44 = call i32 @ftell(i32* %36)
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @fseek(i32* %36, i32 0, i32 %45)
%47 = call i64 @malloc(i32 %44)
%48 = inttoptr i64 %47 to i8*
%49 = call i32 @fread(i8* %48, i32 1, i32 %44, i32* %36)
%50 = call i32 @fclose(i32* %36)
%51 = call i64 @pedigree_load_keymap(i8* %48, i32 %44)
%52 = icmp eq i64 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %41
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %58
56: ; preds = %41
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = call i32 @exit(i32 0)
unreachable
}