#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*/ url;
typedef int /*<<< orphan*/ X509_VERIFY_PARAM;
typedef int /*<<< orphan*/ X509;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_get_ssl(int /*<<< orphan*/ *, int /*<<< orphan*/ **);
int /*<<< orphan*/ *BIO_new_ssl_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_set_conn_hostname(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ ERR_free_strings();
unsigned long ERR_get_error();
char *ERR_reason_error_string(unsigned long);
int /*<<< orphan*/ EVP_cleanup();
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_get0_param(int /*<<< orphan*/ *);
int SSL_CTX_load_verify_locations(int /*<<< orphan*/ *, char *,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_set_verify(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_VERIFY_PEER;
scalar_t__ SSL_do_handshake(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ SSL_set_tlsext_host_name(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ TLS_method();
int /*<<< orphan*/ X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
int /*<<< orphan*/ X509_VERIFY_PARAM_set1_host(int /*<<< orphan*/ *, char *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ X509_VERIFY_PARAM_set_hostflags(int /*<<< orphan*/ *,
                                                   int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  unsigned int bundleLength = 0, urlLength = 0;
  if (argc == 3) {
    printf("UNSUPPORTED\n");
    return EXIT_SUCCESS;
  } else if (argc != 4) {
    printf("usage: %s <host> <port> <ca-bundle>\n", argv[0]);
    return EXIT_FAILURE;
  } else if ((urlLength = strlen(argv[1]) + strlen(argv[2]) + 2) > 1024) {
    printf("Too long URL: %d characters, max: %d\n", urlLength, 1024);
    return EXIT_FAILURE;
  } else if ((bundleLength = strlen(argv[3]) + 1) > 1024) {
    printf("Too long ca-bundle filepath: %d characters, max: %d\n",
           bundleLength, 1024);
    return EXIT_FAILURE;
  }
  char url[1024];
  snprintf(url, sizeof(url), "%s:%s", argv[1], argv[2]);
  char ca_bundle[1024];
  memcpy(ca_bundle, argv[3], bundleLength);
  int exitvalue = 0;
  BIO *sbio;
  SSL_CTX *ssl_ctx;
  SSL *ssl;
  X509 *cert;
  const char *servername = NULL;
  X509_VERIFY_PARAM *param = NULL;
  SSL_load_error_strings();
  SSL_library_init();
  ssl_ctx = SSL_CTX_new(TLS_method());
  param = SSL_CTX_get0_param(ssl_ctx);
  X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  X509_VERIFY_PARAM_set1_host(param, argv[1], 0);
  SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, NULL);
  if (SSL_CTX_load_verify_locations(ssl_ctx, ca_bundle, NULL) != 1) {
    printf("Couldn't load certificate trust store\n");
    printf("%s\n", ERR_reason_error_string(ERR_get_error()));
    exitvalue = EXIT_FAILURE;
    goto end;
  }
  sbio = BIO_new_ssl_connect(ssl_ctx);
  BIO_get_ssl(sbio, &ssl);
  if (!ssl) {
    printf("Connection failed\n");
    printf("%s\n", ERR_reason_error_string(ERR_get_error()));
    exitvalue = EXIT_FAILURE;
    goto connect_end;
  }
  SSL_set_tlsext_host_name(ssl, url);
  BIO_set_conn_hostname(sbio, url);
  if (SSL_do_handshake(ssl) <= 0) {
    unsigned long int error = ERR_get_error();
    printf("%s\n", ERR_reason_error_string(error));
    printf("REJECT\n");
  } else {
    printf("ACCEPT\n");
  }
connect_end:
  BIO_free_all(sbio);
end:
  SSL_CTX_free(ssl_ctx);
  EVP_cleanup();
  ERR_free_strings();
  return exitvalue;
}


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,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    12d0 <main+0x50>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1623 <main+0x3a3>
cmpl   $0x4,-0x8(%rbp)
je     1300 <main+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1623 <main+0x3a3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x864(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x864(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x400,%eax
jbe    1362 <main+0xe2>
mov    -0x18(%rbp),%esi
lea    0xced(%rip),%rdi
mov    $0x400,%edx
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1623 <main+0x3a3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x400,%eax
jbe    13a7 <main+0x127>
mov    -0x14(%rbp),%esi
lea    0xcce(%rip),%rdi
mov    $0x400,%edx
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1623 <main+0x3a3>
jmp    13ac <main+0x12c>
jmp    13b1 <main+0x131>
jmp    13b6 <main+0x136>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    $0x400,%esi
lea    0xcb4(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1100 <memcpy@plt>
movl   $0x0,-0x824(%rbp)
movq   $0x0,-0x850(%rbp)
movq   $0x0,-0x858(%rbp)
mov    $0x0,%al
call   1150 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   10d0 <SSL_library_init@plt>
mov    $0x0,%al
call   10b0 <TLS_method@plt>
mov    %eax,%edi
call   1120 <SSL_CTX_new@plt>
mov    %rax,-0x838(%rbp)
mov    -0x838(%rbp),%rdi
call   1170 <SSL_CTX_get0_param@plt>
mov    %rax,-0x858(%rbp)
mov    -0x858(%rbp),%rdi
mov    0x2b7f(%rip),%rax
mov    (%rax),%esi
call   1030 <X509_VERIFY_PARAM_set_hostflags@plt>
mov    -0x858(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %edx,%edx
call   1070 <X509_VERIFY_PARAM_set1_host@plt>
mov    -0x838(%rbp),%rdi
mov    0x2b4c(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <SSL_CTX_set_verify@plt>
mov    -0x838(%rbp),%rdi
lea    -0x820(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1130 <SSL_CTX_load_verify_locations@plt>
cmp    $0x1,%eax
je     14f1 <main+0x271>
lea    0xbdd(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1160 <ERR_get_error@plt>
mov    %rax,%rdi
call   10a0 <ERR_reason_error_string@plt>
mov    %rax,%rsi
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2afc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
jmp    1600 <main+0x380>
mov    -0x838(%rbp),%rdi
call   11a0 <BIO_new_ssl_connect@plt>
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rdi
lea    -0x840(%rbp),%rsi
call   1050 <BIO_get_ssl@plt>
cmpq   $0x0,-0x840(%rbp)
jne    1567 <main+0x2e7>
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1160 <ERR_get_error@plt>
mov    %rax,%rdi
call   10a0 <ERR_reason_error_string@plt>
mov    %rax,%rsi
lea    0xb6e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2a86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
jmp    15f4 <main+0x374>
mov    -0x840(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10c0 <SSL_set_tlsext_host_name@plt>
mov    -0x830(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10f0 <BIO_set_conn_hostname@plt>
mov    -0x840(%rbp),%rdi
call   1190 <SSL_do_handshake@plt>
cmp    $0x0,%rax
jg     15e1 <main+0x361>
mov    $0x0,%al
call   1160 <ERR_get_error@plt>
mov    %rax,-0x860(%rbp)
mov    -0x860(%rbp),%rdi
call   10a0 <ERR_reason_error_string@plt>
mov    %rax,%rsi
lea    0xaf3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xafc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15ef <main+0x36f>
lea    0xaf1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15f4 <main+0x374>
mov    -0x830(%rbp),%rdi
call   1180 <BIO_free_all@plt>
mov    -0x838(%rbp),%rdi
call   1140 <SSL_CTX_free@plt>
mov    $0x0,%al
call   10e0 <EVP_cleanup@plt>
mov    $0x0,%al
call   1110 <ERR_free_strings@plt>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
je     12bf <main+0x2f>
cmp    $0x3,%edi
jne    12ea <main+0x5a>
lea    0xe1b(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d0b(%rip),%rax
jmp    132f <main+0x9f>
mov    0x8(%rbx),%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1070 <strlen@plt>
lea    (%rax,%rbp,1),%esi
add    $0x2,%esi
cmp    $0x401,%esi
jb     12fd <main+0x6d>
lea    0xd3d(%rip),%rdi
jmp    131c <main+0x8c>
mov    (%rbx),%rsi
lea    0xd0c(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1328 <main+0x98>
mov    0x18(%rbx),%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
cmp    $0x401,%ebp
jb     1341 <main+0xb1>
lea    0xd31(%rip),%rdi
mov    %ebp,%esi
mov    $0x400,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
lea    0xd30(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   10a0 <snprintf@plt>
mov    0x18(%rbx),%rsi
lea    0x410(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%edx
call   1110 <memcpy@plt>
xor    %eax,%eax
call   1160 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   10e0 <SSL_library_init@plt>
xor    %eax,%eax
call   10c0 <TLS_method@plt>
mov    %eax,%edi
call   1130 <SSL_CTX_new@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1180 <SSL_CTX_get0_param@plt>
mov    %rax,%rbp
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1030 <X509_VERIFY_PARAM_set_hostflags@plt>
mov    0x8(%rbx),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1080 <X509_VERIFY_PARAM_set1_host@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %edx,%edx
call   1050 <SSL_CTX_set_verify@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1140 <SSL_CTX_load_verify_locations@plt>
cmp    $0x1,%eax
jne    143f <main+0x1af>
mov    %r14,%rdi
call   11b0 <BIO_new_ssl_connect@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1060 <BIO_get_ssl@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     146d <main+0x1dd>
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   10d0 <SSL_set_tlsext_host_name@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1100 <BIO_set_conn_hostname@plt>
mov    0x8(%rsp),%rdi
call   11a0 <SSL_do_handshake@plt>
test   %rax,%rax
jle    149b <main+0x20b>
lea    0xc65(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    14c0 <main+0x230>
lea    0xc60(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1170 <ERR_get_error@plt>
mov    %rax,%rdi
call   10b0 <ERR_reason_error_string@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    0x2b77(%rip),%rax
mov    (%rax),%ebp
jmp    14c8 <main+0x238>
lea    0xc12(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1170 <ERR_get_error@plt>
mov    %rax,%rdi
call   10b0 <ERR_reason_error_string@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    0x2b49(%rip),%rax
mov    (%rax),%ebp
jmp    14c0 <main+0x230>
xor    %ebp,%ebp
xor    %eax,%eax
call   1170 <ERR_get_error@plt>
mov    %rax,%rdi
call   10b0 <ERR_reason_error_string@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0xbe4(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1190 <BIO_free_all@plt>
mov    %r14,%rdi
call   1150 <SSL_CTX_free@plt>
xor    %eax,%eax
call   10f0 <EVP_cleanup@plt>
xor    %eax,%eax
call   1120 <ERR_free_strings@plt>
jmp    1331 <main+0xa1>

LLVM IR (-O0):
@.str = [13 x i8] c"UNSUPPORTED\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [37 x i8] c"usage: %s <host> <port> <ca-bundle>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [38 x i8] c"Too long URL: %d characters, max: %d\0A\00"
@.str.3 = [53 x i8] c"Too long ca-bundle filepath: %d characters, max: %d\0A\00"
@.str.4 = [6 x i8] c"%s:%s\00"
@X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS = global i32 0
@SSL_VERIFY_PEER = global i32 0
@.str.5 = [39 x i8] c"Couldn't load certificate trust store\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [19 x i8] c"Connection failed\0A\00"
@.str.8 = [8 x i8] c"REJECT\0A\00"
@.str.9 = [8 x i8] c"ACCEPT\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 [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 3
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_SUCCESS
store i32 %22, i32* %3
br label %145
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 4
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %145
32: ; preds = %23
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = add nsw i32 %36, %40
%42 = add nsw i32 %41, 2
store i32 %42, i32* %7
%43 = icmp ugt i32 %42, 1024
br i1 %43, label %44, label %48
44: ; preds = %32
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 1024)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %3
br label %145
48: ; preds = %32
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 @strlen(i8* %51)
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = icmp ugt i32 %53, 1024
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = load i32, i32* %6
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32 1024)
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %3
br label %145
59: ; preds = %48
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 @snprintf(i8* %63, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %66, i8* %69)
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 3
%74 = load i8*, i8** %73
%75 = load i32, i32* %6
%76 = call i32 @memcpy(i8* %71, i8* %74, i32 %75)
store i32 0, i32* %10
store i8* null, i8** %15
store i32* null, i32** %16
%77 = call i32 (...) @SSL_load_error_strings()
%78 = call i32 (...) @SSL_library_init()
%79 = call i32 (...) @TLS_method()
%80 = call i32* @SSL_CTX_new(i32 %79)
store i32* %80, i32** %12
%81 = load i32*, i32** %12
%82 = call i32* @SSL_CTX_get0_param(i32* %81)
store i32* %82, i32** %16
%83 = load i32*, i32** %16
%84 = load i32, i32* @X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS
%85 = call i32 @X509_VERIFY_PARAM_set_hostflags(i32* %83, i32 %84)
%86 = load i32*, i32** %16
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i32 @X509_VERIFY_PARAM_set1_host(i32* %86, i8* %89, i32 0)
%91 = load i32*, i32** %12
%92 = load i32, i32* @SSL_VERIFY_PEER
%93 = call i32 @SSL_CTX_set_verify(i32* %91, i32 %92, i32* null)
%94 = load i32*, i32** %12
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%96 = call i32 @SSL_CTX_load_verify_locations(i32* %94, i8* %95, i32* null)
%97 = icmp ne i32 %96, 1
br i1 %97, label %98, label %104
98: ; preds = %62
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%100 = call i64 (...) @ERR_get_error()
%101 = call i8* @ERR_reason_error_string(i64 %100)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %101)
%103 = load i32, i32* @EXIT_FAILURE
store i32 %103, i32* %10
br label %139
104: ; preds = %62
%105 = load i32*, i32** %12
%106 = call i32* @BIO_new_ssl_connect(i32* %105)
store i32* %106, i32** %11
%107 = load i32*, i32** %11
%108 = call i32 @BIO_get_ssl(i32* %107, i32** %13)
%109 = load i32*, i32** %13
%110 = icmp ne i32* %109, null
br i1 %110, label %117, label %111
111: ; preds = %104
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%113 = call i64 (...) @ERR_get_error()
%114 = call i8* @ERR_reason_error_string(i64 %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %114)
%116 = load i32, i32* @EXIT_FAILURE
store i32 %116, i32* %10
br label %136
117: ; preds = %104
%118 = load i32*, i32** %13
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%120 = call i32 @SSL_set_tlsext_host_name(i32* %118, i8* %119)
%121 = load i32*, i32** %11
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%123 = call i32 @BIO_set_conn_hostname(i32* %121, i8* %122)
%124 = load i32*, i32** %13
%125 = call i64 @SSL_do_handshake(i32* %124)
%126 = icmp sle i64 %125, 0
br i1 %126, label %127, label %133
127: ; preds = %117
%128 = call i64 (...) @ERR_get_error()
store i64 %128, i64* %17
%129 = load i64, i64* %17
%130 = call i8* @ERR_reason_error_string(i64 %129)
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %130)
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %135
133: ; preds = %117
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %135
135: ; preds = %133, %127
br label %136
136: ; preds = %135, %111
%137 = load i32*, i32** %11
%138 = call i32 @BIO_free_all(i32* %137)
br label %139
139: ; preds = %136, %98
%140 = load i32*, i32** %12
%141 = call i32 @SSL_CTX_free(i32* %140)
%142 = call i32 (...) @EVP_cleanup()
%143 = call i32 (...) @ERR_free_strings()
%144 = load i32, i32* %10
store i32 %144, i32* %3
br label %145
145: ; preds = %139, %55, %44, %26, %20
%146 = load i32, i32* %3
ret i32 %146
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str.1 = [37 x i8] c"usage: %s <host> <port> <ca-bundle>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [38 x i8] c"Too long URL: %d characters, max: %d\0A\00"
@.str.3 = [53 x i8] c"Too long ca-bundle filepath: %d characters, max: %d\0A\00"
@.str.4 = [6 x i8] c"%s:%s\00"
@X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS = global i32 0
@SSL_VERIFY_PEER = global i32 0
@str = [18 x i8] c"Connection failed\00"
@str.10 = [7 x i8] c"ACCEPT\00"
@str.11 = [7 x i8] c"REJECT\00"
@str.12 = [38 x i8] c"Couldn't load certificate trust store\00"
@str.13 = [12 x i8] c"UNSUPPORTED\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32*
switch i32 %0, label %9 [
i32 3, label %6
i32 4, label %13
]
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%8 = load i32, i32* @EXIT_SUCCESS
br label %95
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
br label %95
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strlen(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @strlen(i8* %18)
%20 = add i32 %16, 2
%21 = add i32 %20, %19
%22 = icmp ugt i32 %21, 1024
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 1024)
%25 = load i32, i32* @EXIT_FAILURE
br label %95
26: ; preds = %13
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = tail call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 1
%31 = icmp ugt i32 %30, 1024
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 1024)
%34 = load i32, i32* @EXIT_FAILURE
br label %95
35: ; preds = %26
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%37 = load i8*, i8** %14
%38 = load i8*, i8** %17
%39 = call i32 @snprintf(i8* %36, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* %38)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%41 = load i8*, i8** %27
%42 = call i32 @memcpy(i8* %40, i8* %41, i32 %30)
%43 = bitcast i32** %5 to i8*
%44 = call i32 (...) @SSL_load_error_strings()
%45 = call i32 (...) @SSL_library_init()
%46 = call i32 (...) @TLS_method()
%47 = call i32* @SSL_CTX_new(i32 %46)
%48 = call i32* @SSL_CTX_get0_param(i32* %47)
%49 = load i32, i32* @X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS
%50 = call i32 @X509_VERIFY_PARAM_set_hostflags(i32* %48, i32 %49)
%51 = load i8*, i8** %14
%52 = call i32 @X509_VERIFY_PARAM_set1_host(i32* %48, i8* %51, i32 0)
%53 = load i32, i32* @SSL_VERIFY_PEER
%54 = call i32 @SSL_CTX_set_verify(i32* %47, i32 %53, i32* null)
%55 = call i32 @SSL_CTX_load_verify_locations(i32* %47, i8* %40, i32* null)
%56 = icmp eq i32 %55, 1
br i1 %56, label %63, label %57
57: ; preds = %35
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.12, i64 0, i64 0))
%59 = call i64 (...) @ERR_get_error()
%60 = call i8* @ERR_reason_error_string(i64 %59)
%61 = call i32 @puts(i8* dereferenceable(1) %60)
%62 = load i32, i32* @EXIT_FAILURE
br label %90
63: ; preds = %35
%64 = call i32* @BIO_new_ssl_connect(i32* %47)
%65 = call i32 @BIO_get_ssl(i32* %64, i32** %5)
%66 = load i32*, i32** %5
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %74
68: ; preds = %63
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%70 = call i64 (...) @ERR_get_error()
%71 = call i8* @ERR_reason_error_string(i64 %70)
%72 = call i32 @puts(i8* dereferenceable(1) %71)
%73 = load i32, i32* @EXIT_FAILURE
br label %87
74: ; preds = %63
%75 = call i32 @SSL_set_tlsext_host_name(i32* %66, i8* %36)
%76 = call i32 @BIO_set_conn_hostname(i32* %64, i8* %36)
%77 = load i32*, i32** %5
%78 = call i64 @SSL_do_handshake(i32* %77)
%79 = icmp slt i64 %78, 1
br i1 %79, label %80, label %85
80: ; preds = %74
%81 = call i64 (...) @ERR_get_error()
%82 = call i8* @ERR_reason_error_string(i64 %81)
%83 = call i32 @puts(i8* dereferenceable(1) %82)
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
br label %87
85: ; preds = %74
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.10, i64 0, i64 0))
br label %87
87: ; preds = %80, %85, %68
%88 = phi i32 [ 0, %80 ], [ 0, %85 ], [ %73, %68 ]
%89 = call i32 @BIO_free_all(i32* %64)
br label %90
90: ; preds = %87, %57
%91 = phi i32 [ %62, %57 ], [ %88, %87 ]
%92 = call i32 @SSL_CTX_free(i32* %47)
%93 = call i32 (...) @EVP_cleanup()
%94 = call i32 (...) @ERR_free_strings()
br label %95
95: ; preds = %90, %32, %23, %9, %6
%96 = phi i32 [ %8, %6 ], [ %12, %9 ], [ %25, %23 ], [ %34, %32 ], [ %91, %90 ]
ret i32 %96
}