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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int fwrite(char const *, size_t, int, int /*<<< orphan*/ *);
int msgpack_fbuffer_write(void *data, const char *buf, size_t len) {
  assert(buf || len == 0);
  if (!buf)
    return 0;
  return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1;
}


x86 assembly (clang, -O0):
<msgpack_fbuffer_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x1,%al
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
jne    114f <msgpack_fbuffer_write+0x2f>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <msgpack_fbuffer_write+0x53>
movl   $0x0,-0x4(%rbp)
jmp    119f <msgpack_fbuffer_write+0x7f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    %eax,%esi
mov    $0x1,%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msgpack_fbuffer_write>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
setne  %al
test   %rdx,%rdx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
test   %rbx,%rbx
je     116a <msgpack_fbuffer_write+0x4a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fwrite@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
neg    %eax
jmp    116c <msgpack_fbuffer_write+0x4c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @msgpack_fbuffer_write(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i64, i64* %7
%12 = icmp eq i64 %11, 0
br label %13
13: ; preds = %10, %3
%14 = phi i1 [ true, %3 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %13
store i32 0, i32* %4
br label %29
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = load i8*, i8** %5
%24 = bitcast i8* %23 to i32*
%25 = call i32 @fwrite(i8* %21, i64 %22, i32 1, i32* %24)
%26 = icmp eq i32 1, %25
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 0, i32 -1
store i32 %28, i32* %4
br label %29
29: ; preds = %20, %19
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @msgpack_fbuffer_write(i8* nocapture %0, i8* %1, i64 %2) {
%4 = icmp ne i8* %1, null
%5 = icmp eq i64 %2, 0
%6 = or i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
br i1 %4, label %9, label %14
9: ; preds = %3
%10 = bitcast i8* %0 to i32*
%11 = tail call i32 @fwrite(i8* %1, i64 %2, i32 1, i32* %10)
%12 = icmp ne i32 %11, 1
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %3, %9
%15 = phi i32 [ %13, %9 ], [ 0, %3 ]
ret i32 %15
}