#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;
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*/ EXIT_FAILURE;
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*/ *);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
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*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main() {
  int fd, ret;
  struct sockaddr_in addr;
  SSL *ssl;
  SSL_CTX *ctx;
  if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket\n");
    exit(EXIT_FAILURE);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(4321);
  inet_pton(AF_INET, "192.168.101.112", &addr.sin_addr.s_addr);
  if ((ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr))) == -1) {
    perror("connect");
    exit(EXIT_FAILURE);
  }
  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(EXIT_FAILURE);
  }
  ssl = SSL_new(ctx);
  if (ssl == NULL) {
    ERR_print_errors_fp(stdout);
    exit(EXIT_FAILURE);
  }
  SSL_set_fd(ssl, fd);
  if (SSL_connect(ssl) == -1) {
    ERR_print_errors_fp(stdout);
    exit(EXIT_FAILURE);
  }
  char *str = "baby, this is the message from client...\n";
  int len = SSL_write(ssl, str, strlen(str));
  if (len <= 0) {
    printf("send msg failed...\n");
    exit(EXIT_FAILURE);
  }
  SSL_shutdown(ssl);
  SSL_free(ssl);
  close(fd);
  SSL_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    12be <main+0x4e>
lea    0xd55(%rip),%rdi
call   1150 <perror@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x10e1,%edi
call   1080 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rdx
lea    0xd0d(%rip),%rsi
call   1100 <inet_pton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1337 <main+0xc7>
lea    0xcf4(%rip),%rdi
call   1150 <perror@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    $0x0,%al
call   10c0 <SSL_library_init@plt>
mov    $0x0,%al
call   10f0 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   1140 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   1040 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1110 <SSL_CTX_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1385 <main+0x115>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   1180 <ERR_print_errors_fp@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <SSL_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13b9 <main+0x149>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
call   1180 <ERR_print_errors_fp@plt>
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <SSL_set_fd@plt>
mov    -0x20(%rbp),%rdi
call   1120 <SSL_connect@plt>
cmp    $0xffffffff,%eax
jne    13f3 <main+0x183>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
call   1180 <ERR_print_errors_fp@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
lea    0xc26(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <SSL_write@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     144d <main+0x1dd>
lea    0xc10(%rip),%rdi
call   1090 <printf@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <SSL_shutdown@plt>
mov    -0x20(%rbp),%rdi
call   1050 <SSL_free@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
mov    -0x28(%rbp),%rdi
call   1130 <SSL_CTX_free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2d67(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
cmp    $0xffffffff,%eax
je     13a4 <main+0x134>
mov    %eax,%r14d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    $0x10e1,%edi
call   1090 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x0(%rbp),%edi
lea    0xd35(%rip),%rsi
mov    %rbx,%rdx
call   1100 <inet_pton@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
cmp    $0xffffffff,%eax
je     13ad <main+0x13d>
xor    %eax,%eax
call   10c0 <SSL_library_init@plt>
xor    %eax,%eax
call   10f0 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   1140 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   1040 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1110 <SSL_CTX_new@plt>
test   %rax,%rax
je     1394 <main+0x124>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <SSL_new@plt>
test   %rax,%rax
je     1394 <main+0x124>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14d,%esi
call   1070 <SSL_set_fd@plt>
mov    %rbp,%rdi
call   1120 <SSL_connect@plt>
cmp    $0xffffffff,%eax
je     1394 <main+0x124>
lea    0xcd2(%rip),%r15
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <SSL_write@plt>
test   %eax,%eax
jle    13bb <main+0x14b>
mov    %rbp,%rdi
call   10e0 <SSL_shutdown@plt>
mov    %rbp,%rdi
call   1060 <SSL_free@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    %rbx,%rdi
call   1130 <SSL_CTX_free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
call   1180 <ERR_print_errors_fp@plt>
jmp    13c7 <main+0x157>
lea    0xc55(%rip),%rdi
jmp    13b4 <main+0x144>
lea    0xc64(%rip),%rdi
call   1150 <perror@plt>
jmp    13c7 <main+0x157>
lea    0xc88(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [8 x i8] c"socket\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"192.168.101.112\00"
@.str.2 = [8 x i8] c"connect\00"
@stdout = global i32 0
@.str.3 = [42 x i8] c"baby, this is the message from client...\0A\00"
@.str.4 = [20 x i8] c"send msg failed...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 4321)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = call i32 @inet_pton(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i32 @connect(i32 %27, %struct.sockaddr* %28, i32 12)
store i32 %29, i32* %3
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %17
%36 = call i32 (...) @SSL_library_init()
%37 = call i32 (...) @OpenSSL_add_all_algorithms()
%38 = call i32 (...) @SSL_load_error_strings()
%39 = call i32 (...) @SSLv23_client_method()
%40 = call i32* @SSL_CTX_new(i32 %39)
store i32* %40, i32** %6
%41 = load i32*, i32** %6
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %35
%44 = load i32, i32* @stdout
%45 = call i32 @ERR_print_errors_fp(i32 %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %35
%49 = load i32*, i32** %6
%50 = call i32* @SSL_new(i32* %49)
store i32* %50, i32** %5
%51 = load i32*, i32** %5
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i32, i32* @stdout
%55 = call i32 @ERR_print_errors_fp(i32 %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %48
%59 = load i32*, i32** %5
%60 = load i32, i32* %2
%61 = call i32 @SSL_set_fd(i32* %59, i32 %60)
%62 = load i32*, i32** %5
%63 = call i32 @SSL_connect(i32* %62)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %70
65: ; preds = %58
%66 = load i32, i32* @stdout
%67 = call i32 @ERR_print_errors_fp(i32 %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %58
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8** %7
%71 = load i32*, i32** %5
%72 = load i8*, i8** %7
%73 = load i8*, i8** %7
%74 = call i32 @strlen(i8* %73)
%75 = call i32 @SSL_write(i32* %71, i8* %72, i32 %74)
store i32 %75, i32* %8
%76 = load i32, i32* %8
%77 = icmp sle i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %70
%79 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %70
%83 = load i32*, i32** %5
%84 = call i32 @SSL_shutdown(i32* %83)
%85 = load i32*, i32** %5
%86 = call i32 @SSL_free(i32* %85)
%87 = load i32, i32* %2
%88 = call i32 @close(i32 %87)
%89 = load i32*, i32** %6
%90 = call i32 @SSL_CTX_free(i32* %89)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [8 x i8] c"socket\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"192.168.101.112\00"
@.str.2 = [8 x i8] c"connect\00"
@stdout = global i32 0
@.str.3 = [42 x i8] c"baby, this is the message from client...\0A\00"
@str = [19 x i8] c"send msg failed...\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 4321)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
%19 = call i32 @inet_pton(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i32 @connect(i32 %5, %struct.sockaddr* %20, i32 12)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %11
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %11
%28 = call i32 (...) @SSL_library_init()
%29 = call i32 (...) @OpenSSL_add_all_algorithms()
%30 = call i32 (...) @SSL_load_error_strings()
%31 = call i32 (...) @SSLv23_client_method()
%32 = call i32* @SSL_CTX_new(i32 %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %27
%35 = load i32, i32* @stdout
%36 = call i32 @ERR_print_errors_fp(i32 %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %27
%40 = call i32* @SSL_new(i32* %32)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* @stdout
%44 = call i32 @ERR_print_errors_fp(i32 %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %39
%48 = call i32 @SSL_set_fd(i32* %40, i32 %5)
%49 = call i32 @SSL_connect(i32* %40)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i32, i32* @stdout
%53 = call i32 @ERR_print_errors_fp(i32 %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %47
%57 = call i32 @strlen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @SSL_write(i32* %40, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = icmp slt i32 %58, 1
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %56
%65 = call i32 @SSL_shutdown(i32* %40)
%66 = call i32 @SSL_free(i32* %40)
%67 = call i32 @close(i32 %5)
%68 = call i32 @SSL_CTX_free(i32* %32)
ret i32 0
}