#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 (fwrite(ptr, size, 1, stream) != 1) {
    msg(-3, "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)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
je     11a2 <xfwrite+0x62>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0xfffffffd,%edi
lea    0xe71(%rip),%rsi
call   1060 <msg@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfwrite>:
push   %rax
mov    %rdx,%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
jne    1155 <xfwrite+0x15>
pop    %rax
ret
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe96(%rip),%rsi
mov    $0xfffffffd,%edi
mov    %eax,%edx
call   1060 <msg@plt>
mov    0x2e5b(%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 i8*, i8** %4
%8 = load i64, i64* %5
%9 = load i32*, i32** %6
%10 = call i32 @fwrite(i8* %7, i64 %8, i32 1, i32* %9)
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @msg(i32 -3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %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 = tail call i32 @fwrite(i8* %0, i64 %1, i32 1, i32* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @msg(i32 -3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
ret void
}