#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*/ die(char *);
int /*<<< orphan*/ fputs_unlocked(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getchar_unlocked();
int /*<<< orphan*/ readchar();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ transform_binary();
int /*<<< orphan*/ transform_code_w_s();
int /*<<< orphan*/ transform_doc(int);
int /*<<< orphan*/ transform_double();
int /*<<< orphan*/ transform_int32();
int /*<<< orphan*/ transform_int64();
int /*<<< orphan*/ transform_objectid();
int /*<<< orphan*/ transform_regex();
int /*<<< orphan*/ transform_string();
void transform_value(char type) {
  switch (type) {
  case '\x01':
    transform_double();
    break;
  case '\x02':
    transform_string();
    break;
  case '\x03':
    transform_doc(0);
    break;
  case '\x04':
    transform_doc(1);
    break;
  case '\x05':
    transform_binary();
    break;
  case '\x06':
    fputs_unlocked("undefined", stdout);
    break;
  case '\x07':
    transform_objectid();
    break;
  case '\x08':
    fputs_unlocked(readchar() ? "true" : "false", stdout);
    break;
  case '\x09':
    transform_int64();
    break;
  case '\x0A':
    fputs_unlocked("null", stdout);
    break;
  case '\x0B':
    transform_regex();
    break;
  case '\x0C':
    transform_string();
    for (int i = 0; i < 12; i++) {
      getchar_unlocked();
    }
    break;
  case '\x0D':
    transform_string();
    break;
  case '\x0E':
    transform_string();
    break;
  case '\x0F':
    transform_code_w_s();
    break;
  case '\x10':
    transform_int32();
    break;
  case '\x11':
    transform_int64();
    break;
  case '\x12':
    transform_int64();
    break;
  case '\xFF':
    fputs_unlocked("\"__minkey\"", stdout);
    break;
  case '\x7F':
    fputs_unlocked("\"__maxkey\"", stdout);
    break;
  default:
    die("Unrecognized element type");
  }
}


x86 assembly (clang, -O0):
<transform_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x80,%eax
ja     1380 <transform_value+0x1b0>
mov    -0x10(%rbp),%rax
lea    0xdff(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1090 <transform_double@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1060 <transform_string@plt>
jmp    138c <transform_value+0x1bc>
xor    %edi,%edi
call   10e0 <transform_doc@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x1,%edi
call   10e0 <transform_doc@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1050 <transform_binary@plt>
jmp    138c <transform_value+0x1bc>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
lea    0xfab(%rip),%rdi
call   1080 <fputs_unlocked@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   10d0 <transform_objectid@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1030 <readchar@plt>
mov    %eax,%ecx
lea    0xf94(%rip),%rdi
lea    0xf88(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs_unlocked@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   10f0 <transform_int64@plt>
jmp    138c <transform_value+0x1bc>
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
lea    0xf5d(%rip),%rdi
call   1080 <fputs_unlocked@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   10a0 <transform_regex@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1060 <transform_string@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jge    12ff <transform_value+0x12f>
mov    $0x0,%al
call   1040 <getchar_unlocked@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12e0 <transform_value+0x110>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1060 <transform_string@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1060 <transform_string@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   1070 <transform_code_w_s@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   10b0 <transform_int32@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   10f0 <transform_int64@plt>
jmp    138c <transform_value+0x1bc>
mov    $0x0,%al
call   10f0 <transform_int64@plt>
jmp    138c <transform_value+0x1bc>
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
lea    0xec2(%rip),%rdi
call   1080 <fputs_unlocked@plt>
jmp    138c <transform_value+0x1bc>
mov    0x2c73(%rip),%rax
mov    (%rax),%esi
lea    0xeb3(%rip),%rdi
call   1080 <fputs_unlocked@plt>
jmp    138c <transform_value+0x1bc>
lea    0xead(%rip),%rdi
call   10c0 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transform_value>:
push   %rax
add    $0x1,%edi
cmp    $0x80,%edi
ja     1212 <transform_value+0x42>
lea    0xe1d(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
pop    %rcx
jmp    1060 <transform_string@plt>
xor    %eax,%eax
pop    %rcx
jmp    10f0 <transform_int64@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0x1012(%rip),%rdi
pop    %rax
jmp    1080 <fputs_unlocked@plt>
lea    0x101b(%rip),%rdi
pop    %rax
jmp    10c0 <die@plt>
xor    %eax,%eax
pop    %rcx
jmp    1090 <transform_double@plt>
xor    %edi,%edi
pop    %rax
jmp    10e0 <transform_doc@plt>
mov    $0x1,%edi
pop    %rax
jmp    10e0 <transform_doc@plt>
xor    %eax,%eax
pop    %rcx
jmp    1050 <transform_binary@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
lea    0xfb2(%rip),%rdi
pop    %rax
jmp    1080 <fputs_unlocked@plt>
xor    %eax,%eax
pop    %rcx
jmp    10d0 <transform_objectid@plt>
xor    %eax,%eax
call   1030 <readchar@plt>
test   %eax,%eax
lea    0xfa3(%rip),%rax
lea    0xf97(%rip),%rdi
cmove  %rax,%rdi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
pop    %rax
jmp    1080 <fputs_unlocked@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
lea    0xf7f(%rip),%rdi
pop    %rax
jmp    1080 <fputs_unlocked@plt>
xor    %eax,%eax
pop    %rcx
jmp    10a0 <transform_regex@plt>
xor    %eax,%eax
call   1060 <transform_string@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
call   1040 <getchar_unlocked@plt>
xor    %eax,%eax
pop    %rcx
jmp    1040 <getchar_unlocked@plt>
xor    %eax,%eax
pop    %rcx
jmp    1070 <transform_code_w_s@plt>
xor    %eax,%eax
pop    %rcx
jmp    10b0 <transform_int32@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
lea    0xf05(%rip),%rdi
pop    %rax
jmp    1080 <fputs_unlocked@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"undefined\00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"true\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [5 x i8] c"null\00"
@.str.4 = [11 x i8] c"\22__minkey\22\00"
@.str.5 = [11 x i8] c"\22__maxkey\22\00"
@.str.6 = [26 x i8] c"Unrecognized element type\00"
define void @transform_value(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
switch i32 %5, label %64 [
i32 1, label %6
i32 2, label %8
i32 3, label %10
i32 4, label %12
i32 5, label %14
i32 6, label %16
i32 7, label %19
i32 8, label %21
i32 9, label %28
i32 10, label %30
i32 11, label %33
i32 12, label %35
i32 13, label %46
i32 14, label %48
i32 15, label %50
i32 16, label %52
i32 17, label %54
i32 18, label %56
i32 -1, label %58
i32 127, label %61
]
6: ; preds = %1
%7 = call i32 (...) @transform_double()
br label %66
8: ; preds = %1
%9 = call i32 (...) @transform_string()
br label %66
10: ; preds = %1
%11 = call i32 @transform_doc(i32 0)
br label %66
12: ; preds = %1
%13 = call i32 @transform_doc(i32 1)
br label %66
14: ; preds = %1
%15 = call i32 (...) @transform_binary()
br label %66
16: ; preds = %1
%17 = load i32, i32* @stdout
%18 = call i32 @fputs_unlocked(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %66
19: ; preds = %1
%20 = call i32 (...) @transform_objectid()
br label %66
21: ; preds = %1
%22 = call i32 (...) @readchar()
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%26 = load i32, i32* @stdout
%27 = call i32 @fputs_unlocked(i8* %25, i32 %26)
br label %66
28: ; preds = %1
%29 = call i32 (...) @transform_int64()
br label %66
30: ; preds = %1
%31 = load i32, i32* @stdout
%32 = call i32 @fputs_unlocked(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %66
33: ; preds = %1
%34 = call i32 (...) @transform_regex()
br label %66
35: ; preds = %1
%36 = call i32 (...) @transform_string()
store i32 0, i32* %3
br label %37
37: ; preds = %42, %35
%38 = load i32, i32* %3
%39 = icmp slt i32 %38, 12
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = call i32 (...) @getchar_unlocked()
br label %42
42: ; preds = %40
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %37
45: ; preds = %37
br label %66
46: ; preds = %1
%47 = call i32 (...) @transform_string()
br label %66
48: ; preds = %1
%49 = call i32 (...) @transform_string()
br label %66
50: ; preds = %1
%51 = call i32 (...) @transform_code_w_s()
br label %66
52: ; preds = %1
%53 = call i32 (...) @transform_int32()
br label %66
54: ; preds = %1
%55 = call i32 (...) @transform_int64()
br label %66
56: ; preds = %1
%57 = call i32 (...) @transform_int64()
br label %66
58: ; preds = %1
%59 = load i32, i32* @stdout
%60 = call i32 @fputs_unlocked(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %66
61: ; preds = %1
%62 = load i32, i32* @stdout
%63 = call i32 @fputs_unlocked(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %62)
br label %66
64: ; preds = %1
%65 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %64, %61, %58, %56, %54, %52, %50, %48, %46, %45, %33, %30, %28, %21, %19, %16, %14, %12, %10, %8, %6
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"undefined\00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"true\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [5 x i8] c"null\00"
@.str.4 = [11 x i8] c"\22__minkey\22\00"
@.str.5 = [11 x i8] c"\22__maxkey\22\00"
@.str.6 = [26 x i8] c"Unrecognized element type\00"
define void @transform_value(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %63 [
i32 1, label %3
i32 2, label %5
i32 3, label %7
i32 4, label %9
i32 5, label %11
i32 6, label %13
i32 7, label %16
i32 8, label %18
i32 9, label %24
i32 10, label %26
i32 11, label %29
i32 12, label %31
i32 13, label %45
i32 14, label %47
i32 15, label %49
i32 16, label %51
i32 17, label %53
i32 18, label %55
i32 -1, label %57
i32 127, label %60
]
3: ; preds = %1
%4 = tail call i32 (...) @transform_double()
br label %65
5: ; preds = %1
%6 = tail call i32 (...) @transform_string()
br label %65
7: ; preds = %1
%8 = tail call i32 @transform_doc(i32 0)
br label %65
9: ; preds = %1
%10 = tail call i32 @transform_doc(i32 1)
br label %65
11: ; preds = %1
%12 = tail call i32 (...) @transform_binary()
br label %65
13: ; preds = %1
%14 = load i32, i32* @stdout
%15 = tail call i32 @fputs_unlocked(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %65
16: ; preds = %1
%17 = tail call i32 (...) @transform_objectid()
br label %65
18: ; preds = %1
%19 = tail call i32 (...) @readchar()
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%22 = load i32, i32* @stdout
%23 = tail call i32 @fputs_unlocked(i8* %21, i32 %22)
br label %65
24: ; preds = %1
%25 = tail call i32 (...) @transform_int64()
br label %65
26: ; preds = %1
%27 = load i32, i32* @stdout
%28 = tail call i32 @fputs_unlocked(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %65
29: ; preds = %1
%30 = tail call i32 (...) @transform_regex()
br label %65
31: ; preds = %1
%32 = tail call i32 (...) @transform_string()
%33 = tail call i32 (...) @getchar_unlocked()
%34 = tail call i32 (...) @getchar_unlocked()
%35 = tail call i32 (...) @getchar_unlocked()
%36 = tail call i32 (...) @getchar_unlocked()
%37 = tail call i32 (...) @getchar_unlocked()
%38 = tail call i32 (...) @getchar_unlocked()
%39 = tail call i32 (...) @getchar_unlocked()
%40 = tail call i32 (...) @getchar_unlocked()
%41 = tail call i32 (...) @getchar_unlocked()
%42 = tail call i32 (...) @getchar_unlocked()
%43 = tail call i32 (...) @getchar_unlocked()
%44 = tail call i32 (...) @getchar_unlocked()
br label %65
45: ; preds = %1
%46 = tail call i32 (...) @transform_string()
br label %65
47: ; preds = %1
%48 = tail call i32 (...) @transform_string()
br label %65
49: ; preds = %1
%50 = tail call i32 (...) @transform_code_w_s()
br label %65
51: ; preds = %1
%52 = tail call i32 (...) @transform_int32()
br label %65
53: ; preds = %1
%54 = tail call i32 (...) @transform_int64()
br label %65
55: ; preds = %1
%56 = tail call i32 (...) @transform_int64()
br label %65
57: ; preds = %1
%58 = load i32, i32* @stdout
%59 = tail call i32 @fputs_unlocked(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %58)
br label %65
60: ; preds = %1
%61 = load i32, i32* @stdout
%62 = tail call i32 @fputs_unlocked(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %61)
br label %65
63: ; preds = %1
%64 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %65
65: ; preds = %31, %63, %60, %57, %55, %53, %51, %49, %47, %45, %29, %26, %24, %18, %16, %13, %11, %9, %7, %5, %3
ret void
}