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


x86 assembly (clang, -O0):
<fwrite_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     119a <fwrite_err+0x6a>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    0xe77(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    -0x4(%rbp),%eax
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>
movslq %eax,%rcx
cmp    %rbx,%rcx
jne    114f <fwrite_err+0x1f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%edi
lea    0xea1(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14,%r8
call   1030 <fprintf@plt>
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
jmp    1147 <fwrite_err+0x17>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"count %d != %d %d\0A\00"
@.str.1 = [20 x i8] c"toasim: write error\00"
define i32 @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 = sext i32 %5 to i64
%7 = icmp eq i64 %6, %2
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %2, i32 %5, i64 %1)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %8, %4
ret i32 undef
}