#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 *, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int read_uint(char *, unsigned int, int);
int /*<<< orphan*/ stderr;
char *version_name(unsigned int);
void parse_ch_supported_versions(char *data, unsigned offset, unsigned length,
                                 int json) {
  unsigned pos = offset;
  unsigned versions_length = read_uint(data, pos, 1);
  unsigned version_code;
  const char *name = NULL;
  int i = 0;
  pos += 1;
  if (json)
    printf("\"version_list\": [");
  for (; pos < offset + length; pos += 2) {
    if (json && i != 0)
      printf(", ");
    version_code = read_uint(data, pos, 2);
    name = version_name(version_code);
    if (name == NULL) {
      name = "unknown";
      fprintf(stderr, "WARNING! Unknown version (%#.4x)\n", version_code);
    }
    if (json)
      printf("{\"name\": \"%s\", \"id\": \"%#.4x\"}", name, version_code);
    else
      printf("\t\t%s\n", name);
    i++;
  }
  if (json)
    printf("]");
}


x86 assembly (clang, -O0):
<parse_ch_supported_versions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1060 <read_uint@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119f <parse_ch_supported_versions+0x5f>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a4 <parse_ch_supported_versions+0x64>
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jae    1272 <parse_ch_supported_versions+0x132>
cmpl   $0x0,-0x14(%rbp)
je     11d7 <parse_ch_supported_versions+0x97>
cmpl   $0x0,-0x2c(%rbp)
je     11d7 <parse_ch_supported_versions+0x97>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1060 <read_uint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <version_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1225 <parse_ch_supported_versions+0xe5>
lea    0xe0c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1249 <parse_ch_supported_versions+0x109>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125b <parse_ch_supported_versions+0x11b>
mov    -0x28(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <parse_ch_supported_versions+0x64>
cmpl   $0x0,-0x14(%rbp)
je     128a <parse_ch_supported_versions+0x14a>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ch_supported_versions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
mov    $0x1,%edx
call   1070 <read_uint@plt>
lea    0x1(%r12),%ebp
test   %ebx,%ebx
je     1187 <parse_ch_supported_versions+0x37>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r12d,%r15d
cmp    %r15d,%ebp
jae    1240 <parse_ch_supported_versions+0xf0>
xor    %r13d,%r13d
jmp    11bd <parse_ch_supported_versions+0x6d>
nopl   0x0(%rax,%rax,1)
lea    0xeb6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x2,%ebp
cmp    %r15d,%ebp
jae    1240 <parse_ch_supported_versions+0xf0>
add    $0xffffffff,%r13d
setb   %al
test   %ebx,%ebx
je     11da <parse_ch_supported_versions+0x8a>
test   %al,%al
je     11da <parse_ch_supported_versions+0x8a>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1070 <read_uint@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1030 <version_name@plt>
test   %rax,%rax
je     1200 <parse_ch_supported_versions+0xb0>
test   %ebx,%ebx
jne    1227 <parse_ch_supported_versions+0xd7>
jmp    11a0 <parse_ch_supported_versions+0x50>
xchg   %ax,%ax
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
mov    %r12d,%edx
call   1060 <fprintf@plt>
lea    0xdf6(%rip),%rax
test   %ebx,%ebx
je     11a0 <parse_ch_supported_versions+0x50>
lea    0xe11(%rip),%rdi
mov    %rax,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11b1 <parse_ch_supported_versions+0x61>
test   %ebx,%ebx
je     125c <parse_ch_supported_versions+0x10c>
mov    $0x5d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\22version_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.3 = [34 x i8] c"WARNING! Unknown version (%#.4x)\0A\00"
@.str.4 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.5 = [6 x i8] c"\09\09%s\0A\00"
@.str.6 = [2 x i8] c"]\00"
define void @parse_ch_supported_versions(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %6
store i32 %14, i32* %9
%15 = load i8*, i8** %5
%16 = load i32, i32* %9
%17 = call i32 @read_uint(i8* %15, i32 %16, i32 1)
store i32 %17, i32* %10
store i8* null, i8** %12
store i32 0, i32* %13
%18 = load i32, i32* %9
%19 = add i32 %18, 1
store i32 %19, i32* %9
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %4
br label %25
25: ; preds = %64, %24
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = add i32 %27, %28
%30 = icmp ult i32 %26, %29
br i1 %30, label %31, label %67
31: ; preds = %25
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* %13
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %34, %31
%40 = load i8*, i8** %5
%41 = load i32, i32* %9
%42 = call i32 @read_uint(i8* %40, i32 %41, i32 2)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = call i8* @version_name(i32 %43)
store i8* %44, i8** %12
%45 = load i8*, i8** %12
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %51
47: ; preds = %39
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %12
%48 = load i32, i32* @stderr
%49 = load i32, i32* %11
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %47, %39
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i8*, i8** %12
%56 = load i32, i32* %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %55, i32 %56)
br label %61
58: ; preds = %51
%59 = load i8*, i8** %12
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %58, %54
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %13
br label %64
64: ; preds = %61
%65 = load i32, i32* %9
%66 = add i32 %65, 2
store i32 %66, i32* %9
br label %25
67: ; preds = %25
%68 = load i32, i32* %8
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"\22version_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.3 = [34 x i8] c"WARNING! Unknown version (%#.4x)\0A\00"
@.str.4 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.5 = [6 x i8] c"\09\09%s\0A\00"
define void @parse_ch_supported_versions(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @read_uint(i8* %0, i32 %1, i32 1)
%6 = add i32 %1, 1
%7 = icmp ne i32 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = add i32 %2, %1
%12 = icmp ult i32 %6, %11
br i1 %12, label %13, label %37
13: ; preds = %10, %33
%14 = phi i32 [ %34, %33 ], [ 0, %10 ]
%15 = phi i32 [ %35, %33 ], [ %6, %10 ]
%16 = icmp ne i32 %14, 0
%17 = select i1 %7, i1 %16, i1 false
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = tail call i32 @read_uint(i8* %0, i32 %15, i32 2)
%22 = tail call i8* @version_name(i32 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %27
27: ; preds = %24, %20
%28 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %24 ], [ %22, %20 ]
br i1 %7, label %29, label %31
29: ; preds = %27
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %28, i32 %21)
br label %33
31: ; preds = %27
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %33
33: ; preds = %31, %29
%34 = add nuw nsw i32 %14, 1
%35 = add i32 %15, 2
%36 = icmp ult i32 %35, %11
br i1 %36, label %13, label %37
37: ; preds = %33, %10
br i1 %7, label %38, label %40
38: ; preds = %37
%39 = tail call i32 @putchar(i32 93)
br label %40
40: ; preds = %38, %37
ret void
}