#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*/);
char *SSL_CIPHER_get_name(int /*<<< orphan*/);
scalar_t__ SSL_RECEIVED_SHUTDOWN;
int SSL_accept(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_get_current_cipher(int /*<<< orphan*/ *);
int SSL_get_fd(int /*<<< orphan*/ *);
scalar_t__ SSL_get_shutdown(int /*<<< orphan*/ *);
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_shutdown(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ show_certificates(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void process(SSL *ssl) {
  char buf[1024];
  int sd, bytes;
  if (SSL_accept(ssl) == -1) {
    ERR_print_errors_fp(stderr);
    goto out;
  }
  printf("cipher: %s\n", SSL_CIPHER_get_name(SSL_get_current_cipher(ssl)));
  show_certificates(ssl);
  while (1) {
    bytes = SSL_read(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)
mov    -0x8(%rbp),%rdi
call   10c0 <SSL_accept@plt>
cmp    $0xffffffff,%eax
jne    1204 <process+0x34>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
jmp    12c6 <process+0xf6>
mov    -0x8(%rbp),%rdi
call   10a0 <SSL_get_current_cipher@plt>
mov    %eax,%edi
call   10e0 <SSL_CIPHER_get_name@plt>
mov    %rax,%rsi
lea    0xde2(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10d0 <show_certificates@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1090 <SSL_read@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
jle    1282 <process+0xb2>
lea    -0x410(%rbp),%rsi
lea    0xdaa(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%edx
call   1040 <SSL_write@plt>
jmp    1295 <process+0xc5>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
jmp    12c1 <process+0xf1>
mov    -0x8(%rbp),%rdi
call   1050 <SSL_get_shutdown@plt>
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%rax
jne    12bc <process+0xec>
mov    -0x8(%rbp),%rdi
call   10b0 <SSL_shutdown@plt>
jmp    12c1 <process+0xf1>
jmp    122c <process+0x5c>
jmp    12c6 <process+0xf6>
mov    -0x8(%rbp),%rdi
call   1030 <SSL_get_fd@plt>
mov    %eax,-0x414(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <SSL_free@plt>
mov    -0x414(%rbp),%edi
call   1080 <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
call   10c0 <SSL_accept@plt>
cmp    $0xffffffff,%eax
je     1276 <process+0xa6>
mov    %rbx,%rdi
call   10a0 <SSL_get_current_cipher@plt>
mov    %eax,%edi
call   10e0 <SSL_CIPHER_get_name@plt>
lea    0xdfa(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10d0 <show_certificates@plt>
mov    %rsp,%r14
lea    0xdec(%rip),%r15
mov    0x2db1(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1090 <SSL_read@plt>
test   %eax,%eax
jle    1276 <process+0xa6>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <SSL_write@plt>
mov    %rbx,%rdi
call   1050 <SSL_get_shutdown@plt>
cmp    (%r12),%rax
jne    1230 <process+0x60>
mov    %rbx,%rdi
call   10b0 <SSL_shutdown@plt>
jmp    1284 <process+0xb4>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    %rbx,%rdi
call   1030 <SSL_get_fd@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <SSL_free@plt>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"cipher: %s\0A\00"
@.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 = tail call i32 @SSL_accept(i32* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @ERR_print_errors_fp(i32 %7)
br label %28
9: ; preds = %1
%10 = tail call i32 @SSL_get_current_cipher(i32* %0)
%11 = tail call i8* @SSL_CIPHER_get_name(i32 %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @show_certificates(i32* %0)
br label %14
14: ; preds = %17, %9
%15 = call i32 @SSL_read(i32* %0, i8* %3, i32 1024)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%19 = call i32 @SSL_write(i32* %0, i8* %3, i32 %15)
%20 = call i64 @SSL_get_shutdown(i32* %0)
%21 = load i64, i64* @SSL_RECEIVED_SHUTDOWN
%22 = icmp eq i64 %20, %21
br i1 %22, label %26, label %14
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = call i32 @ERR_print_errors_fp(i32 %24)
br label %28
26: ; preds = %17
%27 = call i32 @SSL_shutdown(i32* %0)
br label %28
28: ; preds = %23, %26, %6
%29 = call i32 @SSL_get_fd(i32* %0)
%30 = call i32 @SSL_free(i32* %0)
%31 = call i32 @close(i32 %29)
ret void
}