#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);
char *key_share_group_name(unsigned int);
int /*<<< orphan*/ print_hex_blob(char *, unsigned int, unsigned int,
                                  int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int read_uint(char *, unsigned int, int);
int /*<<< orphan*/ stderr;
void parse_sh_key_share(char *data, unsigned offset, unsigned length,
                        int json) {
  unsigned pos = offset;
  unsigned group_code = 0;
  unsigned key_exchange_length = 0;
  const char *name = NULL;
  int i = 0;
  if (json)
    printf("\"key_share\": ");
  group_code = read_uint(data, pos, 2);
  name = key_share_group_name(group_code);
  pos += 2;
  key_exchange_length = read_uint(data, pos, 2);
  pos += 2;
  if (name == NULL) {
    name = "unknown";
    fprintf(stderr, "WARNING! Unknown group code (%#.4x)\n", group_code);
  }
  if (json) {
    printf("{\"name\": \"%s\", \"id\": \"%#.4x\", \"key_exchange_length\": "
           "\"%d\",",
           name, group_code, key_exchange_length);
    printf("\"key_exchange\": \"");
    print_hex_blob(data, pos, key_exchange_length, 0, 0, json);
    printf("\"}");
  } else {
    printf("\t\tgroup: %s (id = %#.4x) key_exchange_length: %d\n", name,
           group_code, key_exchange_length);
    printf("\t\t\tkey_exchange: ");
    print_hex_blob(data, pos, key_exchange_length, 0, 0, 0);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<parse_sh_key_share>:
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)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a0 <parse_sh_key_share+0x50>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1060 <read_uint@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <key_share_group_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1060 <read_uint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1214 <parse_sh_key_share+0xc4>
lea    0xe16(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe07(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1270 <parse_sh_key_share+0x120>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x14(%rbp),%r9d
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1040 <print_hex_blob@plt>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bc <parse_sh_key_share+0x16c>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <print_hex_blob@plt>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_sh_key_share>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %esi,%ebx
mov    %rdi,%r14
test   %ecx,%ecx
je     1185 <parse_sh_key_share+0x25>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
call   1070 <read_uint@plt>
mov    %eax,%r13d
mov    %eax,%edi
call   1080 <key_share_group_name@plt>
mov    %rax,%rbp
lea    0x2(%rbx),%esi
mov    %r14,%rdi
mov    $0x2,%edx
call   1070 <read_uint@plt>
mov    %eax,%r12d
test   %rbp,%rbp
jne    11d8 <parse_sh_key_share+0x78>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    %r13d,%edx
call   1060 <fprintf@plt>
lea    0xe36(%rip),%rbp
add    $0x4,%ebx
test   %r15d,%r15d
je     1236 <parse_sh_key_share+0xd6>
lea    0xe54(%rip),%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r15d,%r9d
call   1050 <print_hex_blob@plt>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe4e(%rip),%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <print_hex_blob@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [14 x i8] c"\22key_share\22: \00"
@.str.1 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"WARNING! Unknown group code (%#.4x)\0A\00"
@.str.3 = [59 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22, \22key_exchange_length\22: \22%d\22,\00"
@.str.4 = [18 x i8] c"\22key_exchange\22: \22\00"
@.str.5 = [3 x i8] c"\22}\00"
@.str.6 = [50 x i8] c"\09\09group: %s (id = %#.4x) key_exchange_length: %d\0A\00"
@.str.7 = [18 x i8] c"\09\09\09key_exchange: \00"
define void @parse_sh_key_share(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = tail call i32 @read_uint(i8* %0, i32 %1, i32 2)
%10 = tail call i8* @key_share_group_name(i32 %9)
%11 = add i32 %1, 2
%12 = tail call i32 @read_uint(i8* %0, i32 %11, i32 2)
%13 = add i32 %1, 4
%14 = icmp eq i8* %10, null
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %15, %8
%19 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %15 ], [ %10, %8 ]
br i1 %5, label %25, label %20
20: ; preds = %18
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %19, i32 %9, i32 %12)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%23 = tail call i32 @print_hex_blob(i8* %0, i32 %13, i32 %12, i32 0, i32 0, i32 %3)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %30
25: ; preds = %18
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %19, i32 %9, i32 %12)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%28 = tail call i32 @print_hex_blob(i8* %0, i32 %13, i32 %12, i32 0, i32 0, i32 0)
%29 = tail call i32 @putchar(i32 10)
br label %30
30: ; preds = %25, %20
ret void
}