#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 *, ...);
char *psk_key_exchange_mode_name(unsigned int);
unsigned int read_uint(char *, unsigned int, int);
int /*<<< orphan*/ stderr;
void parse_ch_psk_key_exchange_modes(char *data, unsigned offset,
                                     unsigned length, int json) {
  unsigned pos = offset;
  unsigned psk_key_exchange_modes_length = read_uint(data, pos, 1);
  unsigned mode_code = 0;
  const char *name = NULL;
  int i = 0;
  pos += 1;
  if (json)
    printf("\"psk_key_exchange_mode_list\": [");
  for (; pos < offset + length; pos += 1) {
    if (json && i != 0)
      printf(", ");
    mode_code = read_uint(data, pos, 1);
    name = psk_key_exchange_mode_name(mode_code);
    if (name == NULL) {
      name = "unknown";
      fprintf(stderr, "WARNING! Unknown PSK key exchange mode code (%#.4x)\n",
              mode_code);
    }
    if (json) {
      printf("{\"name\": \"%s\", \"id\": \"%#.4x\"}", name, mode_code);
    } else {
      printf("\t\tpsk key exchange mode: %s (id = %#.4x)\n", name, mode_code);
    }
    i++;
  }
  if (json)
    printf("]");
}


x86 assembly (clang, -O0):
<parse_ch_psk_key_exchange_modes>:
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   1050 <read_uint@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%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     11a6 <parse_ch_psk_key_exchange_modes+0x66>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ab <parse_ch_psk_key_exchange_modes+0x6b>
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jae    127c <parse_ch_psk_key_exchange_modes+0x13c>
cmpl   $0x0,-0x14(%rbp)
je     11de <parse_ch_psk_key_exchange_modes+0x9e>
cmpl   $0x0,-0x2c(%rbp)
je     11de <parse_ch_psk_key_exchange_modes+0x9e>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1050 <read_uint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <psk_key_exchange_mode_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122c <parse_ch_psk_key_exchange_modes+0xec>
lea    0xe13(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe04(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1250 <parse_ch_psk_key_exchange_modes+0x110>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1265 <parse_ch_psk_key_exchange_modes+0x125>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ab <parse_ch_psk_key_exchange_modes+0x6b>
cmpl   $0x0,-0x14(%rbp)
je     1294 <parse_ch_psk_key_exchange_modes+0x154>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ch_psk_key_exchange_modes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,0x8(%rsp)
mov    %esi,%r15d
mov    %rdi,0x10(%rsp)
mov    $0x1,%edx
call   1060 <read_uint@plt>
test   %r12d,%r12d
je     118b <parse_ch_psk_key_exchange_modes+0x3b>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
add    %r15d,%eax
add    $0x1,%r15d
cmp    %eax,%r15d
jae    1248 <parse_ch_psk_key_exchange_modes+0xf8>
mov    0x8(%rsp),%rax
add    $0xffffffff,%eax
mov    %rax,0x8(%rsp)
test   %r12d,%r12d
lea    0xea9(%rip),%rax
lea    0xec0(%rip),%rbp
cmovne %rax,%rbp
xor    %r14d,%r14d
jmp    11eb <parse_ch_psk_key_exchange_modes+0x9b>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14d
cmp    %r14d,0x8(%rsp)
je     1248 <parse_ch_psk_key_exchange_modes+0xf8>
lea    (%r15,%r14,1),%ebx
test   %r12d,%r12d
je     1207 <parse_ch_psk_key_exchange_modes+0xb7>
test   %r14d,%r14d
je     1207 <parse_ch_psk_key_exchange_modes+0xb7>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1060 <read_uint@plt>
mov    %eax,%r13d
mov    %eax,%edi
call   1070 <psk_key_exchange_mode_name@plt>
test   %rax,%rax
jne    11d0 <parse_ch_psk_key_exchange_modes+0x80>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
mov    %r13d,%edx
call   1050 <fprintf@plt>
lea    0xddd(%rip),%rax
jmp    11d0 <parse_ch_psk_key_exchange_modes+0x80>
test   %r12d,%r12d
je     1265 <parse_ch_psk_key_exchange_modes+0x115>
mov    $0x5d,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\22psk_key_exchange_mode_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.3 = [53 x i8] c"WARNING! Unknown PSK key exchange mode code (%#.4x)\0A\00"
@.str.4 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.5 = [42 x i8] c"\09\09psk key exchange mode: %s (id = %#.4x)\0A\00"
@.str.6 = [2 x i8] c"]\00"
define void @parse_ch_psk_key_exchange_modes(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 i32 0, i32* %11
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 ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %4
br label %25
25: ; preds = %65, %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 %68
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 1)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = call i8* @psk_key_exchange_mode_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 ([53 x i8], [53 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 %62
58: ; preds = %51
%59 = load i8*, i8** %12
%60 = load i32, i32* %11
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %59, i32 %60)
br label %62
62: ; preds = %58, %54
%63 = load i32, i32* %13
%64 = add nsw i32 %63, 1
store i32 %64, i32* %13
br label %65
65: ; preds = %62
%66 = load i32, i32* %9
%67 = add i32 %66, 1
store i32 %67, i32* %9
br label %25
68: ; preds = %25
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
ret void
}

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