#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 */
scalar_t__ SSL_ERROR_WANT_WRITE;
scalar_t__ SSL_get_error(int /*<<< orphan*/ *, int);
int SSL_write(int /*<<< orphan*/ *, unsigned char *, int);
int ssl_write(void *sl, unsigned char *buf, int len) {
  SSL *ssl = (SSL *)sl;
  int n = -1;
  n = SSL_write(ssl, buf, len);
  if (n < 0) {
    if (SSL_get_error(ssl, n) == SSL_ERROR_WANT_WRITE) {
      n = -11;
    } else {
      n = -1;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<ssl_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <SSL_write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1193 <ssl_write+0x73>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <SSL_get_error@plt>
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jne    1187 <ssl_write+0x67>
movl   $0xfffffff5,-0x24(%rbp)
jmp    118e <ssl_write+0x6e>
movl   $0xffffffff,-0x24(%rbp)
jmp    1193 <ssl_write+0x73>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_write>:
push   %rbx
mov    %rdi,%rbx
call   1040 <SSL_write@plt>
test   %eax,%eax
js     112f <ssl_write+0xf>
pop    %rbx
ret
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <SSL_get_error@plt>
mov    0x2eb0(%rip),%rcx
cmp    (%rcx),%rax
mov    $0xfffffff5,%ecx
mov    $0xffffffff,%eax
cmove  %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@SSL_ERROR_WANT_WRITE = global i64 0
define i32 @ssl_write(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
store i32 -1, i32* %8
%11 = load i32*, i32** %7
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @SSL_write(i32* %11, i8* %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i32, i32* %8
%20 = call i64 @SSL_get_error(i32* %18, i32 %19)
%21 = load i64, i64* @SSL_ERROR_WANT_WRITE
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -11, i32* %8
br label %25
24: ; preds = %17
store i32 -1, i32* %8
br label %25
25: ; preds = %24, %23
br label %26
26: ; preds = %25, %3
%27 = load i32, i32* %8
ret i32 %27
}

LLVM IR (-O2):
@SSL_ERROR_WANT_WRITE = global i64 0
define i32 @ssl_write(i8* %0, i8* %1, i32 %2) {
%4 = bitcast i8* %0 to i32*
%5 = tail call i32 @SSL_write(i32* %4, i8* %1, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = tail call i64 @SSL_get_error(i32* %4, i32 %5)
%9 = load i64, i64* @SSL_ERROR_WANT_WRITE
%10 = icmp eq i64 %8, %9
%11 = select i1 %10, i32 -11, i32 -1
br label %12
12: ; preds = %7, %3
%13 = phi i32 [ %5, %3 ], [ %11, %7 ]
ret i32 %13
}