#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(void *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void writeToOutputFile(FILE *file, void *datagram, size_t datagramSize) {
  fwrite(datagram, sizeof(char), datagramSize, file);
  fflush(file);
  if (ferror(file)) {
    perror("Cannot write into output file.");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<writeToOutputFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11b0 <writeToOutputFile+0x60>
lea    0xe63(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeToOutputFile>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fflush@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    117b <writeToOutputFile+0x2b>
pop    %rbx
ret
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Cannot write into output file.\00"
@EXIT_FAILURE = global i32 0
define void @writeToOutputFile(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 i8*, i8** %5
%8 = load i64, i64* %6
%9 = load i32*, i32** %4
%10 = call i32 @fwrite(i8* %7, i32 1, i64 %8, i32* %9)
%11 = load i32*, i32** %4
%12 = call i32 @fflush(i32* %11)
%13 = load i32*, i32** %4
%14 = call i64 @ferror(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Cannot write into output file.\00"
@EXIT_FAILURE = global i32 0
define void @writeToOutputFile(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32 @fwrite(i8* %1, i32 1, i64 %2, i32* %0)
%5 = tail call i32 @fflush(i32* %0)
%6 = tail call i64 @ferror(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
ret void
}