#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*/ msg;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int SSL_ERROR_ZERO_RETURN;
scalar_t__ SSL_RECEIVED_SHUTDOWN;
int /*<<< orphan*/ SSL_errmsg(int /*<<< orphan*/ *, int);
int SSL_get_error(int /*<<< orphan*/ *, int);
scalar_t__ SSL_get_shutdown(int /*<<< orphan*/ *);
int SSL_read(int /*<<< orphan*/ *, char *, int);
scalar_t__ SSL_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errmesg(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ logMsg(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ sprintf(char *, char *, int, unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int doServerSSL(SSL *ssl) {
  char msg[128];
  int bytes_read = 0;
  memset(msg, '\0', 128);
  putchar('3');
  putchar('\n');
  if ((bytes_read = SSL_read(ssl, msg, sizeof(msg) - 1)) <= 0) {
    int err = SSL_get_error(ssl, bytes_read);
    if (bytes_read == 0) {
      if (SSL_get_shutdown(ssl) == SSL_RECEIVED_SHUTDOWN) {
        return 0;
      }
      if (err == SSL_ERROR_ZERO_RETURN) {
        return 0;
      }
    }
    if (bytes_read < 0) {
      SSL_errmsg(ssl, err);
    }
    fprintf(stderr, "Bytes_read: %d, SSL_get_error: %d\n", bytes_read, err);
    errmesg("SSL_read error");
  }
  putchar('4');
  putchar('\n');
  if (bytes_read == 1 && msg[0] == '\n') {
    return 0;
  }
  msg[bytes_read] = 0;
  putchar('5');
  putchar('\n');
  logMsg(msg);
  putchar('7');
  putchar('\n');
  memset(msg, '\0', 128);
  sprintf(msg, "Msg of %uB recv'd and logged, secret: 0x%08x\n", bytes_read,
          (unsigned int)msg);
  if (SSL_write(ssl, msg, strlen(msg)) < 0) {
    return -1;
  }
  return bytes_read;
}


x86 assembly (clang, -O0):
<doServerSSL>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    $0x33,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x7f,%edx
call   1090 <SSL_read@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jg     12da <doServerSSL+0x11a>
mov    -0x10(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1030 <SSL_get_error@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x94(%rbp)
jne    1291 <doServerSSL+0xd1>
mov    -0x10(%rbp),%rdi
call   1060 <SSL_get_shutdown@plt>
mov    0x2d7a(%rip),%rcx
cmp    (%rcx),%rax
jne    126b <doServerSSL+0xab>
movl   $0x0,-0x4(%rbp)
jmp    13e8 <doServerSSL+0x228>
mov    -0x98(%rbp),%eax
mov    0x2d78(%rip),%rcx
cmp    (%rcx),%eax
jne    128c <doServerSSL+0xcc>
movl   $0x0,-0x4(%rbp)
jmp    13e8 <doServerSSL+0x228>
jmp    1291 <doServerSSL+0xd1>
cmpl   $0x0,-0x94(%rbp)
jge    12ad <doServerSSL+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x98(%rbp),%esi
call   10d0 <SSL_errmsg@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    -0x94(%rbp),%edx
mov    -0x98(%rbp),%ecx
lea    0xd37(%rip),%rsi
call   10c0 <fprintf@plt>
lea    0xd4e(%rip),%rdi
call   10a0 <errmesg@plt>
mov    $0x34,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x1,-0x94(%rbp)
jne    1317 <doServerSSL+0x157>
movsbl -0x90(%rbp),%eax
cmp    $0xa,%eax
jne    1317 <doServerSSL+0x157>
movl   $0x0,-0x4(%rbp)
jmp    13e8 <doServerSSL+0x228>
movslq -0x94(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    $0x35,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    -0x90(%rbp),%rdi
call   10b0 <logMsg@plt>
mov    $0x37,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%edx
lea    -0x90(%rbp),%rax
mov    %eax,%ecx
lea    0xca8(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
call   1050 <SSL_write@plt>
cmp    $0x0,%rax
jge    13df <doServerSSL+0x21f>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e8 <doServerSSL+0x228>
mov    -0x94(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doServerSSL>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
mov    %rsp,%rbp
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    $0x33,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x7f,%edx
call   1090 <SSL_read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1277 <doServerSSL+0xb7>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <SSL_get_error@plt>
mov    %eax,%r15d
mov    %r14,%rdi
test   %ebp,%ebp
je     122c <doServerSSL+0x6c>
mov    %r15d,%esi
call   10d0 <SSL_errmsg@plt>
jmp    1251 <doServerSSL+0x91>
call   1060 <SSL_get_shutdown@plt>
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
je     1312 <doServerSSL+0x152>
mov    0x2da8(%rip),%rax
cmp    (%rax),%r15d
je     1312 <doServerSSL+0x152>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
call   10c0 <fprintf@plt>
lea    0xdb1(%rip),%rdi
call   10a0 <errmesg@plt>
mov    $0x34,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    $0x1,%ebp
jne    1296 <doServerSSL+0xd6>
cmpb   $0xa,(%rsp)
je     1312 <doServerSSL+0x152>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    $0x35,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10b0 <logMsg@plt>
mov    $0x37,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
lea    0xd4c(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %ebx,%ecx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <SSL_write@plt>
test   %rax,%rax
mov    $0xffffffff,%ebx
cmovns %ebp,%ebx
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SSL_RECEIVED_SHUTDOWN = global i64 0
@SSL_ERROR_ZERO_RETURN = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"Bytes_read: %d, SSL_get_error: %d\0A\00"
@.str.1 = [15 x i8] c"SSL_read error\00"
@.str.2 = [46 x i8] c"Msg of %uB recv'd and logged, secret: 0x%08x\0A\00"
define i32 @doServerSSL(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 128)
%9 = call i32 @putchar(i8 signext 51)
%10 = call i32 @putchar(i8 signext 10)
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = call i32 @SSL_read(i32* %11, i8* %12, i32 127)
store i32 %13, i32* %5
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %46
15: ; preds = %1
%16 = load i32*, i32** %3
%17 = load i32, i32* %5
%18 = call i32 @SSL_get_error(i32* %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %15
%22 = load i32*, i32** %3
%23 = call i64 @SSL_get_shutdown(i32* %22)
%24 = load i64, i64* @SSL_RECEIVED_SHUTDOWN
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 0, i32* %2
br label %83
27: ; preds = %21
%28 = load i32, i32* %6
%29 = load i32, i32* @SSL_ERROR_ZERO_RETURN
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 0, i32* %2
br label %83
32: ; preds = %27
br label %33
33: ; preds = %32, %15
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32*, i32** %3
%38 = load i32, i32* %6
%39 = call i32 @SSL_errmsg(i32* %37, i32 %38)
br label %40
40: ; preds = %36, %33
%41 = load i32, i32* @stderr
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %42, i32 %43)
%45 = call i32 @errmesg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %40, %1
%47 = call i32 @putchar(i8 signext 52)
%48 = call i32 @putchar(i8 signext 10)
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %57
51: ; preds = %46
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 0, i32* %2
br label %83
57: ; preds = %51, %46
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %59
store i8 0, i8* %60
%61 = call i32 @putchar(i8 signext 53)
%62 = call i32 @putchar(i8 signext 10)
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%64 = call i32 @logMsg(i8* %63)
%65 = call i32 @putchar(i8 signext 55)
%66 = call i32 @putchar(i8 signext 10)
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%68 = call i32 @memset(i8* %67, i8 signext 0, i32 128)
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%70 = load i32, i32* %5
%71 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%72 = ptrtoint i8* %71 to i32
%73 = call i32 @sprintf(i8* %69, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %70, i32 %72)
%74 = load i32*, i32** %3
%75 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
%78 = call i64 @SSL_write(i32* %74, i8* %75, i32 %77)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %57
store i32 -1, i32* %2
br label %83
81: ; preds = %57
%82 = load i32, i32* %5
store i32 %82, i32* %2
br label %83
83: ; preds = %81, %80, %56, %31, %26
%84 = load i32, i32* %2
ret i32 %84
}

LLVM IR (-O2):
@SSL_RECEIVED_SHUTDOWN = global i64 0
@SSL_ERROR_ZERO_RETURN = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"Bytes_read: %d, SSL_get_error: %d\0A\00"
@.str.1 = [15 x i8] c"SSL_read error\00"
@.str.2 = [46 x i8] c"Msg of %uB recv'd and logged, secret: 0x%08x\0A\00"
define i32 @doServerSSL(i32* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 128)
%5 = call i32 @putchar(i8 signext 51)
%6 = call i32 @putchar(i8 signext 10)
%7 = call i32 @SSL_read(i32* %0, i8* %3, i32 127)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %25
9: ; preds = %1
%10 = call i32 @SSL_get_error(i32* %0, i32 %7)
%11 = icmp eq i32 %7, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = call i64 @SSL_get_shutdown(i32* %0)
%14 = load i64, i64* @SSL_RECEIVED_SHUTDOWN
%15 = icmp eq i64 %13, %14
%16 = load i32, i32* @SSL_ERROR_ZERO_RETURN
%17 = icmp eq i32 %10, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %48, label %21
19: ; preds = %9
%20 = call i32 @SSL_errmsg(i32* %0, i32 %10)
br label %21
21: ; preds = %12, %19
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
%24 = call i32 @errmesg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %21, %1
%26 = call i32 @putchar(i8 signext 52)
%27 = call i32 @putchar(i8 signext 10)
%28 = icmp eq i32 %7, 1
%29 = load i8, i8* %3
%30 = icmp eq i8 %29, 10
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %48, label %32
32: ; preds = %25
%33 = sext i32 %7 to i64
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 @putchar(i8 signext 53)
%36 = call i32 @putchar(i8 signext 10)
%37 = call i32 @logMsg(i8* %3)
%38 = call i32 @putchar(i8 signext 55)
%39 = call i32 @putchar(i8 signext 10)
%40 = call i32 @memset(i8* %3, i8 signext 0, i32 128)
%41 = ptrtoint [128 x i8]* %2 to i64
%42 = trunc i64 %41 to i32
%43 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %42)
%44 = call i32 @strlen(i8* %3)
%45 = call i64 @SSL_write(i32* %0, i8* %3, i32 %44)
%46 = icmp slt i64 %45, 0
%47 = select i1 %46, i32 -1, i32 %7
br label %48
48: ; preds = %32, %25, %12
%49 = phi i32 [ 0, %12 ], [ 0, %25 ], [ %47, %32 ]
ret i32 %49
}