#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ SSL_METHOD;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_socket(int, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/ *);
#define SSL_ERROR_NONE 130
#define SSL_ERROR_SYSCALL 129
#define SSL_ERROR_ZERO_RETURN 128
int SSL_connect(int /*<<< orphan*/ *);
int SSL_get_error(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_set_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int SSL_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ *SSLv23_method();
int atoi(char *);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int c;
  int sock = 0, port = 443, ret = 0;
  char *host = NULL;
  SSL_CTX *ctx;
  SSL *ssl;
  SSL_METHOD *sslmeth;
  BIO *sbio;
  BIO *bio_err = 0;
  struct sockaddr_in addr;
  while ((c = getopt(argc, argv, "h:p:")) != -1) {
    switch (c) {
    case 'h':
      host = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      if (port <= 0 || port >= 65536) {
        exit(1);
      }
      break;
    default:
      exit(1);
      break;
    }
  }
  if (!bio_err) {
    SSL_library_init();
    SSL_load_error_strings();
    OpenSSL_add_all_algorithms();
    bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
  }
  sslmeth = SSLv23_method();
  ctx = SSL_CTX_new(sslmeth);
  if (!ctx) {
    printf("CTX ERROR\n");
    exit(1);
  }
  if (!host) {
    printf("ERROR - host not set.\n");
    exit(1);
  }
  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock < 0) {
    printf("sock error\n");
    exit(1);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin_addr.s_addr = inet_addr(host);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    printf("connect error\n");
    exit(1);
  }
  ssl = SSL_new(ctx);
  sbio = BIO_new_socket(sock, BIO_NOCLOSE);
  SSL_set_bio(ssl, sbio, sbio);
  ret = SSL_connect(ssl);
  if (ret <= 0) {
    printf("SSL connect error\n");
    ERR_print_errors_fp(stderr);
    exit(1);
  }
  printf("Connected!\n");
  ret = SSL_write(ssl, "GET / HTTP/1.0\r\n\r\n\r\n",
                  sizeof("GET / HTTP/1.0\r\n\r\n\r\n"));
  if (ret < 0) {
    printf("SSL write error\n");
    ERR_print_errors_fp(stderr);
    exit(1);
  }
  while (1) {
    char buf[2048];
    ret = SSL_read(ssl, buf, sizeof(buf) - 1);
    printf("ret: %d\n", ret);
    switch (SSL_get_error(ssl, ret)) {
    case SSL_ERROR_NONE:
      buf[ret] = '\0';
      printf("no error: %s\n", buf);
      break;
    case SSL_ERROR_ZERO_RETURN:
      printf("no returen\n");
      exit(1);
      break;
    case SSL_ERROR_SYSCALL:
      fprintf(stderr, "SSL Error: Premature close\n");
      exit(1);
      break;
    default:
      printf("default error\n");
      exit(1);
      break;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1bb,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd34(%rip),%rdx
call   1140 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1362 <main+0xe2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x864(%rbp)
sub    $0x68,%eax
je     1308 <main+0x88>
jmp    12f4 <main+0x74>
mov    -0x864(%rbp),%eax
sub    $0x70,%eax
je     131b <main+0x9b>
jmp    1353 <main+0xd3>
mov    0x2ce9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    135d <main+0xdd>
mov    0x2cd6(%rip),%rax
mov    (%rax),%rdi
call   1150 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1344 <main+0xc4>
cmpl   $0x10000,-0x1c(%rbp)
jl     134e <main+0xce>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    135d <main+0xdd>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    12be <main+0x3e>
cmpq   $0x0,-0x50(%rbp)
jne    139d <main+0x11d>
mov    $0x0,%al
call   10a0 <SSL_library_init@plt>
mov    $0x0,%al
call   1130 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   1100 <OpenSSL_add_all_algorithms@plt>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    0x2c4e(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_new_fp@plt>
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1060 <SSLv23_method@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1110 <SSL_CTX_new@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13d8 <main+0x158>
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    13fb <main+0x17b>
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
mov    0x2bad(%rip),%rax
mov    (%rax),%esi
mov    0x2bbc(%rip),%rax
mov    (%rax),%edx
call   11a0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1440 <main+0x1c0>
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    -0x28(%rbp),%rdi
call   10e0 <inet_addr@plt>
mov    %eax,-0x58(%rbp)
mov    0x2b75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x60(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
cmp    $0x0,%rax
jge    14a6 <main+0x226>
lea    0xba2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x30(%rbp),%rdi
call   10d0 <SSL_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2b23(%rip),%rax
mov    (%rax),%esi
call   10b0 <BIO_new_socket@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1190 <SSL_set_bio@plt>
mov    -0x38(%rbp),%rdi
call   1120 <SSL_connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     1515 <main+0x295>
lea    0xb3d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
call   1180 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xb2a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xb24(%rip),%rsi
mov    $0x15,%edx
call   1050 <SSL_write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    156b <main+0x2eb>
lea    0xb1b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2a66(%rip),%rax
mov    (%rax),%edi
call   1180 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    1570 <main+0x2f0>
mov    -0x38(%rbp),%rdi
lea    -0x860(%rbp),%rsi
mov    $0x7ff,%edx
call   10c0 <SSL_read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xae6(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <SSL_get_error@plt>
mov    %eax,%ecx
mov    %ecx,-0x868(%rbp)
sub    $0x80,%eax
je     160f <main+0x38f>
jmp    15bd <main+0x33d>
mov    -0x868(%rbp),%eax
sub    $0x81,%eax
je     1627 <main+0x3a7>
jmp    15d3 <main+0x353>
mov    -0x868(%rbp),%eax
sub    $0x82,%eax
jne    1646 <main+0x3c6>
jmp    15e9 <main+0x369>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
lea    -0x860(%rbp),%rsi
lea    0xa7e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    165e <main+0x3de>
lea    0xa79(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x2992(%rip),%rax
mov    (%rax),%edi
lea    0xa64(%rip),%rsi
call   10f0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xa6a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    1570 <main+0x2f0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1bb,%ebx
xor    %r14d,%r14d
lea    0xd4b(%rip),%r12
mov    0x2d3c(%rip),%r13
jmp    12d7 <main+0x47>
xchg   %ax,%ax
mov    0x0(%r13),%rdi
call   1160 <atoi@plt>
mov    %eax,%ebx
add    $0xffff0000,%eax
cmp    $0xffff0000,%eax
jbe    1347 <main+0xb7>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1150 <getopt@plt>
cmp    $0x70,%eax
je     12c0 <main+0x30>
cmp    $0x68,%eax
jne    12f4 <main+0x64>
mov    0x0(%r13),%r14
jmp    12d7 <main+0x47>
cmp    $0xffffffff,%eax
jne    1347 <main+0xb7>
xor    %eax,%eax
call   10b0 <SSL_library_init@plt>
xor    %eax,%eax
call   1140 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   1110 <OpenSSL_add_all_algorithms@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
mov    0x2cc2(%rip),%r12
mov    (%r12),%esi
call   1040 <BIO_new_fp@plt>
xor    %eax,%eax
call   1070 <SSLv23_method@plt>
mov    %rax,%rdi
call   1120 <SSL_CTX_new@plt>
test   %rax,%rax
jne    1351 <main+0xc1>
lea    0xd0b(%rip),%rdi
jmp    13db <main+0x14b>
mov    $0x1,%edi
call   1170 <exit@plt>
test   %r14,%r14
jne    135f <main+0xcf>
lea    0xcfa(%rip),%rdi
jmp    13db <main+0x14b>
mov    %rax,%r15
mov    0x2c6f(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
mov    0x2c53(%rip),%rax
mov    (%rax),%edx
call   11b0 <socket@plt>
test   %eax,%eax
jns    1391 <main+0x101>
lea    0xd24(%rip),%rdi
jmp    13db <main+0x14b>
mov    %eax,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    %r14,%rdi
call   10f0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%r13),%eax
mov    %eax,0x4(%rsp)
mov    %ebx,%edi
call   1080 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %rsp,%rsi
mov    $0xc,%edx
call   1180 <connect@plt>
test   %rax,%rax
jns    13ea <main+0x15a>
lea    0xcca(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    %r15,%rdi
call   10e0 <SSL_new@plt>
mov    %rax,%rbx
mov    (%r12),%esi
mov    %ebp,%edi
call   10c0 <BIO_new_socket@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %rax,%rdx
call   11a0 <SSL_set_bio@plt>
mov    %rbx,%rdi
call   1130 <SSL_connect@plt>
test   %eax,%eax
jg     1431 <main+0x1a1>
lea    0xc80(%rip),%rdi
call   1060 <puts@plt>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
jmp    146c <main+0x1dc>
lea    0xc35(%rip),%rdi
call   1060 <puts@plt>
lea    0xbc1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x15,%edx
call   1050 <SSL_write@plt>
test   %eax,%eax
mov    0x2b66(%rip),%r13
jns    147b <main+0x1eb>
lea    0xc2e(%rip),%rdi
call   1060 <puts@plt>
mov    0x0(%r13),%edi
call   1190 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    0x10(%rsp),%r12
lea    0xb93(%rip),%r14
lea    0xb95(%rip),%r15
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x7ff,%edx
call   10d0 <SSL_read@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <SSL_get_error@plt>
cmp    $0x82,%eax
jne    14d6 <main+0x246>
movslq %ebp,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1490 <main+0x200>
cmp    $0x80,%eax
je     14fe <main+0x26e>
cmp    $0x81,%eax
jne    150a <main+0x27a>
mov    0x0(%r13),%edi
lea    0xb42(%rip),%rsi
call   1100 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    0xb73(%rip),%rdi
jmp    13db <main+0x14b>
lea    0xb72(%rip),%rdi
jmp    13db <main+0x14b>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"h:p:\00"
@optarg = global i8* null
@stderr = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.1 = [11 x i8] c"CTX ERROR\0A\00"
@.str.2 = [23 x i8] c"ERROR - host not set.\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [12 x i8] c"sock error\0A\00"
@.str.4 = [15 x i8] c"connect error\0A\00"
@.str.5 = [19 x i8] c"SSL connect error\0A\00"
@.str.6 = [12 x i8] c"Connected!\0A\00"
@.str.7 = [21 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\0D\0A\00"
@.str.8 = [17 x i8] c"SSL write error\0A\00"
@.str.9 = [9 x i8] c"ret: %d\0A\00"
@.str.10 = [14 x i8] c"no error: %s\0A\00"
@.str.11 = [12 x i8] c"no returen\0A\00"
@.str.12 = [28 x i8] c"SSL Error: Premature close\0A\00"
@.str.13 = [15 x i8] c"default error\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 i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca %struct.sockaddr_in
%17 = alloca [2048 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 443, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i32* null, i32** %15
br label %18
18: ; preds = %40, %2
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %21, i32* %6
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %41
23: ; preds = %18
%24 = load i32, i32* %6
switch i32 %24, label %38 [
i32 104, label %25
i32 112, label %27
]
25: ; preds = %23
%26 = load i8*, i8** @optarg
store i8* %26, i8** %10
br label %40
27: ; preds = %23
%28 = load i8*, i8** @optarg
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp sle i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i32, i32* %8
%34 = icmp sge i32 %33, 65536
br i1 %34, label %35, label %37
35: ; preds = %32, %27
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %32
br label %40
38: ; preds = %23
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %37, %25
br label %18
41: ; preds = %18
%42 = load i32*, i32** %15
%43 = icmp ne i32* %42, null
br i1 %43, label %51, label %44
44: ; preds = %41
%45 = call i32 (...) @SSL_library_init()
%46 = call i32 (...) @SSL_load_error_strings()
%47 = call i32 (...) @OpenSSL_add_all_algorithms()
%48 = load i32, i32* @stderr
%49 = load i32, i32* @BIO_NOCLOSE
%50 = call i32* @BIO_new_fp(i32 %48, i32 %49)
store i32* %50, i32** %15
br label %51
51: ; preds = %44, %41
%52 = call i32* (...) @SSLv23_method()
store i32* %52, i32** %13
%53 = load i32*, i32** %13
%54 = call i32* @SSL_CTX_new(i32* %53)
store i32* %54, i32** %11
%55 = load i32*, i32** %11
%56 = icmp ne i32* %55, null
br i1 %56, label %60, label %57
57: ; preds = %51
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %51
%61 = load i8*, i8** %10
%62 = icmp ne i8* %61, null
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %60
%67 = load i32, i32* @AF_INET
%68 = load i32, i32* @SOCK_STREAM
%69 = load i32, i32* @IPPROTO_TCP
%70 = call i32 @socket(i32 %67, i32 %68, i32 %69)
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %66
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %66
%77 = call i32 @memset(%struct.sockaddr_in* %16, i32 0, i32 12)
%78 = load i8*, i8** %10
%79 = call i32 @inet_addr(i8* %78)
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
%81 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %80, i32 0, i32 0
store i32 %79, i32* %81
%82 = load i32, i32* @AF_INET
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i32 %82, i32* %83
%84 = load i32, i32* %8
%85 = call i32 @htons(i32 %84)
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
store i32 %85, i32* %86
%87 = load i32, i32* %7
%88 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%89 = call i64 @connect(i32 %87, %struct.sockaddr* %88, i32 12)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %76
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %76
%95 = load i32*, i32** %11
%96 = call i32* @SSL_new(i32* %95)
store i32* %96, i32** %12
%97 = load i32, i32* %7
%98 = load i32, i32* @BIO_NOCLOSE
%99 = call i32* @BIO_new_socket(i32 %97, i32 %98)
store i32* %99, i32** %14
%100 = load i32*, i32** %12
%101 = load i32*, i32** %14
%102 = load i32*, i32** %14
%103 = call i32 @SSL_set_bio(i32* %100, i32* %101, i32* %102)
%104 = load i32*, i32** %12
%105 = call i32 @SSL_connect(i32* %104)
store i32 %105, i32* %9
%106 = load i32, i32* %9
%107 = icmp sle i32 %106, 0
br i1 %107, label %108, label %113
108: ; preds = %94
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%110 = load i32, i32* @stderr
%111 = call i32 @ERR_print_errors_fp(i32 %110)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %94
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%115 = load i32*, i32** %12
%116 = call i32 @SSL_write(i32* %115, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 21)
store i32 %116, i32* %9
%117 = load i32, i32* %9
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %124
119: ; preds = %113
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%121 = load i32, i32* @stderr
%122 = call i32 @ERR_print_errors_fp(i32 %121)
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %113
br label %125
125: ; preds = %124, %150
%126 = load i32*, i32** %12
%127 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%128 = call i32 @SSL_read(i32* %126, i8* %127, i32 2047)
store i32 %128, i32* %9
%129 = load i32, i32* %9
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %129)
%131 = load i32*, i32** %12
%132 = load i32, i32* %9
%133 = call i32 @SSL_get_error(i32* %131, i32 %132)
switch i32 %133, label %147 [
i32 130, label %134
i32 128, label %140
i32 129, label %143
]
134: ; preds = %125
%135 = load i32, i32* %9
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %136
store i8 0, i8* %137
%138 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %138)
br label %150
140: ; preds = %125
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %125
%144 = load i32, i32* @stderr
%145 = call i32 @fprintf(i32 %144, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0))
%146 = call i32 @exit(i32 1)
unreachable
147: ; preds = %125
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %134
br label %125
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"h:p:\00"
@optarg = global i8* null
@stderr = global i32 0
@BIO_NOCLOSE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.7 = [21 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\0D\0A\00"
@.str.9 = [9 x i8] c"ret: %d\0A\00"
@.str.10 = [14 x i8] c"no error: %s\0A\00"
@.str.12 = [28 x i8] c"SSL Error: Premature close\0A\00"
@str = [10 x i8] c"CTX ERROR\00"
@str.14 = [22 x i8] c"ERROR - host not set.\00"
@str.15 = [11 x i8] c"Connected!\00"
@str.16 = [11 x i8] c"no returen\00"
@str.17 = [14 x i8] c"default error\00"
@str.18 = [16 x i8] c"SSL write error\00"
@str.19 = [18 x i8] c"SSL connect error\00"
@str.20 = [14 x i8] c"connect error\00"
@str.21 = [11 x i8] c"sock error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2048 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
br label %6
6: ; preds = %12, %2
%7 = phi i8* [ %13, %12 ], [ null, %2 ]
%8 = phi i32 [ %10, %12 ], [ 443, %2 ]
br label %9
9: ; preds = %6, %14
%10 = phi i32 [ %16, %14 ], [ %8, %6 ]
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %21 [
i32 -1, label %23
i32 104, label %12
i32 112, label %14
]
12: ; preds = %9
%13 = load i8*, i8** @optarg
br label %6
14: ; preds = %9
%15 = load i8*, i8** @optarg
%16 = tail call i32 @atoi(i8* %15)
%17 = add i32 %16, -65536
%18 = icmp ult i32 %17, -65535
br i1 %18, label %19, label %9
19: ; preds = %14
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %9
%24 = tail call i32 (...) @SSL_library_init()
%25 = tail call i32 (...) @SSL_load_error_strings()
%26 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%27 = load i32, i32* @stderr
%28 = load i32, i32* @BIO_NOCLOSE
%29 = tail call i32* @BIO_new_fp(i32 %27, i32 %28)
%30 = tail call i32* (...) @SSLv23_method()
%31 = tail call i32* @SSL_CTX_new(i32* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %23
%37 = icmp eq i8* %7, null
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.14, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %36
%42 = load i32, i32* @AF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = load i32, i32* @IPPROTO_TCP
%45 = tail call i32 @socket(i32 %42, i32 %43, i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.21, i64 0, i64 0))
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %41
%51 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%52 = call i32 @inet_addr(i8* %7)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %52, i32* %53
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %54, i32* %55
%56 = call i32 @htons(i32 %10)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %56, i32* %57
%58 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%59 = call i64 @connect(i32 %45, %struct.sockaddr* %58, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %50
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.20, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %50
%65 = call i32* @SSL_new(i32* %31)
%66 = load i32, i32* @BIO_NOCLOSE
%67 = call i32* @BIO_new_socket(i32 %45, i32 %66)
%68 = call i32 @SSL_set_bio(i32* %65, i32* %67, i32* %67)
%69 = call i32 @SSL_connect(i32* %65)
%70 = icmp slt i32 %69, 1
br i1 %70, label %71, label %76
71: ; preds = %64
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.19, i64 0, i64 0))
%73 = load i32, i32* @stderr
%74 = call i32 @ERR_print_errors_fp(i32 %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %64
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.15, i64 0, i64 0))
%78 = call i32 @SSL_write(i32* %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 21)
%79 = icmp slt i32 %78, 0
br i1 %79, label %82, label %80
80: ; preds = %76
%81 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
br label %87
82: ; preds = %76
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.18, i64 0, i64 0))
%84 = load i32, i32* @stderr
%85 = call i32 @ERR_print_errors_fp(i32 %84)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %80, %91
%88 = call i32 @SSL_read(i32* %65, i8* %81, i32 2047)
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %88)
%90 = call i32 @SSL_get_error(i32* %65, i32 %88)
switch i32 %90, label %102 [
i32 130, label %91
i32 128, label %95
i32 129, label %98
]
91: ; preds = %87
%92 = sext i32 %88 to i64
%93 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %92
store i8 0, i8* %93
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %81)
br label %87
95: ; preds = %87
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %87
%99 = load i32, i32* @stderr
%100 = call i32 @fprintf(i32 %99, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %87
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.17, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
}