#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
size_t fwrite(void const *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream,
                    const char *fname) {
  size_t w = fwrite(ptr, size, nitems, stream);
  if (w != nitems) {
    fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname,
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  return w;
}


x86 assembly (clang, -O0):
<fwrite_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11c9 <fwrite_check+0x89>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4a(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_check>:
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rdx,%rbx
call   1050 <fwrite@plt>
cmp    %rbx,%rax
jne    115f <fwrite_check+0x1f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e7a(%rip),%rax
mov    (%rax),%ebx
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe83(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"%s: Write to temporary file failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @fwrite_check(i8* %0, i64 %1, i64 %2, i32* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i8* %4, i8** %10
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = load i64, i64* %8
%15 = load i32*, i32** %9
%16 = call i64 @fwrite(i8* %12, i64 %13, i64 %14, i32* %15)
store i64 %16, i64* %11
%17 = load i64, i64* %11
%18 = load i64, i64* %8
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %5
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %10
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %5
%29 = load i64, i64* %11
ret i64 %29
}

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