#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 */
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ server_addr;
typedef int pid_t;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(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_load_error_strings();
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSL_shutdown(int /*<<< orphan*/ *);
int SSL_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ SSLv23_client_method();
int /*<<< orphan*/ ShowCerts(int /*<<< orphan*/ *);
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ make_socket_nonblocking(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  char buffer[1024];
  struct sockaddr_in server_addr;
  struct hostent *host;
  int portnumber, nbytes;
  pid_t pid;
  SSL_CTX *ctx;
  SSL *ssl;
  if (argc != 3) {
    fprintf(stderr, "Usage:%s hostname portnumber\a\n", argv[0]);
    exit(1);
  }
  if ((host = gethostbyname(argv[1])) == NULL) {
    fprintf(stderr, "Gethostname error\n");
    exit(1);
  }
  if ((portnumber = atoi(argv[2])) < 0) {
    fprintf(stderr, "Usage:%s hostname portnumber\a\n", argv[0]);
    exit(1);
  }
  SSL_library_init();
  OpenSSL_add_all_algorithms();
  SSL_load_error_strings();
  ctx = SSL_CTX_new(SSLv23_client_method());
  if (ctx == NULL) {
    ERR_print_errors_fp(stdout);
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "Socket Error:%s\a\n", strerror(errno));
    exit(1);
  }
  make_socket_nonblocking(sockfd);
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(portnumber);
  server_addr.sin_addr = *((struct in_addr *)host->h_addr);
  if (connect(sockfd, (struct sockaddr *)(&server_addr),
              sizeof(struct sockaddr)) == -1) {
    fprintf(stderr, "Connect Error:%s\a\n", strerror(errno));
    exit(1);
  }
  printf("connected!\n");
  ssl = SSL_new(ctx);
  SSL_set_fd(ssl, sockfd);
  if (SSL_connect(ssl) == -1)
    ERR_print_errors_fp(stderr);
  else {
    printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
    ShowCerts(ssl);
    printf("\n");
  }
  if ((pid = fork()) == -1) {
    fprintf(stderr, "Fork error:%s\n\a", strerror(errno));
    exit(1);
  }
  if (pid == 0) {
    while (1) {
      nbytes = SSL_read(ssl, buffer, 1024);
      if (nbytes > 0) {
        buffer[nbytes] = '\0';
        printf("%s\n", buffer);
      }
    }
  }
  while (1) {
    if ((nbytes = read(0, buffer, 1024)) == -1) {
      fprintf(stderr, "Read Error:%s\n", strerror(errno));
      exit(1);
    }
    if (nbytes > 1)
      buffer[nbytes - 1] = '\0';
    if (strcmp("exit", buffer) == 0) {
      printf("Chat logout!\n");
      SSL_shutdown(ssl);
      SSL_free(ssl);
      SSL_CTX_free(ctx);
      close(sockfd);
      exit(0);
    }
    nbytes = SSL_write(ssl, buffer, strlen(buffer));
  }
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     134b <main+0x4b>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcc6(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1140 <gethostbyname@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jne    138a <main+0x8a>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
lea    0xca6(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   11c0 <atoi@plt>
mov    %eax,-0x43c(%rbp)
cmp    $0x0,%eax
jge    13ce <main+0xce>
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc43(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
mov    $0x0,%al
call   10e0 <SSL_library_init@plt>
mov    $0x0,%al
call   1160 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   11a0 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   1050 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1170 <SSL_CTX_new@plt>
mov    %rax,-0x450(%rbp)
cmpq   $0x0,-0x450(%rbp)
jne    141e <main+0x11e>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
call   1200 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
mov    0x2bc3(%rip),%rax
mov    (%rax),%edi
mov    0x2ba2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1220 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1481 <main+0x181>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x45c(%rbp)
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
mov    -0x45c(%rbp),%edi
mov    %rax,%rdx
lea    0xbc2(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <make_socket_nonblocking@plt>
lea    -0x430(%rbp),%rdi
mov    $0xc,%esi
call   11b0 <bzero@plt>
mov    0x2b47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    -0x43c(%rbp),%edi
call   10a0 <htons@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x438(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x4,%edx
call   11e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1527 <main+0x227>
mov    0x2ae8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x460(%rbp)
mov    0x2ac9(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
mov    -0x460(%rbp),%edi
mov    %rax,%rdx
lea    0xb2e(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
lea    0xb29(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    -0x450(%rbp),%rdi
call   1110 <SSL_new@plt>
mov    %rax,-0x458(%rbp)
mov    -0x458(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <SSL_set_fd@plt>
mov    -0x458(%rbp),%rdi
call   1180 <SSL_connect@plt>
cmp    $0xffffffff,%eax
jne    157f <main+0x27f>
mov    0x2a65(%rip),%rax
mov    (%rax),%edi
call   1200 <ERR_print_errors_fp@plt>
jmp    15b6 <main+0x2b6>
mov    -0x458(%rbp),%rdi
call   10d0 <SSL_get_cipher@plt>
mov    %rax,%rsi
lea    0xace(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    -0x458(%rbp),%rdi
call   1060 <ShowCerts@plt>
lea    0xa6e(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    $0x0,%al
call   1210 <fork@plt>
mov    %eax,-0x444(%rbp)
cmp    $0xffffffff,%eax
jne    160a <main+0x30a>
mov    0x2a05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x464(%rbp)
mov    0x29e6(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
mov    -0x464(%rbp),%edi
mov    %rax,%rdx
lea    0xa88(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
cmpl   $0x0,-0x444(%rbp)
jne    1670 <main+0x370>
jmp    161c <main+0x31c>
mov    -0x458(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10f0 <SSL_read@plt>
mov    %eax,-0x440(%rbp)
cmpl   $0x0,-0x440(%rbp)
jle    166b <main+0x36b>
movslq -0x440(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xa38(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
jmp    161c <main+0x31c>
jmp    1675 <main+0x375>
lea    -0x420(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1100 <read@plt>
mov    %eax,-0x440(%rbp)
cmp    $0xffffffff,%eax
jne    16d5 <main+0x3d5>
mov    0x293a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x468(%rbp)
mov    0x291b(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
mov    -0x468(%rbp),%edi
mov    %rax,%rdx
lea    0x9cd(%rip),%rsi
mov    $0x0,%al
call   1150 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
cmpl   $0x1,-0x440(%rbp)
jle    16f5 <main+0x3f5>
mov    -0x440(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0x99d(%rip),%rdi
call   1120 <strcmp@plt>
cmp    $0x0,%rax
jne    1753 <main+0x453>
lea    0x98c(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    -0x458(%rbp),%rdi
call   1130 <SSL_shutdown@plt>
mov    -0x458(%rbp),%rdi
call   1070 <SSL_free@plt>
mov    -0x450(%rbp),%rdi
call   1190 <SSL_CTX_free@plt>
mov    -0x14(%rbp),%edi
call   10c0 <close@plt>
xor    %edi,%edi
call   11d0 <exit@plt>
mov    -0x458(%rbp),%rax
mov    %rax,-0x478(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x470(%rbp)
lea    -0x420(%rbp),%rdi
call   1090 <strlen@plt>
mov    -0x478(%rbp),%rdi
mov    -0x470(%rbp),%rsi
mov    %eax,%edx
call   1030 <SSL_write@plt>
mov    %eax,-0x440(%rbp)
jmp    1675 <main+0x375>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    14b5 <main+0x195>
mov    0x8(%rbx),%rdi
call   1160 <gethostbyname@plt>
test   %rax,%rax
je     14f9 <main+0x1d9>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
call   11e0 <atoi@plt>
test   %eax,%eax
js     14b5 <main+0x195>
mov    %eax,%ebp
xor    %eax,%eax
call   1100 <SSL_library_init@plt>
xor    %eax,%eax
call   1180 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   11c0 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   1060 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1190 <SSL_CTX_new@plt>
test   %rax,%rax
je     151a <main+0x1fa>
mov    %rax,%r14
mov    0x2c4d(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2c2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1240 <socket@plt>
cmp    $0xffffffff,%eax
je     1532 <main+0x212>
mov    %eax,%r15d
mov    %eax,%edi
call   1050 <make_socket_nonblocking@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   11d0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   10c0 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1200 <connect@plt>
cmp    $0xffffffff,%eax
je     1555 <main+0x235>
lea    0xc8b(%rip),%rdi
call   1070 <puts@plt>
mov    %r14,%rdi
call   1130 <SSL_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
call   10a0 <SSL_set_fd@plt>
mov    %rbx,%rdi
call   11a0 <SSL_connect@plt>
cmp    $0xffffffff,%eax
je     1463 <main+0x143>
mov    %rbx,%rdi
call   10f0 <SSL_get_cipher@plt>
lea    0xc12(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10d0 <printf@plt>
mov    %rbx,%rdi
call   1080 <ShowCerts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1471 <main+0x151>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
call   1220 <ERR_print_errors_fp@plt>
xor    %eax,%eax
call   1230 <fork@plt>
test   %eax,%eax
jne    14cd <main+0x1ad>
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1110 <SSL_read@plt>
test   %eax,%eax
jle    1490 <main+0x170>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbp,%rdi
call   1070 <puts@plt>
jmp    1490 <main+0x170>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb38(%rip),%rsi
jmp    1609 <main+0x2e9>
cmp    $0xffffffff,%eax
jne    1578 <main+0x258>
mov    0x2afb(%rip),%rax
mov    (%rax),%ebx
mov    0x2ae2(%rip),%rax
mov    (%rax),%edi
call   1210 <strerror@plt>
lea    0xb81(%rip),%rsi
jmp    1604 <main+0x2e4>
mov    0x2ad8(%rip),%rax
mov    (%rax),%edi
lea    0xb16(%rip),%rsi
xor    %eax,%eax
call   1170 <fprintf@plt>
mov    $0x1,%edi
call   11f0 <exit@plt>
mov    0x2a9f(%rip),%rax
mov    (%rax),%edi
call   1220 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   11f0 <exit@plt>
mov    0x2a9f(%rip),%rax
mov    (%rax),%ebx
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
call   1210 <strerror@plt>
lea    0xae2(%rip),%rsi
jmp    1604 <main+0x2e4>
mov    0x2a7c(%rip),%rax
mov    (%rax),%ebx
mov    0x2a63(%rip),%rax
mov    (%rax),%edi
call   1210 <strerror@plt>
lea    0xad1(%rip),%rsi
jmp    1604 <main+0x2e4>
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1120 <read@plt>
cmp    $0xffffffff,%eax
je     15e6 <main+0x2c6>
lea    0xaff(%rip),%r12
lea    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
cmp    $0x2,%eax
jl     15ad <main+0x28d>
add    $0xffffffff,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1140 <strcmp@plt>
test   %rax,%rax
je     161a <main+0x2fa>
mov    %rbp,%rdi
call   10b0 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <SSL_write@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1120 <read@plt>
cmp    $0xffffffff,%eax
jne    15a0 <main+0x280>
mov    0x29eb(%rip),%rax
mov    (%rax),%ebx
mov    0x29d2(%rip),%rax
mov    (%rax),%edi
call   1210 <strerror@plt>
lea    0xa81(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1170 <fprintf@plt>
mov    $0x1,%edi
call   11f0 <exit@plt>
lea    0xa83(%rip),%rdi
call   1070 <puts@plt>
mov    %rbx,%rdi
call   1150 <SSL_shutdown@plt>
mov    %rbx,%rdi
call   1090 <SSL_free@plt>
mov    %r14,%rdi
call   11b0 <SSL_CTX_free@plt>
mov    %r15d,%edi
call   10e0 <close@plt>
xor    %edi,%edi
call   11f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Usage:%s hostname portnumber\07\0A\00"
@.str.1 = [19 x i8] c"Gethostname error\0A\00"
@stdout = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"Socket Error:%s\07\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"Connect Error:%s\07\0A\00"
@.str.4 = [12 x i8] c"connected!\0A\00"
@.str.5 = [30 x i8] c"Connected with %s encryption\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [16 x i8] c"Fork error:%s\0A\07\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [15 x i8] c"Read Error:%s\0A\00"
@.str.10 = [5 x i8] c"exit\00"
@.str.11 = [14 x i8] c"Chat logout!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.hostent*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call %struct.hostent* @gethostbyname(i8* %27)
store %struct.hostent* %28, %struct.hostent** %9
%29 = icmp eq %struct.hostent* %28, null
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %10
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %34
%48 = call i32 (...) @SSL_library_init()
%49 = call i32 (...) @OpenSSL_add_all_algorithms()
%50 = call i32 (...) @SSL_load_error_strings()
%51 = call i32 (...) @SSLv23_client_method()
%52 = call i32* @SSL_CTX_new(i32 %51)
store i32* %52, i32** %13
%53 = load i32*, i32** %13
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load i32, i32* @stdout
%57 = call i32 @ERR_print_errors_fp(i32 %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %47
%60 = load i32, i32* @AF_INET
%61 = load i32, i32* @SOCK_STREAM
%62 = call i32 @socket(i32 %60, i32 %61, i32 0)
store i32 %62, i32* %6
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %70
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %59
%71 = load i32, i32* %6
%72 = call i32 @make_socket_nonblocking(i32 %71)
%73 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%74 = load i32, i32* @AF_INET
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %74, i32* %75
%76 = load i32, i32* %10
%77 = call i32 @htons(i32 %76)
%78 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %77, i32* %78
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%80 = load %struct.hostent*, %struct.hostent** %9
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %80, i32 0, i32 0
%82 = load i64, i64* %81
%83 = inttoptr i64 %82 to %struct.in_addr*
%84 = bitcast %struct.in_addr* %79 to i8*
%85 = bitcast %struct.in_addr* %83 to i8*
%86 = load i32, i32* %6
%87 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%88 = call i32 @connect(i32 %86, %struct.sockaddr* %87, i32 4)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %96
90: ; preds = %70
%91 = load i32, i32* @stderr
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %93)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %70
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%98 = load i32*, i32** %13
%99 = call i32* @SSL_new(i32* %98)
store i32* %99, i32** %14
%100 = load i32*, i32** %14
%101 = load i32, i32* %6
%102 = call i32 @SSL_set_fd(i32* %100, i32 %101)
%103 = load i32*, i32** %14
%104 = call i32 @SSL_connect(i32* %103)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %109
106: ; preds = %96
%107 = load i32, i32* @stderr
%108 = call i32 @ERR_print_errors_fp(i32 %107)
br label %116
109: ; preds = %96
%110 = load i32*, i32** %14
%111 = call i8* @SSL_get_cipher(i32* %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %111)
%113 = load i32*, i32** %14
%114 = call i32 @ShowCerts(i32* %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %116
116: ; preds = %109, %106
%117 = call i32 (...) @fork()
store i32 %117, i32* %12
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %125
119: ; preds = %116
%120 = load i32, i32* @stderr
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %122)
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %116
%126 = load i32, i32* %12
%127 = icmp eq i32 %126, 0
br i1 %127, label %128, label %142
128: ; preds = %125
br label %129
129: ; preds = %128, %141
%130 = load i32*, i32** %14
%131 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%132 = call i32 @SSL_read(i32* %130, i8* %131, i32 1024)
store i32 %132, i32* %11
%133 = load i32, i32* %11
%134 = icmp sgt i32 %133, 0
br i1 %134, label %135, label %141
135: ; preds = %129
%136 = load i32, i32* %11
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %137
store i8 0, i8* %138
%139 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %139)
br label %141
141: ; preds = %135, %129
br label %129
142: ; preds = %125
br label %143
143: ; preds = %142, %176
%144 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%145 = call i32 @read(i32 0, i8* %144, i32 1024)
store i32 %145, i32* %11
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %153
147: ; preds = %143
%148 = load i32, i32* @stderr
%149 = load i32, i32* @errno
%150 = call i8* @strerror(i32 %149)
%151 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %150)
%152 = call i32 @exit(i32 1)
unreachable
153: ; preds = %143
%154 = load i32, i32* %11
%155 = icmp sgt i32 %154, 1
br i1 %155, label %156, label %161
156: ; preds = %153
%157 = load i32, i32* %11
%158 = sub nsw i32 %157, 1
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %159
store i8 0, i8* %160
br label %161
161: ; preds = %156, %153
%162 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%163 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %162)
%164 = icmp eq i64 %163, 0
br i1 %164, label %165, label %176
165: ; preds = %161
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%167 = load i32*, i32** %14
%168 = call i32 @SSL_shutdown(i32* %167)
%169 = load i32*, i32** %14
%170 = call i32 @SSL_free(i32* %169)
%171 = load i32*, i32** %13
%172 = call i32 @SSL_CTX_free(i32* %171)
%173 = load i32, i32* %6
%174 = call i32 @close(i32 %173)
%175 = call i32 @exit(i32 0)
unreachable
176: ; preds = %161
%177 = load i32*, i32** %14
%178 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%179 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%180 = call i32 @strlen(i8* %179)
%181 = call i32 @SSL_write(i32* %177, i8* %178, i32 %180)
store i32 %181, i32* %11
br label %143
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Usage:%s hostname portnumber\07\0A\00"
@.str.1 = [19 x i8] c"Gethostname error\0A\00"
@stdout = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"Socket Error:%s\07\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"Connect Error:%s\07\0A\00"
@.str.5 = [30 x i8] c"Connected with %s encryption\0A\00"
@.str.7 = [16 x i8] c"Fork error:%s\0A\07\00"
@.str.9 = [15 x i8] c"Read Error:%s\0A\00"
@.str.10 = [5 x i8] c"exit\00"
@str = [11 x i8] c"connected!\00"
@str.12 = [13 x i8] c"Chat logout!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call %struct.hostent* @gethostbyname(i8* %15)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %22
%33 = tail call i32 (...) @SSL_library_init()
%34 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%35 = tail call i32 (...) @SSL_load_error_strings()
%36 = tail call i32 (...) @SSLv23_client_method()
%37 = tail call i32* @SSL_CTX_new(i32 %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %32
%40 = load i32, i32* @stdout
%41 = tail call i32 @ERR_print_errors_fp(i32 %40)
%42 = tail call i32 @exit(i32 1)
unreachable
43: ; preds = %32
%44 = load i32, i32* @AF_INET
%45 = load i32, i32* @SOCK_STREAM
%46 = tail call i32 @socket(i32 %44, i32 %45, i32 0)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %43
%55 = tail call i32 @make_socket_nonblocking(i32 %46)
%56 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%57 = load i32, i32* @AF_INET
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %57, i32* %58
%59 = tail call i32 @htons(i32 %25)
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %59, i32* %60
%61 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to i32*
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%65 = load i32, i32* %63
store i32 %65, i32* %64
%66 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%67 = call i32 @connect(i32 %46, %struct.sockaddr* %66, i32 4)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %75
69: ; preds = %54
%70 = load i32, i32* @stderr
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %54
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%77 = call i32* @SSL_new(i32* %37)
%78 = call i32 @SSL_set_fd(i32* %77, i32 %46)
%79 = call i32 @SSL_connect(i32* %77)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %84
81: ; preds = %75
%82 = load i32, i32* @stderr
%83 = call i32 @ERR_print_errors_fp(i32 %82)
br label %89
84: ; preds = %75
%85 = call i8* @SSL_get_cipher(i32* %77)
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = call i32 @ShowCerts(i32* %77)
%88 = call i32 @putchar(i32 10)
br label %89
89: ; preds = %84, %81
%90 = call i32 (...) @fork()
switch i32 %90, label %91 [
i32 -1, label %94
i32 0, label %100
]
91: ; preds = %89
%92 = call i32 @read(i32 0, i8* %5, i32 1024)
%93 = icmp eq i32 %92, -1
br i1 %93, label %108, label %114
94: ; preds = %89
%95 = load i32, i32* @stderr
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %97)
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %89, %107
%101 = call i32 @SSL_read(i32* %77, i8* %5, i32 1024)
%102 = icmp sgt i32 %101, 0
br i1 %102, label %103, label %107
103: ; preds = %100
%104 = zext i32 %101 to i64
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %104
store i8 0, i8* %105
%106 = call i32 @puts(i8* %5)
br label %107
107: ; preds = %103, %100
br label %100
108: ; preds = %131, %91
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %91, %131
%115 = phi i32 [ %134, %131 ], [ %92, %91 ]
%116 = icmp sgt i32 %115, 1
br i1 %116, label %117, label %121
117: ; preds = %114
%118 = add nsw i32 %115, -1
%119 = zext i32 %118 to i64
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %119
store i8 0, i8* %120
br label %121
121: ; preds = %117, %114
%122 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %5)
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %131
124: ; preds = %121
%125 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%126 = call i32 @SSL_shutdown(i32* %77)
%127 = call i32 @SSL_free(i32* %77)
%128 = call i32 @SSL_CTX_free(i32* %37)
%129 = call i32 @close(i32 %46)
%130 = call i32 @exit(i32 0)
unreachable
131: ; preds = %121
%132 = call i32 @strlen(i8* %5)
%133 = call i32 @SSL_write(i32* %77, i8* %5, i32 %132)
%134 = call i32 @read(i32 0, i8* %5, i32 1024)
%135 = icmp eq i32 %134, -1
br i1 %135, label %108, label %114
}