#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(char *);
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_library_init();
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 *);
char *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);
  }
  SSL_library_init();
  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) {
    printf("Eroor: %s\n", stderr);
    ERR_print_errors_fp(stderr);
  } else {
    char *msg = "HelloWorld";
    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    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     125d <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdaf(%rip),%rdi
call   1090 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
mov    $0x0,%al
call   10c0 <SSL_library_init@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   1120 <atoi@plt>
mov    -0x458(%rbp),%rdi
mov    %eax,%esi
call   1110 <OpenConnection@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   10e0 <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   10f0 <SSL_connect@plt>
cmp    $0xffffffff,%eax
jne    130d <main+0xed>
mov    0x2cf6(%rip),%rax
mov    (%rax),%rsi
lea    0xd2c(%rip),%rdi
call   1090 <printf@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%rdi
call   1140 <ERR_print_errors_fp@plt>
jmp    13bc <main+0x19c>
lea    0xd17(%rip),%rax
mov    %rax,-0x450(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <SSL_get_cipher@plt>
mov    %rax,%rsi
lea    0xd08(%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   10d0 <SSL_read@plt>
mov    %eax,-0x434(%rbp)
movslq -0x434(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xca6(%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   1100 <SSL_CTX_free@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1335 <main+0x115>
xor    %eax,%eax
call   10c0 <SSL_library_init@plt>
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rbx
xor    %eax,%eax
call   1050 <InitCTX@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1120 <atoi@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1110 <OpenConnection@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   10e0 <SSL_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
call   1070 <SSL_set_fd@plt>
mov    %rbx,%rdi
call   10f0 <SSL_connect@plt>
cmp    $0xffffffff,%eax
je     12f7 <main+0xd7>
mov    %rbx,%rdi
call   10b0 <SSL_get_cipher@plt>
lea    0xd9d(%rip),%rdi
mov    %rax,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1040 <ShowCerts@plt>
lea    0xd7b(%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   10d0 <SSL_read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xd6f(%rip),%rdi
mov    %rbp,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1060 <SSL_free@plt>
jmp    1315 <main+0xf5>
mov    0x2ce2(%rip),%rbx
mov    (%rbx),%rsi
lea    0xd18(%rip),%rdi
call   1090 <printf@plt>
mov    (%rbx),%rdi
call   1140 <ERR_print_errors_fp@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r14,%rdi
call   1100 <SSL_CTX_free@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xcc1(%rip),%rdi
call   1090 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>

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

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