#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 /*<<< orphan*/);
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*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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, *portnum;
  if (count != 3) {
    printf("usage: %s <hostname> <portnum>\n", strings[0]);
    exit(0);
  }
  hostname = strings[1];
  portnum = strings[2];
  ctx = InitCTX();
  server = OpenConnection(hostname, atoi(portnum));
  ssl = SSL_new(ctx);
  SSL_set_fd(ssl, server);
  if (SSL_connect(ssl) == -1)
    ERR_print_errors_fp(stderr);
  else {
    char *msg = "Hello???";
    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);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     124d <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbf(%rip),%rdi
call   1090 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x440(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x448(%rbp)
mov    $0x0,%al
call   1050 <InitCTX@plt>
mov    %rax,-0x18(%rbp)
mov    -0x440(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x448(%rbp),%rdi
call   1110 <atoi@plt>
mov    -0x458(%rbp),%rdi
mov    %eax,%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    12df <main+0xcf>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   1130 <ERR_print_errors_fp@plt>
jmp    138e <main+0x17e>
lea    0xd3a(%rip),%rax
mov    %rax,-0x450(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <SSL_get_cipher@plt>
mov    %rax,%rsi
lea    0xd29(%rip),%rdi
call   1090 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <ShowCerts@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x468(%rbp)
mov    -0x450(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    -0x450(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x468(%rbp),%rdi
mov    -0x460(%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    0xcc7(%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>
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x3,%edi
jne    130b <main+0xfb>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rbp
xor    %eax,%eax
call   1050 <InitCTX@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1110 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%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     12dd <main+0xcd>
mov    %rbx,%rdi
call   10b0 <SSL_get_cipher@plt>
lea    0xdaa(%rip),%rdi
mov    %rax,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1040 <ShowCerts@plt>
lea    0xd8a(%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    0xd7c(%rip),%rdi
mov    %rbp,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1060 <SSL_free@plt>
jmp    12eb <main+0xdb>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   1130 <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
mov    (%rsi),%rsi
lea    0xceb(%rip),%rdi
call   1090 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"usage: %s <hostname> <portnum>\0A\00"
@stderr = global i32 0
@.str.1 = [9 x i8] c"Hello???\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*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %11
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
store i8* %28, i8** %12
%29 = call i32* (...) @InitCTX()
store i32* %29, i32** %6
%30 = load i8*, i8** %11
%31 = load i8*, i8** %12
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @OpenConnection(i8* %30, i32 %32)
store i32 %33, i32* %7
%34 = load i32*, i32** %6
%35 = call i32* @SSL_new(i32* %34)
store i32* %35, i32** %8
%36 = load i32*, i32** %8
%37 = load i32, i32* %7
%38 = call i32 @SSL_set_fd(i32* %36, i32 %37)
%39 = load i32*, i32** %8
%40 = call i32 @SSL_connect(i32* %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %22
%43 = load i32, i32* @stderr
%44 = call i32 @ERR_print_errors_fp(i32 %43)
br label %66
45: ; preds = %22
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %13
%46 = load i32*, i32** %8
%47 = call i8* @SSL_get_cipher(i32* %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %8
%50 = call i32 @ShowCerts(i32* %49)
%51 = load i32*, i32** %8
%52 = load i8*, i8** %13
%53 = load i8*, i8** %13
%54 = call i32 @strlen(i8* %53)
%55 = call i32 @SSL_write(i32* %51, i8* %52, i32 %54)
%56 = load i32*, i32** %8
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%58 = call i32 @SSL_read(i32* %56, i8* %57, i32 1024)
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%63 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %62)
%64 = load i32*, i32** %8
%65 = call i32 @SSL_free(i32* %64)
br label %66
66: ; preds = %45, %42
%67 = load i32, i32* %7
%68 = call i32 @close(i32 %67)
%69 = load i32*, i32** %6
%70 = call i32 @SSL_CTX_free(i32* %69)
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [32 x i8] c"usage: %s <hostname> <portnum>\0A\00"
@stderr = global i32 0
@.str.1 = [9 x i8] c"Hello???\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 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* (...) @InitCTX()
%16 = tail call i32 @atoi(i8* %14)
%17 = tail call i32 @OpenConnection(i8* %12, i32 %16)
%18 = tail call i32* @SSL_new(i32* %15)
%19 = tail call i32 @SSL_set_fd(i32* %18, i32 %17)
%20 = tail call i32 @SSL_connect(i32* %18)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %10
%23 = load i32, i32* @stderr
%24 = tail call i32 @ERR_print_errors_fp(i32 %23)
br label %36
25: ; preds = %10
%26 = tail call i8* @SSL_get_cipher(i32* %18)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = tail call i32 @ShowCerts(i32* %18)
%29 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @SSL_write(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = call i32 @SSL_read(i32* %18, i8* %4, i32 1024)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%35 = call i32 @SSL_free(i32* %18)
br label %36
36: ; preds = %25, %22
%37 = call i32 @close(i32 %17)
%38 = call i32 @SSL_CTX_free(i32* %15)
ret i32 0
}