#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 */
scalar_t__ ferror(int /*<<< orphan*/ *);
int fwrite(void *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ my_err(char *, long long, ...);
int /*<<< orphan*/ strerror(scalar_t__);
void util_must_fwrite(FILE *file, void *buf, size_t size) {
  if (size != 0 && fwrite(buf, size, 1, file) != 1) {
    if (ferror(file)) {
      my_err("error writing %lld bytes: %s", (long long)size,
             strerror(ferror(file)));
    } else {
      my_err("error writing %lld bytes\n", (long long)size);
    }
  }
}


x86 assembly (clang, -O0):
<util_must_fwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11da <util_must_fwrite+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
je     11da <util_must_fwrite+0x9a>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11c3 <util_must_fwrite+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rdi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <my_err@plt>
jmp    11d5 <util_must_fwrite+0x95>
mov    -0x18(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <my_err@plt>
jmp    11da <util_must_fwrite+0x9a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_must_fwrite>:
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     1167 <util_must_fwrite+0x27>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
jne    116f <util_must_fwrite+0x2f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     119e <util_must_fwrite+0x5e>
mov    %rax,%rdi
call   1050 <strerror@plt>
lea    0xe75(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <my_err@plt>
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <my_err@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"error writing %lld bytes: %s\00"
@.str.1 = [26 x i8] c"error writing %lld bytes\0A\00"
define void @util_must_fwrite(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i64, i64* %6
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = load i32*, i32** %4
%13 = call i32 @fwrite(i8* %10, i64 %11, i32 1, i32* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %29
15: ; preds = %9
%16 = load i32*, i32** %4
%17 = call i64 @ferror(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i64, i64* %6
%21 = load i32*, i32** %4
%22 = call i64 @ferror(i32* %21)
%23 = call i32 @strerror(i64 %22)
%24 = call i32 (i8*, i64, ...) @my_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %20, i32 %23)
br label %28
25: ; preds = %15
%26 = load i64, i64* %6
%27 = call i32 (i8*, i64, ...) @my_err(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %25, %19
br label %29
29: ; preds = %28, %9, %3
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"error writing %lld bytes: %s\00"
@.str.1 = [26 x i8] c"error writing %lld bytes\0A\00"
define void @util_must_fwrite(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i32 @fwrite(i8* %1, i64 %2, i32 1, i32* %0)
%7 = icmp eq i32 %6, 1
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = tail call i64 @ferror(i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @strerror(i64 %9)
%13 = tail call i32 (i8*, i64, ...) @my_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %2, i32 %12)
br label %16
14: ; preds = %8
%15 = tail call i32 (i8*, i64, ...) @my_err(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %2)
br label %16
16: ; preds = %11, %14, %5, %3
ret void
}