#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 */
char *alpn_desc(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int read_uint(char *, unsigned int, int);
void parse_alpns(char *data, unsigned offset, unsigned length, int json) {
  unsigned pos = offset;
  unsigned alpns_length = read_uint(data, pos, 2);
  unsigned alpn_code_length;
  int i = 0;
  pos += 2;
  if (json)
    printf("\"alpn_list\": [");
  for (; pos < offset + length;) {
    alpn_code_length = read_uint(data, pos, 1);
    pos += 1;
    char *alpn_code = (char *)malloc(sizeof(char) * alpn_code_length + 1);
    memcpy(alpn_code, data + pos, alpn_code_length);
    alpn_code[alpn_code_length] = '\0';
    if (json) {
      if (i != 0)
        printf(", ");
      printf("{\"id\": \"%s\"", alpn_code);
    } else
      printf("\t\t%s", alpn_code);
    if (alpn_desc(alpn_code)) {
      if (json)
        printf(", \"description\": \"%s\"", alpn_desc(alpn_code));
      else
        printf(" (%s)", alpn_desc(alpn_code));
    }
    if (json)
      printf("}");
    else
      printf("\n");
    pos += alpn_code_length;
    i++;
  }
  if (json)
    printf("]");
}


x86 assembly (clang, -O0):
<parse_alpns>:
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    $0x2,%edx
call   1050 <read_uint@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a7 <parse_alpns+0x57>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ac <parse_alpns+0x5c>
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jae    12f9 <parse_alpns+0x1a9>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1050 <read_uint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%eax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x14(%rbp)
je     124a <parse_alpns+0xfa>
cmpl   $0x0,-0x24(%rbp)
je     1233 <parse_alpns+0xe3>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125c <parse_alpns+0x10c>
mov    -0x30(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <alpn_desc@plt>
cmp    $0x0,%rax
je     12b7 <parse_alpns+0x167>
cmpl   $0x0,-0x14(%rbp)
je     1298 <parse_alpns+0x148>
mov    -0x30(%rbp),%rdi
call   1030 <alpn_desc@plt>
mov    %rax,%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b2 <parse_alpns+0x162>
mov    -0x30(%rbp),%rdi
call   1030 <alpn_desc@plt>
mov    %rax,%rsi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b7 <parse_alpns+0x167>
cmpl   $0x0,-0x14(%rbp)
je     12d4 <parse_alpns+0x184>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e2 <parse_alpns+0x192>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ac <parse_alpns+0x5c>
cmpl   $0x0,-0x14(%rbp)
je     1311 <parse_alpns+0x1c1>
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_alpns>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,0x10(%rsp)
mov    $0x2,%edx
call   1060 <read_uint@plt>
lea    0x2(%r12),%ebp
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
je     11a0 <parse_alpns+0x40>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r12d,%r14d
mov    %r14d,0x8(%rsp)
cmp    %r14d,%ebp
jae    135d <parse_alpns+0x1fd>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1060 <read_uint@plt>
mov    %eax,%r15d
add    $0x3,%r12d
lea    0x1(%r15),%edi
call   1080 <malloc@plt>
mov    %rax,%r13
lea    (%r12,%rbx,1),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1070 <memcpy@plt>
mov    %r15d,%eax
movb   $0x0,0x0(%r13,%rax,1)
cmpl   $0x0,0x4(%rsp)
je     1223 <parse_alpns+0xc3>
lea    0xe14(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <alpn_desc@plt>
mov    $0x7d,%ebx
test   %rax,%rax
je     1262 <parse_alpns+0x102>
lea    0xe02(%rip),%r14
jmp    124d <parse_alpns+0xed>
lea    0xdf4(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <alpn_desc@plt>
mov    $0xa,%ebx
test   %rax,%rax
je     1262 <parse_alpns+0x102>
lea    0xdec(%rip),%r14
mov    %r13,%rdi
call   1030 <alpn_desc@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1040 <putchar@plt>
add    %r12d,%r15d
jmp    127b <parse_alpns+0x11b>
xchg   %ax,%ax
mov    %r12d,%edi
call   1040 <putchar@plt>
add    %ebx,%r15d
cmp    0x8(%rsp),%r15d
jae    135d <parse_alpns+0x1fd>
mov    %r15d,%ebp
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1060 <read_uint@plt>
mov    %eax,%r15d
lea    0x1(%rbp),%eax
mov    %eax,0xc(%rsp)
lea    0x1(%r15),%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %ebp,%eax
lea    (%rax,%rbx,1),%rsi
add    $0x1,%rsi
mov    %r13,%rdi
mov    %r15d,%edx
call   1070 <memcpy@plt>
mov    %r15d,%eax
movb   $0x0,0x0(%r13,%rax,1)
cmpl   $0x0,0x4(%rsp)
je     1310 <parse_alpns+0x1b0>
lea    0xd2f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd24(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <alpn_desc@plt>
mov    $0x7d,%r12d
lea    0xd16(%rip),%r14
jmp    1336 <parse_alpns+0x1d6>
nop
lea    0xd07(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <alpn_desc@plt>
mov    $0xa,%r12d
lea    0xd03(%rip),%r14
test   %rax,%rax
mov    0xc(%rsp),%ebx
je     1270 <parse_alpns+0x110>
mov    %r13,%rdi
call   1030 <alpn_desc@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1270 <parse_alpns+0x110>
cmpl   $0x0,0x4(%rsp)
je     137c <parse_alpns+0x21c>
mov    $0x5d,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putchar@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\22alpn_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [12 x i8] c"{\22id\22: \22%s\22\00"
@.str.3 = [5 x i8] c"\09\09%s\00"
@.str.4 = [22 x i8] c", \22description\22: \22%s\22\00"
@.str.5 = [6 x i8] c" (%s)\00"
@.str.6 = [2 x i8] c"}\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [2 x i8] c"]\00"
define void @parse_alpns(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 i32
%13 = alloca i8*
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 2)
store i32 %17, i32* %10
store i32 0, i32* %12
%18 = load i32, i32* %9
%19 = add i32 %18, 2
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 ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %4
br label %25
25: ; preds = %91, %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 %97
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = load i32, i32* %9
%34 = call i32 @read_uint(i8* %32, i32 %33, i32 1)
store i32 %34, i32* %11
%35 = load i32, i32* %9
%36 = add i32 %35, 1
store i32 %36, i32* %9
%37 = load i32, i32* %11
%38 = zext i32 %37 to i64
%39 = mul i64 1, %38
%40 = add i64 %39, 1
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %13
%44 = load i8*, i8** %13
%45 = load i8*, i8** %5
%46 = load i32, i32* %9
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i32, i32* %11
%50 = call i32 @memcpy(i8* %44, i8* %48, i32 %49)
%51 = load i8*, i8** %13
%52 = load i32, i32* %11
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %31
%58 = load i32, i32* %12
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %60, %57
%63 = load i8*, i8** %13
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %63)
br label %68
65: ; preds = %31
%66 = load i8*, i8** %13
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %65, %62
%69 = load i8*, i8** %13
%70 = call i8* @alpn_desc(i8* %69)
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %84
72: ; preds = %68
%73 = load i32, i32* %8
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %72
%76 = load i8*, i8** %13
%77 = call i8* @alpn_desc(i8* %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %77)
br label %83
79: ; preds = %72
%80 = load i8*, i8** %13
%81 = call i8* @alpn_desc(i8* %80)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %79, %75
br label %84
84: ; preds = %83, %68
%85 = load i32, i32* %8
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %91
89: ; preds = %84
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %91
91: ; preds = %89, %87
%92 = load i32, i32* %11
%93 = load i32, i32* %9
%94 = add i32 %93, %92
store i32 %94, i32* %9
%95 = load i32, i32* %12
%96 = add nsw i32 %95, 1
store i32 %96, i32* %12
br label %25
97: ; preds = %25
%98 = load i32, i32* %8
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %97
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %102
102: ; preds = %100, %97
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"\22alpn_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [12 x i8] c"{\22id\22: \22%s\22\00"
@.str.3 = [5 x i8] c"\09\09%s\00"
@.str.4 = [22 x i8] c", \22description\22: \22%s\22\00"
@.str.5 = [6 x i8] c" (%s)\00"
define void @parse_alpns(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @read_uint(i8* %0, i32 %1, i32 2)
%6 = add i32 %1, 2
%7 = icmp eq i32 %3, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 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 %73
13: ; preds = %10
%14 = tail call i32 @read_uint(i8* %0, i32 %6, i32 1)
%15 = add i32 %1, 3
%16 = zext i32 %14 to i64
%17 = add i32 %14, 1
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = zext i32 %15 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = tail call i32 @memcpy(i8* %19, i8* %21, i32 %14)
%23 = getelementptr inbounds i8, i8* %19, i64 %16
store i8 0, i8* %23
br i1 %7, label %28, label %24
24: ; preds = %13
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%26 = tail call i8* @alpn_desc(i8* %19)
%27 = icmp eq i8* %26, null
br i1 %27, label %37, label %32
28: ; preds = %13
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%30 = tail call i8* @alpn_desc(i8* %19)
%31 = icmp eq i8* %30, null
br i1 %31, label %37, label %32
32: ; preds = %28, %24
%33 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), %24 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %28 ]
%34 = phi i32 [ 125, %24 ], [ 10, %28 ]
%35 = tail call i8* @alpn_desc(i8* %19)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %33, i8* %35)
br label %37
37: ; preds = %32, %28, %24
%38 = phi i32 [ 125, %24 ], [ 10, %28 ], [ %34, %32 ]
%39 = tail call i32 @putchar(i32 %38)
%40 = add i32 %14, %15
%41 = icmp ult i32 %40, %11
br i1 %41, label %42, label %73
42: ; preds = %37, %68
%43 = phi i32 [ %71, %68 ], [ %40, %37 ]
%44 = tail call i32 @read_uint(i8* %0, i32 %43, i32 1)
%45 = add nuw i32 %43, 1
%46 = zext i32 %44 to i64
%47 = add i32 %44, 1
%48 = tail call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
%50 = zext i32 %45 to i64
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = tail call i32 @memcpy(i8* %49, i8* %51, i32 %44)
%53 = getelementptr inbounds i8, i8* %49, i64 %46
store i8 0, i8* %53
br i1 %7, label %54, label %58
54: ; preds = %42
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%56 = tail call i8* @alpn_desc(i8* %49)
%57 = icmp eq i8* %56, null
br i1 %57, label %68, label %63
58: ; preds = %42
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%61 = tail call i8* @alpn_desc(i8* %49)
%62 = icmp eq i8* %61, null
br i1 %62, label %68, label %63
63: ; preds = %54, %58
%64 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), %58 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %54 ]
%65 = phi i32 [ 125, %58 ], [ 10, %54 ]
%66 = tail call i8* @alpn_desc(i8* %49)
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %64, i8* %66)
br label %68
68: ; preds = %63, %54, %58
%69 = phi i32 [ 125, %58 ], [ 10, %54 ], [ %65, %63 ]
%70 = tail call i32 @putchar(i32 %69)
%71 = add i32 %44, %45
%72 = icmp ult i32 %71, %11
br i1 %72, label %42, label %73
73: ; preds = %68, %37, %10
br i1 %7, label %76, label %74
74: ; preds = %73
%75 = tail call i32 @putchar(i32 93)
br label %76
76: ; preds = %74, %73
ret void
}