#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*/);
int SSL_accept(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int SSL_get_fd(int /*<<< orphan*/ *);
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ShowCerts(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char const *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
void Servlet(SSL *ssl) {
  char buf[1024];
  char reply[1024];
  int sd, bytes, retcode;
  const char *serverMessage = "Server Says HI !!!!!!";
  if (SSL_accept(ssl) == -1) {
    printf("SSL_accept() failed\n");
    ERR_print_errors_fp(stderr);
  } else {
    ShowCerts(ssl);
    bytes = SSL_read(ssl, buf, sizeof(buf));
    if (bytes > 0) {
      buf[bytes] = 0;
      printf("Client msg: \"%s\"\n", buf);
      sprintf(reply, serverMessage, buf);
      SSL_write(ssl, reply, strlen(reply));
    } else {
      printf("SSL_read() failed\n");
      ERR_print_errors_fp(stderr);
    }
  }
  sd = SSL_get_fd(ssl);
  SSL_free(ssl);
  close(sd);
}


x86 assembly (clang, -O0):
<Servlet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe3a(%rip),%rax
mov    %rax,-0x828(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <SSL_accept@plt>
cmp    $0xffffffff,%eax
jne    1200 <Servlet+0x50>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
jmp    12cf <Servlet+0x11f>
mov    -0x8(%rbp),%rdi
call   1050 <ShowCerts@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <SSL_read@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x0,-0x818(%rbp)
jle    12ae <Servlet+0xfe>
movslq -0x818(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x810(%rbp),%rdi
mov    -0x828(%rbp),%rsi
lea    -0x410(%rbp),%rdx
call   10c0 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x810(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
mov    %eax,%edx
call   1040 <SSL_write@plt>
jmp    12ca <Servlet+0x11a>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   10d0 <ERR_print_errors_fp@plt>
jmp    12cf <Servlet+0x11f>
mov    -0x8(%rbp),%rdi
call   1030 <SSL_get_fd@plt>
mov    %eax,-0x814(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <SSL_free@plt>
mov    -0x814(%rbp),%edi
call   1090 <close@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Servlet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%rbx
call   10c0 <SSL_accept@plt>
cmp    $0xffffffff,%eax
je     1241 <Servlet+0x81>
mov    %rbx,%rdi
call   1060 <ShowCerts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   10b0 <SSL_read@plt>
test   %eax,%eax
jle    124a <Servlet+0x8a>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe13(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xde9(%rip),%rsi
lea    0x400(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   10d0 <sprintf@plt>
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <SSL_write@plt>
jmp    1264 <Servlet+0xa4>
lea    0xdf2(%rip),%rdi
jmp    1251 <Servlet+0x91>
lea    0xdd7(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10e0 <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   10a0 <close@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Server Says HI !!!!!!\00"
@.str.1 = [21 x i8] c"SSL_accept() failed\0A\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Client msg: \22%s\22\0A\00"
@.str.3 = [19 x i8] c"SSL_read() failed\0A\00"
define void @Servlet(i32* %0) {
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %2
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i32*, i32** %2
%10 = call i32 @SSL_accept(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 @ERR_print_errors_fp(i32 %14)
br label %44
16: ; preds = %1
%17 = load i32*, i32** %2
%18 = call i32 @ShowCerts(i32* %17)
%19 = load i32*, i32** %2
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = call i32 @SSL_read(i32* %19, i8* %20, i32 1024)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %16
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%31 = load i8*, i8** %8
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%33 = call i32 @sprintf(i8* %30, i8* %31, i8* %32)
%34 = load i32*, i32** %2
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @SSL_write(i32* %34, i8* %35, i32 %37)
br label %43
39: ; preds = %16
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 @ERR_print_errors_fp(i32 %41)
br label %43
43: ; preds = %39, %24
br label %44
44: ; preds = %43, %12
%45 = load i32*, i32** %2
%46 = call i32 @SSL_get_fd(i32* %45)
store i32 %46, i32* %5
%47 = load i32*, i32** %2
%48 = call i32 @SSL_free(i32* %47)
%49 = load i32, i32* %5
%50 = call i32 @close(i32 %49)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Server Says HI !!!!!!\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Client msg: \22%s\22\0A\00"
@str = [18 x i8] c"SSL_read() failed\00"
@str.4 = [20 x i8] c"SSL_accept() failed\00"
define void @Servlet(i32* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @SSL_accept(i32* %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @ERR_print_errors_fp(i32 %10)
br label %27
12: ; preds = %1
%13 = tail call i32 @ShowCerts(i32* %0)
%14 = call i32 @SSL_read(i32* %0, i8* %4, i32 1024)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = zext i32 %14 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%20 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %4)
%21 = call i32 @strlen(i8* %5)
%22 = call i32 @SSL_write(i32* %0, i8* %5, i32 %21)
br label %27
23: ; preds = %12
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 @ERR_print_errors_fp(i32 %25)
br label %27
27: ; preds = %16, %23, %8
%28 = call i32 @SSL_get_fd(i32* %0)
%29 = call i32 @SSL_free(i32* %0)
%30 = call i32 @close(i32 %28)
ret void
}