#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*/ fprintf(int /*<<< orphan*/, char *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int output_header(FILE *output_file, int file_format) {
  if (!output_file) {
    fprintf(stderr, "output_header: No output file given\n");
    return 1;
  }
  size_t bytes_written, write_size;
  if (file_format == 1) {
    write_size = 4;
    bytes_written = fwrite("\0\0\0\0", sizeof(char), write_size, output_file);
  } else {
    write_size = 8;
    bytes_written = fwrite("DD-WRT\0\0", sizeof(char), write_size, output_file);
  }
  if (bytes_written < write_size) {
    fprintf(stderr, "output_header: Problem writing header\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<output_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115b <output_header+0x3b>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ea <output_header+0xca>
cmpl   $0x1,-0x14(%rbp)
jne    118f <output_header+0x6f>
movq   $0x4,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xed0(%rip),%rdi
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    %rax,-0x20(%rbp)
jmp    11b4 <output_header+0x94>
movq   $0x8,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xeab(%rip),%rdi
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11e3 <output_header+0xc3>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ea <output_header+0xca>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_header>:
push   %rbx
test   %rdi,%rdi
je     1141 <output_header+0x21>
mov    %rdi,%rcx
cmp    $0x1,%esi
jne    114a <output_header+0x2a>
lea    0xf17(%rip),%rdi
mov    $0x4,%ebx
mov    $0x4,%edx
jmp    115b <output_header+0x3b>
lea    0xeb8(%rip),%rsi
jmp    1173 <output_header+0x53>
lea    0xf00(%rip),%rdi
mov    $0x8,%ebx
mov    $0x8,%edx
mov    $0x1,%esi
call   1040 <fwrite@plt>
xor    %ecx,%ecx
cmp    %rbx,%rax
jae    1186 <output_header+0x66>
lea    0xeb2(%rip),%rsi
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1030 <fprintf@plt>
mov    $0x1,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"output_header: No output file given\0A\00"
@.str.1 = [5 x i8] zeroinitializer
@.str.2 = [9 x i8] c"DD-WRT\00\00\00"
@.str.3 = [39 x i8] c"output_header: Problem writing header\0A\00"
define i32 @output_header(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %32
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %13
store i64 4, i64* %7
%17 = load i64, i64* %7
%18 = load i32*, i32** %4
%19 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1, i64 %17, i32* %18)
store i64 %19, i64* %6
br label %24
20: ; preds = %13
store i64 8, i64* %7
%21 = load i64, i64* %7
%22 = load i32*, i32** %4
%23 = call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1, i64 %21, i32* %22)
store i64 %23, i64* %6
br label %24
24: ; preds = %20, %16
%25 = load i64, i64* %6
%26 = load i64, i64* %7
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %32
31: ; preds = %24
store i32 0, i32* %3
br label %32
32: ; preds = %31, %28, %10
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"output_header: No output file given\0A\00"
@.str.1 = [5 x i8] zeroinitializer
@.str.2 = [9 x i8] c"DD-WRT\00\00\00"
@.str.3 = [39 x i8] c"output_header: Problem writing header\0A\00"
define i32 @output_header(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 1
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1, i64 4, i32* %0)
br label %10
8: ; preds = %4
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1, i64 8, i32* %0)
br label %10
10: ; preds = %8, %6
%11 = phi i64 [ %7, %6 ], [ %9, %8 ]
%12 = phi i64 [ 4, %6 ], [ 8, %8 ]
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10, %2
%15 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), %10 ]
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* %15)
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ 0, %10 ], [ 1, %14 ]
ret i32 %19
}