#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 */
typedef int /*<<< orphan*/ SSL;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_dump(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, char *, char *, int,
                              int);
#define TLSEXT_TYPE_client_certificate_url 137
#define TLSEXT_TYPE_ec_point_formats 136
#define TLSEXT_TYPE_elliptic_curves 135
#define TLSEXT_TYPE_max_fragment_length 134
#define TLSEXT_TYPE_renegotiate 133
#define TLSEXT_TYPE_server_name 132
#define TLSEXT_TYPE_session_ticket 131
#define TLSEXT_TYPE_status_request 130
#define TLSEXT_TYPE_truncated_hmac 129
#define TLSEXT_TYPE_trusted_ca_keys 128
void tlsext_cb(SSL *s, int client_server, int type, unsigned char *data,
               int len, void *arg) {
  BIO *bio = arg;
  char *extname;
  switch (type) {
  case TLSEXT_TYPE_server_name:
    extname = "server name";
    break;
  case TLSEXT_TYPE_max_fragment_length:
    extname = "max fragment length";
    break;
  case TLSEXT_TYPE_client_certificate_url:
    extname = "client certificate URL";
    break;
  case TLSEXT_TYPE_trusted_ca_keys:
    extname = "trusted CA keys";
    break;
  case TLSEXT_TYPE_truncated_hmac:
    extname = "truncated HMAC";
    break;
  case TLSEXT_TYPE_status_request:
    extname = "status request";
    break;
  case TLSEXT_TYPE_elliptic_curves:
    extname = "elliptic curves";
    break;
  case TLSEXT_TYPE_ec_point_formats:
    extname = "EC point formats";
    break;
  case TLSEXT_TYPE_session_ticket:
    extname = "server ticket";
    break;
  case TLSEXT_TYPE_renegotiate:
    extname = "renegotiate";
    break;
  default:
    extname = "unknown";
    break;
  }
  BIO_printf(bio, "TLS %s extension \"%s\" (id=%d), len=%d\n",
             client_server ? "server" : "client", extname, type, len);
  BIO_dump(bio, (char *)data, len);
  (void)BIO_flush(bio);
}


x86 assembly (clang, -O0):
<tlsext_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x9,%eax
ja     121f <tlsext_cb+0xef>
mov    -0x40(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xe9e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea9(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea9(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea8(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea7(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea7(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea8(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea6(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    122a <tlsext_cb+0xfa>
lea    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%ecx
lea    0xec6(%rip),%rdx
lea    0xeb8(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xe77(%rip),%rsi
call   1030 <BIO_printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <BIO_dump@plt>
mov    -0x30(%rbp),%rdi
call   1050 <BIO_flush@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tlsext_cb>:
push   %rbp
push   %r14
push   %rbx
mov    %r9,%rbx
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %edx,%r8d
lea    -0x80(%r8),%eax
cmp    $0x9,%eax
ja     115b <tlsext_cb+0x2b>
cltq
lea    0xf8e(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
jmp    1162 <tlsext_cb+0x32>
lea    0xf3e(%rip),%rcx
test   %esi,%esi
lea    0xf6b(%rip),%rax
lea    0xf5d(%rip),%rdx
cmove  %rax,%rdx
lea    0xf2b(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%r9d
call   1030 <BIO_printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <BIO_dump@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <BIO_flush@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"server name\00"
@.str.1 = [20 x i8] c"max fragment length\00"
@.str.2 = [23 x i8] c"client certificate URL\00"
@.str.3 = [16 x i8] c"trusted CA keys\00"
@.str.4 = [15 x i8] c"truncated HMAC\00"
@.str.5 = [15 x i8] c"status request\00"
@.str.6 = [16 x i8] c"elliptic curves\00"
@.str.7 = [17 x i8] c"EC point formats\00"
@.str.8 = [14 x i8] c"server ticket\00"
@.str.9 = [12 x i8] c"renegotiate\00"
@.str.10 = [8 x i8] c"unknown\00"
@.str.11 = [39 x i8] c"TLS %s extension \22%s\22 (id=%d), len=%d\0A\00"
@.str.12 = [7 x i8] c"server\00"
@.str.13 = [7 x i8] c"client\00"
define void @tlsext_cb(i32* %0, i32 %1, i32 %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i8*
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%15 = load i8*, i8** %12
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %13
%17 = load i32, i32* %9
switch i32 %17, label %28 [
i32 132, label %18
i32 134, label %19
i32 137, label %20
i32 128, label %21
i32 129, label %22
i32 130, label %23
i32 135, label %24
i32 136, label %25
i32 131, label %26
i32 133, label %27
]
18: ; preds = %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %14
br label %29
19: ; preds = %6
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %14
br label %29
20: ; preds = %6
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %14
br label %29
21: ; preds = %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %14
br label %29
22: ; preds = %6
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %14
br label %29
23: ; preds = %6
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %14
br label %29
24: ; preds = %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8** %14
br label %29
25: ; preds = %6
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8** %14
br label %29
26: ; preds = %6
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %14
br label %29
27: ; preds = %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8** %14
br label %29
28: ; preds = %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8** %14
br label %29
29: ; preds = %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18
%30 = load i32*, i32** %13
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0)
%35 = load i8*, i8** %14
%36 = load i32, i32* %9
%37 = load i32, i32* %11
%38 = call i32 @BIO_printf(i32* %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0), i8* %34, i8* %35, i32 %36, i32 %37)
%39 = load i32*, i32** %13
%40 = load i8*, i8** %10
%41 = load i32, i32* %11
%42 = call i32 @BIO_dump(i32* %39, i8* %40, i32 %41)
%43 = load i32*, i32** %13
%44 = call i32 @BIO_flush(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"server name\00"
@.str.1 = [20 x i8] c"max fragment length\00"
@.str.2 = [23 x i8] c"client certificate URL\00"
@.str.3 = [16 x i8] c"trusted CA keys\00"
@.str.4 = [15 x i8] c"truncated HMAC\00"
@.str.5 = [15 x i8] c"status request\00"
@.str.6 = [16 x i8] c"elliptic curves\00"
@.str.7 = [17 x i8] c"EC point formats\00"
@.str.8 = [14 x i8] c"server ticket\00"
@.str.9 = [12 x i8] c"renegotiate\00"
@.str.10 = [8 x i8] c"unknown\00"
@.str.11 = [39 x i8] c"TLS %s extension \22%s\22 (id=%d), len=%d\0A\00"
@.str.12 = [7 x i8] c"server\00"
@.str.13 = [7 x i8] c"client\00"
@reltable.tlsext_cb = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.tlsext_cb to i64)) to i32)]
define void @tlsext_cb(i32* nocapture readnone %0, i32 %1, i32 %2, i8* %3, i32 %4, i8* %5) {
%7 = bitcast i8* %5 to i32*
%8 = add i32 %2, -128
%9 = icmp ult i32 %8, 10
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = sext i32 %8 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.tlsext_cb to i8*), i64 %12)
br label %14
14: ; preds = %6, %10
%15 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), %6 ]
%16 = icmp eq i32 %1, 0
%17 = select i1 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
%18 = tail call i32 @BIO_printf(i32* %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0), i8* %17, i8* %15, i32 %2, i32 %4)
%19 = tail call i32 @BIO_dump(i32* %7, i8* %3, i32 %4)
%20 = tail call i32 @BIO_flush(i32* %7)
ret void
}