#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_indent(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ BIO_puts(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ SSL3_VERSION;
int /*<<< orphan*/ TLS1_get_version(int /*<<< orphan*/ *);
int ssl_get_keyex(char const **, int /*<<< orphan*/ *);
int /*<<< orphan*/ ssl_print_hex(int /*<<< orphan*/ *, int, char *,
                                 unsigned char const *, size_t);
int /*<<< orphan*/ ssl_print_hexbuf(int /*<<< orphan*/ *, int, char *, int,
                                    unsigned char const **, size_t *);
int ssl_print_client_keyex(BIO *bio, int indent, SSL *ssl,
                           const unsigned char *msg, size_t msglen) {
  const char *algname;
  int id;
  id = ssl_get_keyex(&algname, ssl);
  BIO_indent(bio, indent, 80);
  BIO_printf(bio, "KeyExchangeAlgorithm=%s\n", algname);
  switch (id) {
  case 0x00000001L:
    if (TLS1_get_version(ssl) == SSL3_VERSION) {
      ssl_print_hex(bio, indent + 2, "EncyptedPreMasterSecret", msg, msglen);
    } else {
      if (!ssl_print_hexbuf(bio, indent + 2, "EncyptedPreMasterSecret", 2, &msg,
                            &msglen))
        return 0;
    }
    break;
  case 0x00000004L:
  case 0x00000002L:
    if (msglen == 0) {
      BIO_indent(bio, indent + 2, 80);
      BIO_puts(bio, "implicit\n");
      break;
    }
  case 0x00000008L:
    if (!ssl_print_hexbuf(bio, indent + 2, "dh_Yc", 2, &msg, &msglen))
      return 0;
    break;
  case 0x00000020L:
  case 0x00000040L:
    if (msglen == 0) {
      BIO_indent(bio, indent + 2, 80);
      BIO_puts(bio, "implicit\n");
      break;
    }
  case 0x00000080L:
    if (!ssl_print_hexbuf(bio, indent + 2, "ecdh_Yc", 1, &msg, &msglen))
      return 0;
    break;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ssl_print_client_keyex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1070 <ssl_get_keyex@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x50,%edx
call   1040 <BIO_indent@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1050 <BIO_printf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x1,%eax
je     123c <ssl_print_client_keyex+0xcc>
jmp    11d4 <ssl_print_client_keyex+0x64>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     12b9 <ssl_print_client_keyex+0x149>
jmp    11e5 <ssl_print_client_keyex+0x75>
mov    -0x40(%rbp),%eax
sub    $0x4,%eax
je     12b9 <ssl_print_client_keyex+0x149>
jmp    11f6 <ssl_print_client_keyex+0x86>
mov    -0x40(%rbp),%eax
sub    $0x8,%eax
je     12f2 <ssl_print_client_keyex+0x182>
jmp    1207 <ssl_print_client_keyex+0x97>
mov    -0x40(%rbp),%eax
sub    $0x20,%eax
je     132f <ssl_print_client_keyex+0x1bf>
jmp    1218 <ssl_print_client_keyex+0xa8>
mov    -0x40(%rbp),%eax
sub    $0x40,%eax
je     132f <ssl_print_client_keyex+0x1bf>
jmp    1229 <ssl_print_client_keyex+0xb9>
mov    -0x40(%rbp),%eax
sub    $0x80,%eax
je     1368 <ssl_print_client_keyex+0x1f8>
jmp    13a5 <ssl_print_client_keyex+0x235>
mov    -0x20(%rbp),%rdi
call   1060 <TLS1_get_version@plt>
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%eax
jne    1277 <ssl_print_client_keyex+0x107>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xdac(%rip),%rdx
call   1030 <ssl_print_hex@plt>
jmp    12b4 <ssl_print_client_keyex+0x144>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
lea    0xd91(%rip),%rdx
mov    $0x2,%ecx
lea    -0x28(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1080 <ssl_print_hexbuf@plt>
cmp    $0x0,%eax
jne    12af <ssl_print_client_keyex+0x13f>
movl   $0x0,-0x4(%rbp)
jmp    13ac <ssl_print_client_keyex+0x23c>
jmp    12b4 <ssl_print_client_keyex+0x144>
jmp    13a5 <ssl_print_client_keyex+0x235>
cmpq   $0x0,-0x30(%rbp)
jne    12ed <ssl_print_client_keyex+0x17d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
mov    $0x50,%edx
call   1040 <BIO_indent@plt>
mov    -0x10(%rbp),%rdi
lea    0xd4e(%rip),%rsi
call   1090 <BIO_puts@plt>
jmp    13a5 <ssl_print_client_keyex+0x235>
jmp    12f2 <ssl_print_client_keyex+0x182>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
lea    0xd3a(%rip),%rdx
mov    $0x2,%ecx
lea    -0x28(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1080 <ssl_print_hexbuf@plt>
cmp    $0x0,%eax
jne    132a <ssl_print_client_keyex+0x1ba>
movl   $0x0,-0x4(%rbp)
jmp    13ac <ssl_print_client_keyex+0x23c>
jmp    13a5 <ssl_print_client_keyex+0x235>
cmpq   $0x0,-0x30(%rbp)
jne    1363 <ssl_print_client_keyex+0x1f3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
mov    $0x50,%edx
call   1040 <BIO_indent@plt>
mov    -0x10(%rbp),%rdi
lea    0xcd8(%rip),%rsi
call   1090 <BIO_puts@plt>
jmp    13a5 <ssl_print_client_keyex+0x235>
jmp    1368 <ssl_print_client_keyex+0x1f8>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
lea    0xcc2(%rip),%rdx
mov    $0x1,%ecx
lea    -0x28(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1080 <ssl_print_hexbuf@plt>
cmp    $0x0,%eax
jne    13a0 <ssl_print_client_keyex+0x230>
movl   $0x0,-0x4(%rbp)
jmp    13ac <ssl_print_client_keyex+0x23c>
jmp    13a5 <ssl_print_client_keyex+0x235>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_print_client_keyex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r13
mov    %esi,%ebp
mov    %rdi,%r12
mov    %rcx,0x8(%rsp)
mov    %r8,(%rsp)
lea    0x10(%rsp),%rdi
mov    %rdx,%rsi
call   1070 <ssl_get_keyex@plt>
mov    %eax,%ebx
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x50,%edx
call   1040 <BIO_indent@plt>
mov    0x10(%rsp),%rdx
lea    0xec1(%rip),%rsi
mov    %r12,%rdi
call   1050 <BIO_printf@plt>
lea    -0x1(%rbx),%eax
cmp    $0x1f,%eax
ja     1202 <ssl_print_client_keyex+0x92>
lea    0xe2a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
test   %r14,%r14
je     123f <ssl_print_client_keyex+0xcf>
add    $0x2,%ebp
lea    0xecf(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %rsp,%r9
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x2,%ecx
jmp    1232 <ssl_print_client_keyex+0xc2>
cmp    $0x40,%ebx
je     1211 <ssl_print_client_keyex+0xa1>
cmp    $0x80,%ebx
je     1216 <ssl_print_client_keyex+0xa6>
jmp    128f <ssl_print_client_keyex+0x11f>
test   %r14,%r14
je     123f <ssl_print_client_keyex+0xcf>
add    $0x2,%ebp
lea    0xe9b(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %rsp,%r9
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x1,%ecx
call   1080 <ssl_print_hexbuf@plt>
test   %eax,%eax
jne    128f <ssl_print_client_keyex+0x11f>
xor    %eax,%eax
jmp    1294 <ssl_print_client_keyex+0x124>
add    $0x2,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x50,%edx
call   1040 <BIO_indent@plt>
lea    0xe59(%rip),%rsi
mov    %r12,%rdi
call   1090 <BIO_puts@plt>
jmp    128f <ssl_print_client_keyex+0x11f>
mov    %r13,%rdi
call   1060 <TLS1_get_version@plt>
mov    0x2d77(%rip),%rcx
add    $0x2,%ebp
cmp    (%rcx),%eax
jne    12a3 <ssl_print_client_keyex+0x133>
lea    0xe1a(%rip),%rdx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <ssl_print_hex@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdx
jmp    11ee <ssl_print_client_keyex+0x7e>

LLVM IR (-O0):
@.str = [25 x i8] c"KeyExchangeAlgorithm=%s\0A\00"
@SSL3_VERSION = global i32 0
@.str.1 = [24 x i8] c"EncyptedPreMasterSecret\00"
@.str.2 = [10 x i8] c"implicit\0A\00"
@.str.3 = [6 x i8] c"dh_Yc\00"
@.str.4 = [8 x i8] c"ecdh_Yc\00"
define i32 @ssl_print_client_keyex(i32* %0, i32 %1, i32* %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%14 = load i32*, i32** %9
%15 = call i32 @ssl_get_keyex(i8** %12, i32* %14)
store i32 %15, i32* %13
%16 = load i32*, i32** %7
%17 = load i32, i32* %8
%18 = call i32 @BIO_indent(i32* %16, i32 %17, i32 80)
%19 = load i32*, i32** %7
%20 = load i8*, i8** %12
%21 = call i32 @BIO_printf(i32* %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %13
switch i32 %22, label %82 [
i32 1, label %23
i32 4, label %44
i32 2, label %44
i32 8, label %55
i32 32, label %63
i32 64, label %63
i32 128, label %74
]
23: ; preds = %5
%24 = load i32*, i32** %9
%25 = call i32 @TLS1_get_version(i32* %24)
%26 = load i32, i32* @SSL3_VERSION
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32*, i32** %7
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 2
%32 = load i8*, i8** %10
%33 = load i64, i64* %11
%34 = call i32 @ssl_print_hex(i32* %29, i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %32, i64 %33)
br label %43
35: ; preds = %23
%36 = load i32*, i32** %7
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 2
%39 = call i32 @ssl_print_hexbuf(i32* %36, i32 %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 2, i8** %10, i64* %11)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %35
store i32 0, i32* %6
br label %83
42: ; preds = %35
br label %43
43: ; preds = %42, %28
br label %82
44: ; preds = %5, %5
%45 = load i64, i64* %11
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32*, i32** %7
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 2
%51 = call i32 @BIO_indent(i32* %48, i32 %50, i32 80)
%52 = load i32*, i32** %7
%53 = call i32 @BIO_puts(i32* %52, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %82
54: ; preds = %44
br label %55
55: ; preds = %5, %54
%56 = load i32*, i32** %7
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 2
%59 = call i32 @ssl_print_hexbuf(i32* %56, i32 %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 2, i8** %10, i64* %11)
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %55
store i32 0, i32* %6
br label %83
62: ; preds = %55
br label %82
63: ; preds = %5, %5
%64 = load i64, i64* %11
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %73
66: ; preds = %63
%67 = load i32*, i32** %7
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 2
%70 = call i32 @BIO_indent(i32* %67, i32 %69, i32 80)
%71 = load i32*, i32** %7
%72 = call i32 @BIO_puts(i32* %71, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %82
73: ; preds = %63
br label %74
74: ; preds = %5, %73
%75 = load i32*, i32** %7
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 2
%78 = call i32 @ssl_print_hexbuf(i32* %75, i32 %77, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1, i8** %10, i64* %11)
%79 = icmp ne i32 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %74
store i32 0, i32* %6
br label %83
81: ; preds = %74
br label %82
82: ; preds = %5, %81, %66, %62, %47, %43
store i32 1, i32* %6
br label %83
83: ; preds = %82, %80, %61, %41
%84 = load i32, i32* %6
ret i32 %84
}

LLVM IR (-O2):
@.str = [25 x i8] c"KeyExchangeAlgorithm=%s\0A\00"
@SSL3_VERSION = global i32 0
@.str.1 = [24 x i8] c"EncyptedPreMasterSecret\00"
@.str.2 = [10 x i8] c"implicit\0A\00"
@.str.3 = [6 x i8] c"dh_Yc\00"
@.str.4 = [8 x i8] c"ecdh_Yc\00"
define i32 @ssl_print_client_keyex(i32* %0, i32 %1, i32* %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i8* %3, i8** %6
store i64 %4, i64* %7
%9 = bitcast i8** %8 to i8*
%10 = call i32 @ssl_get_keyex(i8** %8, i32* %2)
%11 = call i32 @BIO_indent(i32* %0, i32 %1, i32 80)
%12 = load i8*, i8** %8
%13 = call i32 @BIO_printf(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
switch i32 %10, label %44 [
i32 1, label %14
i32 4, label %24
i32 2, label %24
i32 8, label %30
i32 32, label %34
i32 64, label %34
i32 128, label %40
]
14: ; preds = %5
%15 = call i32 @TLS1_get_version(i32* %2)
%16 = load i32, i32* @SSL3_VERSION
%17 = icmp eq i32 %15, %16
%18 = add nsw i32 %1, 2
br i1 %17, label %19, label %21
19: ; preds = %14
%20 = call i32 @ssl_print_hex(i32* %0, i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %3, i64 %4)
br label %44
21: ; preds = %14
%22 = call i32 @ssl_print_hexbuf(i32* %0, i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 2, i8** %6, i64* %7)
%23 = icmp eq i32 %22, 0
br i1 %23, label %45, label %44
24: ; preds = %5, %5
%25 = icmp eq i64 %4, 0
br i1 %25, label %26, label %30
26: ; preds = %24
%27 = add nsw i32 %1, 2
%28 = call i32 @BIO_indent(i32* %0, i32 %27, i32 80)
%29 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %44
30: ; preds = %24, %5
%31 = add nsw i32 %1, 2
%32 = call i32 @ssl_print_hexbuf(i32* %0, i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 2, i8** %6, i64* %7)
%33 = icmp eq i32 %32, 0
br i1 %33, label %45, label %44
34: ; preds = %5, %5
%35 = icmp eq i64 %4, 0
br i1 %35, label %36, label %40
36: ; preds = %34
%37 = add nsw i32 %1, 2
%38 = call i32 @BIO_indent(i32* %0, i32 %37, i32 80)
%39 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %44
40: ; preds = %34, %5
%41 = add nsw i32 %1, 2
%42 = call i32 @ssl_print_hexbuf(i32* %0, i32 %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1, i8** %6, i64* %7)
%43 = icmp eq i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40, %30, %19, %21, %5, %36, %26
br label %45
45: ; preds = %40, %30, %21, %44
%46 = phi i32 [ 1, %44 ], [ 0, %21 ], [ 0, %30 ], [ 0, %40 ]
ret i32 %46
}