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

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ *InitCTX();
int OpenConnection(char *, int);
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int SSL_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
char *SSL_get_cipher(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSL_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ShowCerts(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int count, char *strings[]) {
  SSL_CTX *ctx;
  int server;
  SSL *ssl;
  char buf[1024];
  int bytes;
  char *hostname = "192.168.2.2";
  ctx = InitCTX();
  server = OpenConnection(hostname, 5006);
  ssl = SSL_new(ctx);
  SSL_set_fd(ssl, server);
  if (SSL_connect(ssl) == -1)
    ERR_print_errors_fp(stderr);
  else {
    char *msg = "I am SSL Client";
    printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
    ShowCerts(ssl);
    SSL_write(ssl, msg, strlen(msg));
    bytes = SSL_read(ssl, buf, sizeof(buf));
    buf[bytes] = 0;
    printf("Received: \"%s\"\n", buf);
    SSL_free(ssl);
  }
  close(server);
  SSL_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdf0(%rip),%rax
mov    %rax,-0x440(%rbp)
mov    $0x0,%al
call   1050 <InitCTX@plt>
mov    %rax,-0x18(%rbp)
mov    -0x440(%rbp),%rdi
mov    $0x138e,%esi
call   1100 <OpenConnection@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <SSL_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <SSL_set_fd@plt>
mov    -0x28(%rbp),%rdi
call   10e0 <SSL_connect@plt>
cmp    $0xffffffff,%eax
jne    1274 <main+0x84>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1110 <ERR_print_errors_fp@plt>
jmp    1323 <main+0x133>
lea    0xd91(%rip),%rax
mov    %rax,-0x448(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <SSL_get_cipher@plt>
mov    %rax,%rsi
lea    0xd87(%rip),%rdi
call   1090 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <ShowCerts@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x448(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    -0x448(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x458(%rbp),%rdi
mov    -0x450(%rbp),%rsi
mov    %eax,%edx
call   1030 <SSL_write@plt>
mov    -0x28(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <SSL_read@plt>
mov    %eax,-0x434(%rbp)
movslq -0x434(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xd25(%rip),%rdi
call   1090 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <SSL_free@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <SSL_CTX_free@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   1050 <InitCTX@plt>
mov    %rax,%r14
lea    0xdf2(%rip),%rdi
mov    $0x138e,%esi
call   1100 <OpenConnection@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   10d0 <SSL_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
call   1070 <SSL_set_fd@plt>
mov    %rbx,%rdi
call   10e0 <SSL_connect@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0xbb>
mov    %rbx,%rdi
call   10b0 <SSL_get_cipher@plt>
lea    0xdcf(%rip),%rdi
mov    %rax,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1040 <ShowCerts@plt>
lea    0xda8(%rip),%rbp
mov    %rbp,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <SSL_write@plt>
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x400,%edx
call   10c0 <SSL_read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xda1(%rip),%rdi
mov    %rbp,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1060 <SSL_free@plt>
jmp    12b9 <main+0xc9>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1110 <ERR_print_errors_fp@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r14,%rdi
call   10f0 <SSL_CTX_free@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"192.168.2.2\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"I am SSL Client\00"
@.str.2 = [30 x i8] c"Connected with %s encryption\0A\00"
@.str.3 = [16 x i8] c"Received: \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %11
%13 = call i32* (...) @InitCTX()
store i32* %13, i32** %6
%14 = load i8*, i8** %11
%15 = call i32 @OpenConnection(i8* %14, i32 5006)
store i32 %15, i32* %7
%16 = load i32*, i32** %6
%17 = call i32* @SSL_new(i32* %16)
store i32* %17, i32** %8
%18 = load i32*, i32** %8
%19 = load i32, i32* %7
%20 = call i32 @SSL_set_fd(i32* %18, i32 %19)
%21 = load i32*, i32** %8
%22 = call i32 @SSL_connect(i32* %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = call i32 @ERR_print_errors_fp(i32 %25)
br label %48
27: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %12
%28 = load i32*, i32** %8
%29 = call i8* @SSL_get_cipher(i32* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32*, i32** %8
%32 = call i32 @ShowCerts(i32* %31)
%33 = load i32*, i32** %8
%34 = load i8*, i8** %12
%35 = load i8*, i8** %12
%36 = call i32 @strlen(i8* %35)
%37 = call i32 @SSL_write(i32* %33, i8* %34, i32 %36)
%38 = load i32*, i32** %8
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = call i32 @SSL_read(i32* %38, i8* %39, i32 1024)
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load i32*, i32** %8
%47 = call i32 @SSL_free(i32* %46)
br label %48
48: ; preds = %27, %24
%49 = load i32, i32* %7
%50 = call i32 @close(i32 %49)
%51 = load i32*, i32** %6
%52 = call i32 @SSL_CTX_free(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"192.168.2.2\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"I am SSL Client\00"
@.str.2 = [30 x i8] c"Connected with %s encryption\0A\00"
@.str.3 = [16 x i8] c"Received: \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* (...) @InitCTX()
%6 = tail call i32 @OpenConnection(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 5006)
%7 = tail call i32* @SSL_new(i32* %5)
%8 = tail call i32 @SSL_set_fd(i32* %7, i32 %6)
%9 = tail call i32 @SSL_connect(i32* %7)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @ERR_print_errors_fp(i32 %12)
br label %25
14: ; preds = %2
%15 = tail call i8* @SSL_get_cipher(i32* %7)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @ShowCerts(i32* %7)
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @SSL_write(i32* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @SSL_read(i32* %7, i8* %4, i32 1024)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%24 = call i32 @SSL_free(i32* %7)
br label %25
25: ; preds = %14, %11
%26 = call i32 @close(i32 %6)
%27 = call i32 @SSL_CTX_free(i32* %5)
ret i32 0
}