#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 */
struct szl_interp {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ ERR_error_string(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_get_error();
scalar_t__ SSL_write(int /*<<< orphan*/ *, unsigned char const *, int);
int /*<<< orphan*/ szl_set_last_str(struct szl_interp *, int /*<<< orphan*/,
                                    int);
ssize_t szl_tls_write(struct szl_interp *interp, void *priv,
                      const unsigned char *buf, const size_t len) {
  ssize_t out;
  out = (ssize_t)SSL_write((SSL *)priv, buf, (int)len);
  if (out < 0) {
    szl_set_last_str(interp, ERR_error_string(ERR_get_error(), NULL), -1);
    return -1;
  }
  return out;
}


x86 assembly (clang, -O0):
<szl_tls_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1030 <SSL_write@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    11b1 <szl_tls_write+0x71>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <ERR_get_error@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <ERR_error_string@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    $0xffffffff,%edx
call   1050 <szl_set_last_str@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b9 <szl_tls_write+0x79>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<szl_tls_write>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <SSL_write@plt>
test   %rax,%rax
js     1158 <szl_tls_write+0x18>
pop    %rbx
ret
xor    %eax,%eax
call   1060 <ERR_get_error@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1040 <ERR_error_string@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0xffffffff,%edx
call   1050 <szl_set_last_str@plt>
mov    $0xffffffffffffffff,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.szl_interp = type { i32 }
define i64 @szl_tls_write(%struct.szl_interp* %0, i8* %1, i8* %2, i64 %3) {
%5 = bitcast i8* %1 to i32*
%6 = trunc i64 %3 to i32
%7 = tail call i64 @SSL_write(i32* %5, i8* %2, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = tail call i32 (...) @ERR_get_error()
%11 = tail call i32 @ERR_error_string(i32 %10, i32* null)
%12 = tail call i32 @szl_set_last_str(%struct.szl_interp* %0, i32 %11, i32 -1)
br label %13
13: ; preds = %4, %9
%14 = phi i64 [ -1, %9 ], [ %7, %4 ]
ret i64 %14
}