#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 */
#define SSL_ERROR_SSL 132
#define SSL_ERROR_SYSCALL 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*/ g_writeln(char *, ...);
int ssl_tls_print_error(char *func, SSL *connection, int value) {
  switch (SSL_get_error(connection, value)) {
  case SSL_ERROR_ZERO_RETURN:
    g_writeln("ssl_tls_print_error: %s: Server closed TLS connection", func);
    return 1;
  case SSL_ERROR_WANT_READ:
    g_writeln("ssl_tls_print_error: SSL_ERROR_WANT_READ");
    return 0;
  case SSL_ERROR_WANT_WRITE:
    g_writeln("ssl_tls_print_error: SSL_ERROR_WANT_WRITE");
    return 0;
  case SSL_ERROR_SYSCALL:
    g_writeln("ssl_tls_print_error: %s: I/O error", func);
    return 1;
  case SSL_ERROR_SSL:
    g_writeln(
        "ssl_tls_print_error: %s: Failure in SSL library (protocol error?)",
        func);
    return 1;
  default:
    g_writeln("ssl_tls_print_error: %s: Unknown error", func);
    return 1;
  }
}


x86 assembly (clang, -O0):
<ssl_tls_print_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <SSL_get_error@plt>
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     11f3 <ssl_tls_print_error+0xd3>
mov    -0x28(%rbp),%rax
lea    0xea4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    120c <ssl_tls_print_error+0xec>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x0,-0x4(%rbp)
jmp    120c <ssl_tls_print_error+0xec>
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x0,-0x4(%rbp)
jmp    120c <ssl_tls_print_error+0xec>
mov    -0x10(%rbp),%rsi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    120c <ssl_tls_print_error+0xec>
mov    -0x10(%rbp),%rsi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    120c <ssl_tls_print_error+0xec>
mov    -0x10(%rbp),%rsi
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_tls_print_error>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %edx,%esi
call   1030 <SSL_get_error@plt>
add    $0xffffff80,%eax
cmp    $0x4,%eax
ja     114f <ssl_tls_print_error+0x2f>
lea    0xec3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec7(%rip),%rdi
jmp    1183 <ssl_tls_print_error+0x63>
lea    0xfac(%rip),%rdi
jmp    1183 <ssl_tls_print_error+0x63>
lea    0xf14(%rip),%rdi
jmp    1168 <ssl_tls_print_error+0x48>
lea    0xee2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <g_writeln@plt>
jmp    1192 <ssl_tls_print_error+0x72>
lea    0xf23(%rip),%rdi
jmp    1183 <ssl_tls_print_error+0x63>
lea    0xf3d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <g_writeln@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [54 x i8] c"ssl_tls_print_error: %s: Server closed TLS connection\00"
@.str.1 = [41 x i8] c"ssl_tls_print_error: SSL_ERROR_WANT_READ\00"
@.str.2 = [42 x i8] c"ssl_tls_print_error: SSL_ERROR_WANT_WRITE\00"
@.str.3 = [35 x i8] c"ssl_tls_print_error: %s: I/O error\00"
@.str.4 = [66 x i8] c"ssl_tls_print_error: %s: Failure in SSL library (protocol error?)\00"
@.str.5 = [39 x i8] c"ssl_tls_print_error: %s: Unknown error\00"
define i32 @ssl_tls_print_error(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%8 = load i32*, i32** %6
%9 = load i32, i32* %7
%10 = call i32 @SSL_get_error(i32* %8, i32 %9)
switch i32 %10, label %24 [
i32 128, label %11
i32 130, label %14
i32 129, label %16
i32 131, label %18
i32 132, label %21
]
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %4
br label %27
14: ; preds = %3
%15 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %27
16: ; preds = %3
%17 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %27
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %19)
store i32 1, i32* %4
br label %27
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* %22)
store i32 1, i32* %4
br label %27
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %25)
store i32 1, i32* %4
br label %27
27: ; preds = %24, %21, %18, %16, %14, %11
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [54 x i8] c"ssl_tls_print_error: %s: Server closed TLS connection\00"
@.str.1 = [41 x i8] c"ssl_tls_print_error: SSL_ERROR_WANT_READ\00"
@.str.2 = [42 x i8] c"ssl_tls_print_error: SSL_ERROR_WANT_WRITE\00"
@.str.3 = [35 x i8] c"ssl_tls_print_error: %s: I/O error\00"
@.str.4 = [66 x i8] c"ssl_tls_print_error: %s: Failure in SSL library (protocol error?)\00"
@.str.5 = [39 x i8] c"ssl_tls_print_error: %s: Unknown error\00"
define i32 @ssl_tls_print_error(i8* %0, i32* %1, i32 %2) {
%4 = tail call i32 @SSL_get_error(i32* %1, i32 %2)
switch i32 %4, label %15 [
i32 128, label %5
i32 130, label %7
i32 129, label %9
i32 131, label %11
i32 132, label %13
]
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %17
9: ; preds = %3
%10 = tail call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %17
11: ; preds = %3
%12 = tail call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %17
13: ; preds = %3
%14 = tail call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %17
15: ; preds = %3
%16 = tail call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %15, %13, %11, %9, %7, %5
%18 = phi i32 [ 1, %15 ], [ 1, %13 ], [ 1, %11 ], [ 0, %9 ], [ 0, %7 ], [ 1, %5 ]
ret i32 %18
}