#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*/ errno;
int /*<<< orphan*/ fatal_error(int /*<<< orphan*/, char *, char *, int, int,
                               int, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int fwrite(void *, int, int, int /*<<< orphan*/ *);
void _blockwrite(FILE *fp, int nelem, int size, void *data, char *what,
                 char *file, int line) {
  int len;
  if ((len = fwrite(data, size, nelem, fp)) != nelem)
    fatal_error(errno,
                "writing %s (%dx%d, len=%d, pos=%d) from file %s, "
                "line %d",
                what, nelem, size, len, ftell(fp), file, line);
}


x86 assembly (clang, -O0):
<_blockwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
call   1050 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
cmp    -0xc(%rbp),%eax
je     11d4 <_blockwrite+0xa4>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    %eax,%r11d
mov    -0x28(%rbp),%r10
mov    0x10(%rbp),%eax
lea    0xe3e(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <fatal_error@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_blockwrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%rbp
mov    %rcx,%rdi
mov    %edx,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1050 <fwrite@plt>
cmp    %ebx,%eax
jne    1162 <_blockwrite+0x32>
add    $0x8,%rsp
jmp    11a7 <_blockwrite+0x77>
mov    %eax,%r13d
mov    0x2e74(%rip),%rax
mov    %r14,(%rsp)
mov    (%rax),%r14d
mov    %rbp,%rdi
call   1030 <ftell@plt>
sub    $0x8,%rsp
lea    0xe7a(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %r12d,%r8d
mov    %r13d,%r9d
mov    0x48(%rsp),%ebp
push   %rbp
push   0x10(%rsp)
push   %rax
call   1040 <fatal_error@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [57 x i8] c"writing %s (%dx%d, len=%d, pos=%d) from file %s, line %d\00"
define void @_blockwrite(i32* %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%16 = load i8*, i8** %11
%17 = load i32, i32* %10
%18 = load i32, i32* %9
%19 = load i32*, i32** %8
%20 = call i32 @fwrite(i8* %16, i32 %17, i32 %18, i32* %19)
store i32 %20, i32* %15
%21 = load i32, i32* %9
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %7
%24 = load i32, i32* @errno
%25 = load i8*, i8** %12
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = load i32, i32* %15
%29 = load i32*, i32** %8
%30 = call i32 @ftell(i32* %29)
%31 = load i8*, i8** %13
%32 = load i32, i32* %14
%33 = call i32 @fatal_error(i32 %24, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26, i32 %27, i32 %28, i32 %30, i8* %31, i32 %32)
br label %34
34: ; preds = %23, %7
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [57 x i8] c"writing %s (%dx%d, len=%d, pos=%d) from file %s, line %d\00"
define void @_blockwrite(i32* nocapture %0, i32 %1, i32 %2, i8* nocapture %3, i8* %4, i8* %5, i32 %6) {
%8 = tail call i32 @fwrite(i8* %3, i32 %2, i32 %1, i32* %0)
%9 = icmp eq i32 %8, %1
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = tail call i32 @ftell(i32* %0)
%13 = tail call i32 @fatal_error(i32 %11, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %1, i32 %2, i32 %8, i32 %12, i8* %5, i32 %6)
br label %14
14: ; preds = %10, %7
ret void
}