#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_accept(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(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;
  }
  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   10b0 <SSL_accept@plt>
cmp    $0xffffffff,%eax
jne    11e4 <process+0x34>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
jmp    1287 <process+0xd7>
mov    -0x8(%rbp),%rdi
call   10c0 <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    1243 <process+0x93>
lea    -0x410(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%edx
call   1040 <SSL_write@plt>
jmp    1256 <process+0xa6>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
jmp    1282 <process+0xd2>
mov    -0x8(%rbp),%rdi
call   1050 <SSL_get_shutdown@plt>
mov    0x2d72(%rip),%rcx
cmp    (%rcx),%rax
jne    127d <process+0xcd>
mov    -0x8(%rbp),%rdi
call   10a0 <SSL_shutdown@plt>
jmp    1282 <process+0xd2>
jmp    11ed <process+0x3d>
jmp    1287 <process+0xd7>
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   10b0 <SSL_accept@plt>
cmp    $0xffffffff,%eax
je     1236 <process+0x86>
mov    %rbx,%rdi
call   10c0 <show_certificates@plt>
mov    %rsp,%r14
lea    0xe22(%rip),%r15
mov    0x2df3(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1090 <SSL_read@plt>
test   %eax,%eax
jle    1236 <process+0x86>
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    11f0 <process+0x40>
mov    %rbx,%rdi
call   10a0 <SSL_shutdown@plt>
jmp    1244 <process+0x94>
mov    0x2da3(%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   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 = [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 %41
12: ; preds = %1
%13 = load i32*, i32** %2
%14 = call i32 @show_certificates(i32* %13)
br label %15
15: ; preds = %12, %39
%16 = load i32*, i32** %2
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = call i32 @SSL_read(i32* %16, i8* %17, i32 1024)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %2
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%26 = load i32, i32* %5
%27 = call i32 @SSL_write(i32* %24, i8* %25, i32 %26)
br label %31
28: ; preds = %15
%29 = load i32, i32* @stderr
%30 = call i32 @ERR_print_errors_fp(i32 %29)
br label %40
31: ; preds = %21
%32 = load i32*, i32** %2
%33 = call i64 @SSL_get_shutdown(i32* %32)
%34 = load i64, i64* @SSL_RECEIVED_SHUTDOWN
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32*, i32** %2
%38 = call i32 @SSL_shutdown(i32* %37)
br label %40
39: ; preds = %31
br label %15
40: ; preds = %36, %28
br label %41
41: ; preds = %40, %9
%42 = load i32*, i32** %2
%43 = call i32 @SSL_get_fd(i32* %42)
store i32 %43, i32* %4
%44 = load i32*, i32** %2
%45 = call i32 @SSL_free(i32* %44)
%46 = load i32, i32* %4
%47 = call i32 @close(i32 %46)
ret void
}

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