#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 */

/* Variables and functions */
int /*<<< orphan*/ check_byte_arrays(unsigned char *, unsigned int,
                                     unsigned char *, unsigned int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ output_header(unsigned char *, int, unsigned int *);
unsigned char *raw_elf_header();
unsigned int raw_elf_header_size();
int /*<<< orphan*/ stderr;
void test_output_header() {
  unsigned char *expected;
  unsigned expected_len;
  unsigned char actual[128];
  unsigned actual_len;
  unsigned int min;
  expected = raw_elf_header();
  expected_len = raw_elf_header_size();
  min = 45;
  output_header(actual, 128, &actual_len);
  if (actual_len < min) {
    fprintf(stderr, "elf headers are at least %d bytes\n", min);
  }
  check_byte_arrays(actual, actual_len, expected, expected_len, "ELF");
}


x86 assembly (clang, -O0):
<test_output_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    $0x0,%al
call   1060 <raw_elf_header@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <raw_elf_header_size@plt>
mov    %eax,-0xc(%rbp)
movl   $0x2d,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
lea    -0x94(%rbp),%rdx
call   1030 <output_header@plt>
mov    -0x94(%rbp),%eax
cmp    -0x98(%rbp),%eax
jae    11bf <test_output_header+0x6f>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x98(%rbp),%edx
lea    0xe46(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe49(%rip),%r8
call   1050 <check_byte_arrays@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_output_header>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
xor    %eax,%eax
call   1060 <raw_elf_header@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <raw_elf_header_size@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x80,%esi
call   1030 <output_header@plt>
mov    0xc(%rsp),%esi
cmp    $0x2c,%esi
ja     11a7 <test_output_header+0x57>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x2d,%edx
call   1040 <fprintf@plt>
mov    0xc(%rsp),%esi
lea    0xe75(%rip),%r8
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1050 <check_byte_arrays@plt>
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"elf headers are at least %d bytes\0A\00"
@.str.1 = [4 x i8] c"ELF\00"
define void @test_output_header() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = call i8* (...) @raw_elf_header()
store i8* %6, i8** %1
%7 = call i32 (...) @raw_elf_header_size()
store i32 %7, i32* %2
store i32 45, i32* %5
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%9 = call i32 @output_header(i8* %8, i32 128, i32* %4)
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = load i32, i32* %5
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %0
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %4
%20 = load i8*, i8** %1
%21 = load i32, i32* %2
%22 = call i32 @check_byte_arrays(i8* %18, i32 %19, i8* %20, i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"elf headers are at least %d bytes\0A\00"
@.str.1 = [4 x i8] c"ELF\00"
define void @test_output_header() {
%1 = alloca [128 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i8* (...) @raw_elf_header()
%6 = tail call i32 (...) @raw_elf_header_size()
%7 = call i32 @output_header(i8* %3, i32 128, i32* %2)
%8 = load i32, i32* %2
%9 = icmp ult i32 %8, 45
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 45)
%13 = load i32, i32* %2
br label %14
14: ; preds = %10, %0
%15 = phi i32 [ %13, %10 ], [ %8, %0 ]
%16 = call i32 @check_byte_arrays(i8* %3, i32 %15, i8* %5, i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}