#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fwrite(void const *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ msg(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void xfwrite(const void *ptr, size_t size, FILE *stream) {
  if (size && fwrite(ptr, size, 1, stream) != 1) {
    msg(-4, "Failed to write to file: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<xfwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ad <xfwrite+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
je     11ad <xfwrite+0x6d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0xfffffffc,%edi
lea    0xe66(%rip),%rsi
call   1060 <msg@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfwrite>:
push   %rax
test   %rsi,%rsi
je     1158 <xfwrite+0x18>
mov    %rdx,%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
jne    115a <xfwrite+0x1a>
pop    %rax
ret
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe91(%rip),%rsi
mov    $0xfffffffc,%edi
mov    %eax,%edx
call   1060 <msg@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Failed to write to file: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @xfwrite(i8* %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%7 = load i64, i64* %5
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i64, i64* %5
%12 = load i32*, i32** %6
%13 = call i32 @fwrite(i8* %10, i64 %11, i32 1, i32* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @msg(i32 -4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %9, %3
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Failed to write to file: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @xfwrite(i8* nocapture %0, i64 %1, i32* nocapture %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = tail call i32 @fwrite(i8* %0, i64 %1, i32 1, i32* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 @msg(i32 -4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %5, %3
ret void
}