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

/* Variables and functions */
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
scalar_t__ BIO_write(int /*<<< orphan*/ *, int /*<<< orphan*/ const *, size_t);
int /*<<< orphan*/ ERR_clear_error();
int /*<<< orphan*/ OPENSSL_assert(int);
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int SSL_do_handshake(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
scalar_t__ SSL_read(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSL_set_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int SSL_set_cipher_list(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ SSL_set_connect_state(int /*<<< orphan*/ *);
int SSL_set_min_proto_version(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ SSL_set_tlsext_host_name(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ SSLv23_method();
int FuzzerTestOneInput(const uint8_t *buf, size_t len) {
  SSL *client;
  BIO *in;
  BIO *out;
  SSL_CTX *ctx;
  if (len == 0)
    return 0;
  ctx = SSL_CTX_new(SSLv23_method());
  client = SSL_new(ctx);
  OPENSSL_assert(SSL_set_min_proto_version(client, 0) == 1);
  OPENSSL_assert(SSL_set_cipher_list(client, "ALL:eNULL:@SECLEVEL=0") == 1);
  SSL_set_tlsext_host_name(client, "localhost");
  in = BIO_new(BIO_s_mem());
  out = BIO_new(BIO_s_mem());
  SSL_set_bio(client, in, out);
  SSL_set_connect_state(client);
  OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
  if (SSL_do_handshake(client) == 1) {
    uint8_t tmp[1024];
    for (;;) {
      if (SSL_read(client, tmp, sizeof(tmp)) <= 0) {
        break;
      }
    }
  }
  SSL_free(client);
  ERR_clear_error();
  SSL_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<FuzzerTestOneInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123a <FuzzerTestOneInput+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1369 <FuzzerTestOneInput+0x159>
mov    $0x0,%al
call   1040 <SSLv23_method@plt>
mov    %eax,%edi
call   10c0 <SSL_CTX_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <SSL_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   10a0 <SSL_set_min_proto_version@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <OPENSSL_assert@plt>
mov    -0x20(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   1120 <SSL_set_cipher_list@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <OPENSSL_assert@plt>
mov    -0x20(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1060 <SSL_set_tlsext_host_name@plt>
mov    $0x0,%al
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10d0 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10d0 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1130 <SSL_set_bio@plt>
mov    -0x20(%rbp),%rdi
call   1090 <SSL_set_connect_state@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   10f0 <BIO_write@plt>
cmp    -0x18(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <OPENSSL_assert@plt>
mov    -0x20(%rbp),%rdi
call   1100 <SSL_do_handshake@plt>
cmp    $0x1,%eax
jne    1349 <FuzzerTestOneInput+0x139>
jmp    131b <FuzzerTestOneInput+0x10b>
mov    -0x20(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <SSL_read@plt>
cmp    $0x0,%rax
jg     133f <FuzzerTestOneInput+0x12f>
jmp    1344 <FuzzerTestOneInput+0x134>
jmp    131b <FuzzerTestOneInput+0x10b>
jmp    1349 <FuzzerTestOneInput+0x139>
mov    -0x20(%rbp),%rdi
call   1050 <SSL_free@plt>
mov    $0x0,%al
call   10b0 <ERR_clear_error@plt>
mov    -0x38(%rbp),%rdi
call   10e0 <SSL_CTX_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FuzzerTestOneInput>:
test   %rsi,%rsi
je     132c <FuzzerTestOneInput+0x11c>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <SSLv23_method@plt>
mov    %eax,%edi
call   10c0 <SSL_CTX_new@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <SSL_new@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
call   10a0 <SSL_set_min_proto_version@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <OPENSSL_assert@plt>
lea    0xd96(%rip),%rsi
mov    %r13,%rdi
call   1120 <SSL_set_cipher_list@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <OPENSSL_assert@plt>
lea    0xd8f(%rip),%rsi
mov    %r13,%rdi
call   1060 <SSL_set_tlsext_host_name@plt>
xor    %eax,%eax
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10d0 <BIO_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10d0 <BIO_new@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1130 <SSL_set_bio@plt>
mov    %r13,%rdi
call   1090 <SSL_set_connect_state@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10f0 <BIO_write@plt>
xor    %edi,%edi
cmp    %r15,%rax
sete   %dil
call   1030 <OPENSSL_assert@plt>
mov    %r13,%rdi
call   1100 <SSL_do_handshake@plt>
cmp    $0x1,%eax
jne    1305 <FuzzerTestOneInput+0xf5>
mov    %rsp,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <SSL_read@plt>
test   %rax,%rax
jg     12f0 <FuzzerTestOneInput+0xe0>
mov    %r13,%rdi
call   1050 <SSL_free@plt>
xor    %eax,%eax
call   10b0 <ERR_clear_error@plt>
mov    %r14,%rdi
call   10e0 <SSL_CTX_free@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [22 x i8] c"ALL:eNULL:@SECLEVEL=0\00"
@.str.1 = [10 x i8] c"localhost\00"
define i32 @FuzzerTestOneInput(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [1024 x i32]
store i32* %0, i32** %4
store i64 %1, i64* %5
%11 = load i64, i64* %5
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %67
14: ; preds = %2
%15 = call i32 (...) @SSLv23_method()
%16 = call i32* @SSL_CTX_new(i32 %15)
store i32* %16, i32** %9
%17 = load i32*, i32** %9
%18 = call i32* @SSL_new(i32* %17)
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = call i32 @SSL_set_min_proto_version(i32* %19, i32 0)
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i32
%23 = call i32 @OPENSSL_assert(i32 %22)
%24 = load i32*, i32** %6
%25 = call i32 @SSL_set_cipher_list(i32* %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i32 %25, 1
%27 = zext i1 %26 to i32
%28 = call i32 @OPENSSL_assert(i32 %27)
%29 = load i32*, i32** %6
%30 = call i32 @SSL_set_tlsext_host_name(i32* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 (...) @BIO_s_mem()
%32 = call i32* @BIO_new(i32 %31)
store i32* %32, i32** %7
%33 = call i32 (...) @BIO_s_mem()
%34 = call i32* @BIO_new(i32 %33)
store i32* %34, i32** %8
%35 = load i32*, i32** %6
%36 = load i32*, i32** %7
%37 = load i32*, i32** %8
%38 = call i32 @SSL_set_bio(i32* %35, i32* %36, i32* %37)
%39 = load i32*, i32** %6
%40 = call i32 @SSL_set_connect_state(i32* %39)
%41 = load i32*, i32** %7
%42 = load i32*, i32** %4
%43 = load i64, i64* %5
%44 = call i64 @BIO_write(i32* %41, i32* %42, i64 %43)
%45 = load i64, i64* %5
%46 = icmp eq i64 %44, %45
%47 = zext i1 %46 to i32
%48 = call i32 @OPENSSL_assert(i32 %47)
%49 = load i32*, i32** %6
%50 = call i32 @SSL_do_handshake(i32* %49)
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %61
52: ; preds = %14
br label %53
53: ; preds = %59, %52
%54 = load i32*, i32** %6
%55 = getelementptr inbounds [1024 x i32], [1024 x i32]* %10, i64 0, i64 0
%56 = call i64 @SSL_read(i32* %54, i32* %55, i32 4096)
%57 = icmp sle i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
br label %60
59: ; preds = %53
br label %53
60: ; preds = %58
br label %61
61: ; preds = %60, %14
%62 = load i32*, i32** %6
%63 = call i32 @SSL_free(i32* %62)
%64 = call i32 (...) @ERR_clear_error()
%65 = load i32*, i32** %9
%66 = call i32 @SSL_CTX_free(i32* %65)
store i32 0, i32* %3
br label %67
67: ; preds = %61, %13
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [22 x i8] c"ALL:eNULL:@SECLEVEL=0\00"
@.str.1 = [10 x i8] c"localhost\00"
define i32 @FuzzerTestOneInput(i32* %0, i64 %1) {
%3 = alloca [1024 x i32]
%4 = icmp eq i64 %1, 0
br i1 %4, label %41, label %5
5: ; preds = %2
%6 = tail call i32 (...) @SSLv23_method()
%7 = tail call i32* @SSL_CTX_new(i32 %6)
%8 = tail call i32* @SSL_new(i32* %7)
%9 = tail call i32 @SSL_set_min_proto_version(i32* %8, i32 0)
%10 = icmp eq i32 %9, 1
%11 = zext i1 %10 to i32
%12 = tail call i32 @OPENSSL_assert(i32 %11)
%13 = tail call i32 @SSL_set_cipher_list(i32* %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 1
%15 = zext i1 %14 to i32
%16 = tail call i32 @OPENSSL_assert(i32 %15)
%17 = tail call i32 @SSL_set_tlsext_host_name(i32* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 (...) @BIO_s_mem()
%19 = tail call i32* @BIO_new(i32 %18)
%20 = tail call i32 (...) @BIO_s_mem()
%21 = tail call i32* @BIO_new(i32 %20)
%22 = tail call i32 @SSL_set_bio(i32* %8, i32* %19, i32* %21)
%23 = tail call i32 @SSL_set_connect_state(i32* %8)
%24 = tail call i64 @BIO_write(i32* %19, i32* %0, i64 %1)
%25 = icmp eq i64 %24, %1
%26 = zext i1 %25 to i32
%27 = tail call i32 @OPENSSL_assert(i32 %26)
%28 = tail call i32 @SSL_do_handshake(i32* %8)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %37
30: ; preds = %5
%31 = bitcast [1024 x i32]* %3 to i8*
%32 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
br label %33
33: ; preds = %33, %30
%34 = call i64 @SSL_read(i32* %8, i32* %32, i32 4096)
%35 = icmp slt i64 %34, 1
br i1 %35, label %36, label %33
36: ; preds = %33
br label %37
37: ; preds = %36, %5
%38 = call i32 @SSL_free(i32* %8)
%39 = call i32 (...) @ERR_clear_error()
%40 = call i32 @SSL_CTX_free(i32* %7)
br label %41
41: ; preds = %2, %37
ret i32 0
}