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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
unsigned int keycode_from_id(char const *);
char *keycode_to_id(int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  const char *name;
  unsigned code, out;
  int result;
  (void)argc;
  (void)argv;
  result = 0;
  for (code = 0; code < 256; code++) {
    name = keycode_to_id(code);
    if (name != NULL) {
      out = keycode_from_id(name);
      if (out != code) {
        fprintf(stderr,
                "Error: keycode_to_id(0x%02x) = \"%s\", "
                "keycode_from_id(\"%s\") = 0x%02x, expect 0x%02x\n",
                code, name, name, out, code);
        result = 1;
      }
    }
  }
  name = keycode_to_id(-1);
  if (name != NULL) {
    fputs("Error: keycode_to_id(-1) != NULL\n", stderr);
    result = 1;
  }
  static const char *INVAL_NAMES[3] = {"xx", "",
                                       "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"};
  for (code = 0; code < 3; code++) {
    out = keycode_from_id(INVAL_NAMES[code]);
    if (out != 0) {
      fprintf(stderr, "Error: keycode_from_id(\"%s\") = 0x%02x, expect 0\n",
              INVAL_NAMES[code], out);
      result = 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jae    11eb <main+0xab>
mov    -0x1c(%rbp),%edi
call   1060 <keycode_to_id@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d8 <main+0x98>
mov    -0x18(%rbp),%rdi
call   1030 <keycode_from_id@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11d3 <main+0x93>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xe3e(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    11d8 <main+0x98>
jmp    11dd <main+0x9d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1164 <main+0x24>
mov    $0xffffffff,%edi
call   1060 <keycode_to_id@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1220 <main+0xe0>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe40(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jae    1297 <main+0x157>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
lea    0x2e13(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1030 <keycode_from_id@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1284 <main+0x144>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
lea    0x2de8(%rip),%rax
mov    (%rax,%rcx,8),%rdx
mov    -0x20(%rbp),%ecx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    1289 <main+0x149>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1227 <main+0xe7>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e8d(%rip),%r12
lea    0xea6(%rip),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    117b <main+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x100,%ebp
je     11ba <main+0x7a>
mov    %ebp,%edi
call   1060 <keycode_to_id@plt>
test   %rax,%rax
je     1170 <main+0x30>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <keycode_from_id@plt>
cmp    %eax,%ebp
je     1170 <main+0x30>
mov    (%r12),%edi
mov    %ebp,(%rsp)
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
mov    %rbx,%r8
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r15d
jmp    1170 <main+0x30>
mov    $0xffffffff,%edi
call   1060 <keycode_to_id@plt>
test   %rax,%rax
je     11df <main+0x9f>
mov    (%r12),%esi
lea    0xe80(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%r15d
lea    0xe90(%rip),%rdi
call   1030 <keycode_from_id@plt>
test   %eax,%eax
je     1210 <main+0xd0>
mov    (%r12),%edi
lea    0xe9e(%rip),%rsi
lea    0xe75(%rip),%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r15d
lea    0xeb1(%rip),%rdi
call   1030 <keycode_from_id@plt>
test   %eax,%eax
je     1241 <main+0x101>
mov    (%r12),%edi
lea    0xe6d(%rip),%rsi
lea    0xe96(%rip),%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r15d
lea    0xe31(%rip),%rdi
call   1030 <keycode_from_id@plt>
test   %eax,%eax
je     1272 <main+0x132>
mov    (%r12),%edi
lea    0xe3c(%rip),%rsi
lea    0xe16(%rip),%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [84 x i8] c"Error: keycode_to_id(0x%02x) = \22%s\22, keycode_from_id(\22%s\22) = 0x%02x, expect 0x%02x\0A\00"
@.str.1 = [34 x i8] c"Error: keycode_to_id(-1) != NULL\0A\00"
@main.INVAL_NAMES = internal global [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i32 0, i32 0)]
@.str.2 = [3 x i8] c"xx\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [31 x i8] c"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\00"
@.str.5 = [49 x i8] c"Error: keycode_from_id(\22%s\22) = 0x%02x, expect 0\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %7
br label %12
12: ; preds = %36, %2
%13 = load i32, i32* %7
%14 = icmp ult i32 %13, 256
br i1 %14, label %15, label %39
15: ; preds = %12
%16 = load i32, i32* %7
%17 = call i8* @keycode_to_id(i32 %16)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = call i32 @keycode_from_id(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i32, i32* %7
%29 = load i8*, i8** %6
%30 = load i8*, i8** %6
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %29, i8* %30, i32 %31, i32 %32)
store i32 1, i32* %9
br label %34
34: ; preds = %26, %20
br label %35
35: ; preds = %34, %15
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add i32 %37, 1
store i32 %38, i32* %7
br label %12
39: ; preds = %12
%40 = call i8* @keycode_to_id(i32 -1)
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %44)
store i32 1, i32* %9
br label %46
46: ; preds = %43, %39
store i32 0, i32* %7
br label %47
47: ; preds = %67, %46
%48 = load i32, i32* %7
%49 = icmp ult i32 %48, 3
br i1 %49, label %50, label %70
50: ; preds = %47
%51 = load i32, i32* %7
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds [3 x i8*], [3 x i8*]* @main.INVAL_NAMES, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @keycode_from_id(i8* %54)
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %50
%59 = load i32, i32* @stderr
%60 = load i32, i32* %7
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds [3 x i8*], [3 x i8*]* @main.INVAL_NAMES, i64 0, i64 %61
%63 = load i8*, i8** %62
%64 = load i32, i32* %8
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %63, i32 %64)
store i32 1, i32* %9
br label %66
66: ; preds = %58, %50
br label %67
67: ; preds = %66
%68 = load i32, i32* %7
%69 = add i32 %68, 1
store i32 %69, i32* %7
br label %47
70: ; preds = %47
%71 = load i32, i32* %9
ret i32 %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [84 x i8] c"Error: keycode_to_id(0x%02x) = \22%s\22, keycode_from_id(\22%s\22) = 0x%02x, expect 0x%02x\0A\00"
@.str.1 = [34 x i8] c"Error: keycode_to_id(-1) != NULL\0A\00"
@.str.2 = [3 x i8] c"xx\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [31 x i8] c"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\00"
@.str.5 = [49 x i8] c"Error: keycode_from_id(\22%s\22) = 0x%02x, expect 0\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %14
%4 = phi i32 [ 0, %2 ], [ %15, %14 ]
%5 = phi i32 [ 0, %2 ], [ %16, %14 ]
%6 = tail call i8* @keycode_to_id(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = tail call i32 @keycode_from_id(i8* %6)
%10 = icmp eq i32 %9, %5
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %6, i8* %6, i32 %9, i32 %5)
br label %14
14: ; preds = %3, %11, %8
%15 = phi i32 [ 1, %11 ], [ %4, %8 ], [ %4, %3 ]
%16 = add nuw nsw i32 %5, 1
%17 = icmp eq i32 %16, 256
br i1 %17, label %18, label %3
18: ; preds = %14
%19 = tail call i8* @keycode_to_id(i32 -1)
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %18
%25 = phi i32 [ 1, %21 ], [ %15, %18 ]
%26 = tail call i32 @keycode_from_id(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %31
31: ; preds = %24, %28
%32 = phi i32 [ 1, %28 ], [ %25, %24 ]
%33 = tail call i32 @keycode_from_id(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %38
38: ; preds = %35, %31
%39 = phi i32 [ 1, %35 ], [ %32, %31 ]
%40 = tail call i32 @keycode_from_id(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %45
45: ; preds = %42, %38
%46 = phi i32 [ 1, %42 ], [ %39, %38 ]
ret i32 %46
}