#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*/ SSL;

/* Variables and functions */
int ERR_error_string(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_get_error();
int /*<<< orphan*/ LOG_ERR;
#define SSL_ERROR_NONE 135
#define SSL_ERROR_SSL 134
#define SSL_ERROR_SYSCALL 133
#define SSL_ERROR_WANT_ACCEPT 132
#define SSL_ERROR_WANT_CONNECT 131
#define SSL_ERROR_WANT_READ 130
#define SSL_ERROR_WANT_WRITE 129
#define SSL_ERROR_ZERO_RETURN 128
int SSL_get_error(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ plog(int /*<<< orphan*/, char *, int, char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void plog_ssl_error(SSL *ssl_conn, int ret, char *cls, int sock) {
  int err = SSL_get_error(ssl_conn, ret);
  switch (err) {
  case SSL_ERROR_NONE:
  case SSL_ERROR_WANT_READ:
  case SSL_ERROR_WANT_WRITE:
  case SSL_ERROR_WANT_CONNECT:
  case SSL_ERROR_WANT_ACCEPT:
    break;
  case SSL_ERROR_SSL:
    plog(LOG_ERR, "ERROR @%d %s: %s", sock, cls,
         ERR_error_string(ERR_get_error(), NULL));
    break;
  case SSL_ERROR_SYSCALL:
    if (!ret) {
      plog(LOG_ERR, "ERROR @%d %s: Unexpected EOF", sock, cls);
    } else {
      plog(LOG_ERR, "ERROR @%d %s: %s (errno=%d)", sock, cls, strerror(errno),
           errno);
    }
    break;
  case SSL_ERROR_ZERO_RETURN:
    break;
  default:
    plog(LOG_ERR, "ERROR @%d %s: Unknown SSL error (SSL_get_error()=%d)", sock,
         cls, err);
    break;
  }
}


x86 assembly (clang, -O0):
<plog_ssl_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <SSL_get_error@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x7,%eax
ja     1273 <plog_ssl_error+0x123>
mov    -0x28(%rbp),%rax
lea    0xe6b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1295 <plog_ssl_error+0x145>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <ERR_get_error@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <ERR_error_string@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1040 <plog@plt>
jmp    1295 <plog_ssl_error+0x145>
cmpl   $0x0,-0xc(%rbp)
jne    121c <plog_ssl_error+0xcc>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1040 <plog@plt>
jmp    1269 <plog_ssl_error+0x119>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
mov    0x2d88(%rip),%rax
mov    (%rax),%r9d
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1040 <plog@plt>
jmp    1295 <plog_ssl_error+0x145>
jmp    1295 <plog_ssl_error+0x145>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8d
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1040 <plog@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plog_ssl_error>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %esi,%ebx
call   1030 <SSL_get_error@plt>
lea    -0x80(%rax),%ecx
cmp    $0x7,%ecx
ja     1186 <plog_ssl_error+0x36>
lea    0xe8e(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e43(%rip),%rcx
mov    (%rcx),%edi
lea    0xed4(%rip),%rsi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %eax,%r8d
jmp    120c <plog_ssl_error+0xbc>
mov    0x2e29(%rip),%rax
mov    (%rax),%r15d
test   %ebx,%ebx
je     121d <plog_ssl_error+0xcd>
mov    0x2e2b(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%r9d
lea    0xe88(%rip),%rsi
mov    %r15d,%edi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <plog@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1060 <ERR_get_error@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1050 <ERR_error_string@plt>
lea    0xe1e(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <plog@plt>
lea    0xe0d(%rip),%rsi
mov    %r15d,%edi
mov    %ebp,%edx
mov    %r14,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <plog@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [17 x i8] c"ERROR @%d %s: %s\00"
@.str.1 = [29 x i8] c"ERROR @%d %s: Unexpected EOF\00"
@.str.2 = [28 x i8] c"ERROR @%d %s: %s (errno=%d)\00"
@errno = global i32 0
@.str.3 = [53 x i8] c"ERROR @%d %s: Unknown SSL error (SSL_get_error()=%d)\00"
define void @plog_ssl_error(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = load i32, i32* %6
%12 = call i32 @SSL_get_error(i32* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
switch i32 %13, label %40 [
i32 135, label %14
i32 130, label %14
i32 129, label %14
i32 131, label %14
i32 132, label %14
i32 134, label %15
i32 133, label %22
i32 128, label %39
]
14: ; preds = %4, %4, %4, %4, %4
br label %46
15: ; preds = %4
%16 = load i32, i32* @LOG_ERR
%17 = load i32, i32* %8
%18 = load i8*, i8** %7
%19 = call i32 (...) @ERR_get_error()
%20 = call i32 @ERR_error_string(i32 %19, i32* null)
%21 = call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %18, i32 %20)
br label %46
22: ; preds = %4
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = load i32, i32* @LOG_ERR
%27 = load i32, i32* %8
%28 = load i8*, i8** %7
%29 = call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %28)
br label %38
30: ; preds = %22
%31 = load i32, i32* @LOG_ERR
%32 = load i32, i32* %8
%33 = load i8*, i8** %7
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = load i32, i32* @errno
%37 = call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %33, i32 %35, i32 %36)
br label %38
38: ; preds = %30, %25
br label %46
39: ; preds = %4
br label %46
40: ; preds = %4
%41 = load i32, i32* @LOG_ERR
%42 = load i32, i32* %8
%43 = load i8*, i8** %7
%44 = load i32, i32* %9
%45 = call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %41, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %42, i8* %43, i32 %44)
br label %46
46: ; preds = %40, %39, %38, %15, %14
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [17 x i8] c"ERROR @%d %s: %s\00"
@.str.1 = [29 x i8] c"ERROR @%d %s: Unexpected EOF\00"
@.str.2 = [28 x i8] c"ERROR @%d %s: %s (errno=%d)\00"
@errno = global i32 0
@.str.3 = [53 x i8] c"ERROR @%d %s: Unknown SSL error (SSL_get_error()=%d)\00"
define void @plog_ssl_error(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @SSL_get_error(i32* %0, i32 %1)
switch i32 %5, label %21 [
i32 135, label %24
i32 130, label %24
i32 129, label %24
i32 131, label %24
i32 132, label %24
i32 134, label %6
i32 133, label %11
i32 128, label %24
]
6: ; preds = %4
%7 = load i32, i32* @LOG_ERR
%8 = tail call i32 (...) @ERR_get_error()
%9 = tail call i32 @ERR_error_string(i32 %8, i32* null)
%10 = tail call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2, i32 %9)
br label %24
11: ; preds = %4
%12 = icmp eq i32 %1, 0
%13 = load i32, i32* @LOG_ERR
br i1 %12, label %14, label %16
14: ; preds = %11
%15 = tail call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %3, i8* %2)
br label %24
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = tail call i32 @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = tail call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %3, i8* %2, i32 %18, i32 %19)
br label %24
21: ; preds = %4
%22 = load i32, i32* @LOG_ERR
%23 = tail call i32 (i32, i8*, i32, i8*, ...) @plog(i32 %22, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %3, i8* %2, i32 %5)
br label %24
24: ; preds = %14, %16, %4, %4, %4, %4, %4, %21, %4, %6
ret void
}