#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 136
#define TLSEXT_TYPE_ec_point_formats 135
#define TLSEXT_TYPE_elliptic_curves 134
#define TLSEXT_TYPE_max_fragment_length 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;
  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    $0x8,%eax
ja     120f <tlsext_cb+0xdf>
mov    -0x40(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xe9a(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xe9e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xea5(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xea5(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xea4(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xea3(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xea3(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
lea    0xea4(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121a <tlsext_cb+0xea>
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    $0x8,%eax
ja     115b <tlsext_cb+0x2b>
cltq
lea    0xf82(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
jmp    1162 <tlsext_cb+0x32>
lea    0xf32(%rip),%rcx
test   %esi,%esi
lea    0xf5f(%rip),%rax
lea    0xf51(%rip),%rdx
cmove  %rax,%rdx
lea    0xf1f(%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 = [8 x i8] c"unknown\00"
@.str.10 = [39 x i8] c"TLS %s extension \22%s\22 (id=%d), len=%d\0A\00"
@.str.11 = [7 x i8] c"server\00"
@.str.12 = [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 %27 [
i32 132, label %18
i32 133, label %19
i32 136, label %20
i32 128, label %21
i32 129, label %22
i32 130, label %23
i32 134, label %24
i32 135, label %25
i32 131, label %26
]
18: ; preds = %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %14
br label %28
19: ; preds = %6
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %14
br label %28
20: ; preds = %6
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %14
br label %28
21: ; preds = %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %14
br label %28
22: ; preds = %6
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %14
br label %28
23: ; preds = %6
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %14
br label %28
24: ; preds = %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8** %14
br label %28
25: ; preds = %6
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8** %14
br label %28
26: ; preds = %6
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %14
br label %28
27: ; preds = %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8** %14
br label %28
28: ; preds = %27, %26, %25, %24, %23, %22, %21, %20, %19, %18
%29 = load i32*, i32** %13
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
%34 = load i8*, i8** %14
%35 = load i32, i32* %9
%36 = load i32, i32* %11
%37 = call i32 @BIO_printf(i32* %29, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0), i8* %33, i8* %34, i32 %35, i32 %36)
%38 = load i32*, i32** %13
%39 = load i8*, i8** %10
%40 = load i32, i32* %11
%41 = call i32 @BIO_dump(i32* %38, i8* %39, i32 %40)
%42 = load i32*, i32** %13
%43 = call i32 @BIO_flush(i32* %42)
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 = [8 x i8] c"unknown\00"
@.str.10 = [39 x i8] c"TLS %s extension \22%s\22 (id=%d), len=%d\0A\00"
@.str.11 = [7 x i8] c"server\00"
@.str.12 = [7 x i8] c"client\00"
@reltable.tlsext_cb = [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.8 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.6 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @reltable.tlsext_cb to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.2 to i64), i64 ptrtoint ([9 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, 9
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 ([9 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.9, 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.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0)
%18 = tail call i32 @BIO_printf(i32* %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, 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
}