#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*/ fprintf(int /*<<< orphan*/, char *, unsigned int,
                           unsigned int, unsigned int);
unsigned int fwrite(void const *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void fwrite_err(const void *ptr, size_t size, size_t count, FILE *stream) {
  unsigned c = fwrite(ptr, size, count, stream);
  if (c != count) {
    fprintf(stderr, "count %u != %u %u\n", (unsigned)count, c, (unsigned)size);
    perror("toasim: write error");
  }
}


x86 assembly (clang, -O0):
<fwrite_err>:
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    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <fwrite@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%rax
je     119e <fwrite_err+0x6e>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %eax,%r8d
lea    0xe73(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_err>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
call   1050 <fwrite@plt>
mov    %eax,%ecx
cmp    %rbx,%rcx
jne    114e <fwrite_err+0x1e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e8b(%rip),%rcx
mov    (%rcx),%edi
lea    0xea2(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
mov    %r14d,%r8d
call   1030 <fprintf@plt>
lea    0xea2(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <perror@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"count %u != %u %u\0A\00"
@.str.1 = [20 x i8] c"toasim: write error\00"
define void @fwrite_err(i8* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = load i64, i64* %7
%13 = load i32*, i32** %8
%14 = call i32 @fwrite(i8* %10, i64 %11, i64 %12, i32* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = zext i32 %15 to i64
%17 = load i64, i64* %7
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = load i64, i64* %7
%22 = trunc i64 %21 to i32
%23 = load i32, i32* %9
%24 = load i64, i64* %6
%25 = trunc i64 %24 to i32
%26 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23, i32 %25)
%27 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %19, %4
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"count %u != %u %u\0A\00"
@.str.1 = [20 x i8] c"toasim: write error\00"
define void @fwrite_err(i8* nocapture %0, i64 %1, i64 %2, i32* nocapture %3) {
%5 = tail call i32 @fwrite(i8* %0, i64 %1, i64 %2, i32* %3)
%6 = zext i32 %5 to i64
%7 = icmp eq i64 %6, %2
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = trunc i64 %2 to i32
%11 = trunc i64 %1 to i32
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %5, i32 %11)
%13 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %8, %4
ret void
}