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

/* Variables and functions */
int /*<<< orphan*/ *BIO_next(int /*<<< orphan*/ *);
int BIO_write(int /*<<< orphan*/ *, char const *, int);
int dwrap_write(BIO *b, const char *in, int inl) {
  if (!b || !in || (inl <= 0)) {
    return 0;
  }
  BIO *next = BIO_next(b);
  int ret = BIO_write(next, in, inl);
  return ret;
}


x86 assembly (clang, -O0):
<dwrap_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1153 <dwrap_write+0x33>
cmpq   $0x0,-0x18(%rbp)
je     1153 <dwrap_write+0x33>
cmpl   $0x0,-0x1c(%rbp)
jg     115f <dwrap_write+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1185 <dwrap_write+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <BIO_next@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <BIO_write@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dwrap_write>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     114e <dwrap_write+0x2e>
mov    %rsi,%rbx
test   %rsi,%rsi
je     114e <dwrap_write+0x2e>
mov    %edx,%ebp
test   %edx,%edx
jle    114e <dwrap_write+0x2e>
call   1040 <BIO_next@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <BIO_write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dwrap_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
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %3
store i32 0, i32* %4
br label %27
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i32* @BIO_next(i32* %20)
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @BIO_write(i32* %22, i8* %23, i32 %24)
store i32 %25, i32* %9
%26 = load i32, i32* %9
store i32 %26, i32* %4
br label %27
27: ; preds = %19, %18
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @dwrap_write(i32* %0, i8* %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp slt i32 %2, 1
%8 = or i1 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = tail call i32* @BIO_next(i32* %0)
%11 = tail call i32 @BIO_write(i32* %10, i8* %1, i32 %2)
br label %12
12: ; preds = %3, %9
%13 = phi i32 [ %11, %9 ], [ 0, %3 ]
ret i32 %13
}