#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, void *data, size_t len, uint32_t *crc) {
  uint8_t *ptr = data;
  errno = 0;
  fwrite(ptr, len, 1, outfile);
  if (errno) {
    errmsg(1, "unable to write output file");
    return -1;
  }
  if (crc) {
    update_crc(ptr, 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    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e89(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    0x2e65(%rip),%rax
cmpq   $0x0,(%rax)
je     11a2 <write_out_data+0x72>
mov    $0x1,%edi
lea    0xe6f(%rip),%rsi
call   1040 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <write_out_data+0x95>
cmpq   $0x0,-0x28(%rbp)
je     11be <write_out_data+0x8e>
mov    -0x30(%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, i8* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%11 = load i8*, i8** %7
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %10
store i64 0, i64* @errno
%13 = load i32*, i32** %10
%14 = load i64, i64* %8
%15 = load i32*, i32** %6
%16 = call i32 @fwrite(i32* %13, i64 %14, i32 1, i32* %15)
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = 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 %30
21: ; preds = %4
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32*, i32** %10
%26 = load i64, i64* %8
%27 = load i32*, i32** %9
%28 = call i32 @update_crc(i32* %25, i64 %26, i32* %27)
br label %29
29: ; preds = %24, %21
store i32 0, i32* %5
br label %30
30: ; preds = %29, %19
%31 = load i32, i32* %5
ret i32 %31
}

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, i8* %1, i64 %2, i32* %3) {
%5 = bitcast i8* %1 to i32*
store i64 0, i64* @errno
%6 = tail call i32 @fwrite(i32* %5, i64 %2, i32 1, i32* %0)
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @errmsg(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %4
%12 = icmp eq i32* %3, null
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = tail call i32 @update_crc(i32* %5, i64 %2, i32* %3)
br label %15
15: ; preds = %11, %13, %9
%16 = phi i32 [ -1, %9 ], [ 0, %13 ], [ 0, %11 ]
ret i32 %16
}