#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*/ die(char *, int /*<<< orphan*/);
scalar_t__ errno;
size_t fwrite(void const *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(scalar_t__);
size_t efwrite(const void *ptr, size_t size, size_t nitems, FILE *stream) {
  errno = 0;
  size_t nbytes = fwrite(ptr, size, nitems, stream);
  if (errno)
    die("fwrite error: %s", strerror(errno));
  return nbytes;
}


x86 assembly (clang, -O0):
<efwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e91(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e6a(%rip),%rax
cmpq   $0x0,(%rax)
je     119d <efwrite+0x6d>
mov    0x2e59(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
call   1030 <die@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<efwrite>:
push   %r14
push   %rbx
push   %rax
mov    0x2ea5(%rip),%r14
movq   $0x0,(%r14)
call   1040 <fwrite@plt>
mov    %rax,%rbx
mov    (%r14),%rdi
test   %rdi,%rdi
je     1165 <efwrite+0x35>
call   1050 <strerror@plt>
lea    0xea2(%rip),%rdi
mov    %eax,%esi
call   1030 <die@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@errno = global i64 0
@.str = [17 x i8] c"fwrite error: %s\00"
define i64 @efwrite(i8* nocapture %0, i64 %1, i64 %2, i32* nocapture %3) {
store i64 0, i64* @errno
%5 = tail call i64 @fwrite(i8* %0, i64 %1, i64 %2, i32* %3)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @strerror(i64 %6)
%10 = tail call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %4
ret i64 %5
}