#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
scalar_t__ SSL_RECEIVED_SHUTDOWN;
int SSL_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int SSL_get_fd(int /*<<< orphan*/ *);
scalar_t__ SSL_get_shutdown(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_shutdown(int /*<<< orphan*/ *);
int SSL_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ show_certificates(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
void process(SSL *ssl) {
  char buf[1024];
  int sd, bytes;
  strcpy(buf, "Hello World\n");
  if (SSL_connect(ssl) != 1) {
    ERR_print_errors_fp(stderr);
    goto out;
  }
  show_certificates(ssl);
  while (1) {
    bytes = SSL_write(ssl, buf, sizeof(buf));
    if (bytes > 0) {
      printf("received from client: \"%s\"\n", buf);
      SSL_write(ssl, buf, bytes);
    } else {
      ERR_print_errors_fp(stderr);
      break;
    }
    if (SSL_get_shutdown(ssl) == SSL_RECEIVED_SHUTDOWN) {
      SSL_shutdown(ssl);
      break;
    }
  }
out:
  sd = SSL_get_fd(ssl);
  SSL_free(ssl);
  close(sd);
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <SSL_connect@plt>
cmp    $0x1,%eax
je     11f7 <process+0x47>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
jmp    129a <process+0xea>
mov    -0x8(%rbp),%rdi
call   10b0 <show_certificates@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <SSL_write@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
jle    1256 <process+0xa6>
lea    -0x410(%rbp),%rsi
lea    0xdd7(%rip),%rdi
call   1080 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%edx
call   1040 <SSL_write@plt>
jmp    1269 <process+0xb9>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
jmp    1295 <process+0xe5>
mov    -0x8(%rbp),%rdi
call   1060 <SSL_get_shutdown@plt>
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%rax
jne    1290 <process+0xe0>
mov    -0x8(%rbp),%rdi
call   10a0 <SSL_shutdown@plt>
jmp    1295 <process+0xe5>
jmp    1200 <process+0x50>
jmp    129a <process+0xea>
mov    -0x8(%rbp),%rdi
call   1030 <SSL_get_fd@plt>
mov    %eax,-0x414(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <SSL_free@plt>
mov    -0x414(%rbp),%edi
call   1090 <close@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0xe37(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   10c0 <SSL_connect@plt>
cmp    $0x1,%eax
jne    1246 <process+0x96>
mov    %rbx,%rdi
call   10b0 <show_certificates@plt>
mov    %rsp,%r14
lea    0xe1d(%rip),%r15
mov    0x2de1(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <SSL_write@plt>
test   %eax,%eax
jle    1246 <process+0x96>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <SSL_write@plt>
mov    %rbx,%rdi
call   1060 <SSL_get_shutdown@plt>
cmp    (%r12),%rax
jne    1200 <process+0x50>
mov    %rbx,%rdi
call   10a0 <SSL_shutdown@plt>
jmp    1254 <process+0xa4>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
mov    %rbx,%rdi
call   1030 <SSL_get_fd@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <SSL_free@plt>
mov    %ebp,%edi
call   1090 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Hello World\0A\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"received from client: \22%s\22\0A\00"
@SSL_RECEIVED_SHUTDOWN = global i64 0
define void @process(i32* %0) {
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32*, i32** %2
%9 = call i32 @SSL_connect(i32* %8)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @ERR_print_errors_fp(i32 %12)
br label %43
14: ; preds = %1
%15 = load i32*, i32** %2
%16 = call i32 @show_certificates(i32* %15)
br label %17
17: ; preds = %14, %41
%18 = load i32*, i32** %2
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = call i32 @SSL_write(i32* %18, i8* %19, i32 1024)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %2
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @SSL_write(i32* %26, i8* %27, i32 %28)
br label %33
30: ; preds = %17
%31 = load i32, i32* @stderr
%32 = call i32 @ERR_print_errors_fp(i32 %31)
br label %42
33: ; preds = %23
%34 = load i32*, i32** %2
%35 = call i64 @SSL_get_shutdown(i32* %34)
%36 = load i64, i64* @SSL_RECEIVED_SHUTDOWN
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32*, i32** %2
%40 = call i32 @SSL_shutdown(i32* %39)
br label %42
41: ; preds = %33
br label %17
42: ; preds = %38, %30
br label %43
43: ; preds = %42, %11
%44 = load i32*, i32** %2
%45 = call i32 @SSL_get_fd(i32* %44)
store i32 %45, i32* %4
%46 = load i32*, i32** %2
%47 = call i32 @SSL_free(i32* %46)
%48 = load i32, i32* %4
%49 = call i32 @close(i32 %48)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Hello World\0A\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"received from client: \22%s\22\0A\00"
@SSL_RECEIVED_SHUTDOWN = global i64 0
define void @process(i32* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @SSL_connect(i32* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @ERR_print_errors_fp(i32 %8)
br label %26
10: ; preds = %1
%11 = call i32 @show_certificates(i32* %0)
br label %12
12: ; preds = %15, %10
%13 = call i32 @SSL_write(i32* %0, i8* %3, i32 1024)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%17 = call i32 @SSL_write(i32* %0, i8* %3, i32 %13)
%18 = call i64 @SSL_get_shutdown(i32* %0)
%19 = load i64, i64* @SSL_RECEIVED_SHUTDOWN
%20 = icmp eq i64 %18, %19
br i1 %20, label %24, label %12
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @ERR_print_errors_fp(i32 %22)
br label %26
24: ; preds = %15
%25 = call i32 @SSL_shutdown(i32* %0)
br label %26
26: ; preds = %21, %24, %7
%27 = call i32 @SSL_get_fd(i32* %0)
%28 = call i32 @SSL_free(i32* %0)
%29 = call i32 @close(i32 %27)
ret void
}