#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 */
char *ERR_error_string(long, int /*<<< orphan*/ *);
long ERR_get_error();
int SSL_ERROR_WANT_READ;
int SSL_ERROR_WANT_WRITE;
int SSL_get_error(int /*<<< orphan*/ *, int);
int SSL_write(int /*<<< orphan*/ *, char const *, int);
int ssl_write(SSL *conn, const char *req, int length) {
  int w = SSL_write(conn, req, length);
  if (w < 0) {
    int ssl_error = SSL_get_error(conn, w);
    if (ssl_error == SSL_ERROR_WANT_WRITE) {
      ;
      return w;
    }
    if (ssl_error == SSL_ERROR_WANT_READ) {
      ;
      return w;
    }
    long error = ERR_get_error();
    const char *error_string = ERR_error_string(error, NULL);
    ;
    return w;
  }
}


x86 assembly (clang, -O0):
<ssl_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <SSL_write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11db <ssl_write+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <SSL_get_error@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%eax
jne    119c <ssl_write+0x5c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <ssl_write+0x9b>
mov    -0x24(%rbp),%eax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%eax
jne    11b9 <ssl_write+0x79>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <ssl_write+0x9b>
mov    $0x0,%al
call   1060 <ERR_get_error@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <ERR_error_string@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_write>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <SSL_write@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1182 <ssl_write+0x42>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <SSL_get_error@plt>
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
je     1182 <ssl_write+0x42>
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
je     1182 <ssl_write+0x42>
xor    %eax,%eax
call   1060 <ERR_get_error@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <ERR_error_string@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SSL_ERROR_WANT_WRITE = global i32 0
@SSL_ERROR_WANT_READ = global i32 0
define i32 @ssl_write(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i32*, i32** %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i32 @SSL_write(i32* %12, i8* %13, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %3
%19 = load i32*, i32** %5
%20 = load i32, i32* %8
%21 = call i32 @SSL_get_error(i32* %19, i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = load i32, i32* @SSL_ERROR_WANT_WRITE
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %38
27: ; preds = %18
%28 = load i32, i32* %9
%29 = load i32, i32* @SSL_ERROR_WANT_READ
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %38
33: ; preds = %27
%34 = call i64 (...) @ERR_get_error()
store i64 %34, i64* %10
%35 = load i64, i64* %10
%36 = call i8* @ERR_error_string(i64 %35, i32* null)
store i8* %36, i8** %11
%37 = load i32, i32* %8
store i32 %37, i32* %4
br label %38
38: ; preds = %25, %31, %33, %3
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@SSL_ERROR_WANT_WRITE = global i32 0
@SSL_ERROR_WANT_READ = global i32 0
define i32 @ssl_write(i32* %0, i8* %1, i32 %2) {
%4 = tail call i32 @SSL_write(i32* %0, i8* %1, i32 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = tail call i32 @SSL_get_error(i32* %0, i32 %4)
%8 = load i32, i32* @SSL_ERROR_WANT_WRITE
%9 = icmp eq i32 %7, %8
%10 = load i32, i32* @SSL_ERROR_WANT_READ
%11 = icmp eq i32 %7, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %16, label %13
13: ; preds = %6
%14 = tail call i64 (...) @ERR_get_error()
%15 = tail call i8* @ERR_error_string(i64 %14, i32* null)
br label %16
16: ; preds = %3, %13, %6
ret i32 %4
}