#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errmsg(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, size_t, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ update_crc(int /*<<< orphan*/ *, size_t,
                              int /*<<< orphan*/ *);
int write_out_data(FILE *outfile, uint8_t *data, size_t len, uint32_t *crc) {
  errno = 0;
  fwrite(data, len, 1, outfile);
  if (errno) {
    errmsg(1, "unable to write output file");
    return -1;
  }
  if (crc) {
    update_crc(data, len, crc);
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_out_data>:
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    0x2e91(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    0x2e6d(%rip),%rax
cmpq   $0x0,(%rax)
je     119a <write_out_data+0x6a>
mov    $0x1,%edi
lea    0xe77(%rip),%rsi
call   1040 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <write_out_data+0x8d>
cmpq   $0x0,-0x28(%rbp)
je     11b6 <write_out_data+0x86>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <update_crc@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_out_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    0x2e96(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    $0x1,%edx
call   1050 <fwrite@plt>
cmpq   $0x0,0x0(%rbp)
je     1181 <write_out_data+0x51>
lea    0xe90(%rip),%rsi
mov    $0x1,%edi
call   1040 <errmsg@plt>
mov    $0xffffffff,%ebp
jmp    1196 <write_out_data+0x66>
xor    %ebp,%ebp
test   %r14,%r14
je     1196 <write_out_data+0x66>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <update_crc@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [28 x i8] c"unable to write output file\00"
define i32 @write_out_data(i32* %0, i32* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i64 0, i64* @errno
%10 = load i32*, i32** %7
%11 = load i64, i64* %8
%12 = load i32*, i32** %6
%13 = call i32 @fwrite(i32* %10, i64 %11, i32 1, i32* %12)
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @errmsg(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %27
18: ; preds = %4
%19 = load i32*, i32** %9
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32*, i32** %7
%23 = load i64, i64* %8
%24 = load i32*, i32** %9
%25 = call i32 @update_crc(i32* %22, i64 %23, i32* %24)
br label %26
26: ; preds = %21, %18
store i32 0, i32* %5
br label %27
27: ; preds = %26, %16
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [28 x i8] c"unable to write output file\00"
define i32 @write_out_data(i32* nocapture %0, i32* %1, i64 %2, i32* %3) {
store i64 0, i64* @errno
%5 = tail call i32 @fwrite(i32* %1, i64 %2, i32 1, i32* %0)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @errmsg(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %14
10: ; preds = %4
%11 = icmp eq i32* %3, null
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 @update_crc(i32* %1, i64 %2, i32* %3)
br label %14
14: ; preds = %10, %12, %8
%15 = phi i32 [ -1, %8 ], [ 0, %12 ], [ 0, %10 ]
ret i32 %15
}