#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*/ die();
int /*<<< orphan*/ err_msg(char *);
unsigned char *raw_elf_header();
unsigned int raw_elf_header_size();
void output_header(unsigned char *buf, unsigned int buf_size,
                   unsigned int *length) {
  unsigned char *bytes;
  unsigned int i;
  *length = raw_elf_header_size();
  if (buf_size < *length) {
    err_msg("buf_size too small for output_header\n");
    die();
  }
  bytes = raw_elf_header();
  for (i = 0; i < *length; i++) {
    buf[i] = bytes[i];
  }
}


x86 assembly (clang, -O0):
<output_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <raw_elf_header_size@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jae    1184 <output_header+0x44>
lea    0xe88(%rip),%rdi
call   1060 <err_msg@plt>
mov    $0x0,%al
call   1040 <die@plt>
mov    $0x0,%al
call   1030 <raw_elf_header@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jae    11c7 <output_header+0x87>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <output_header+0x56>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_header>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <raw_elf_header_size@plt>
mov    %eax,(%rbx)
cmp    %ebp,%eax
jbe    116c <output_header+0x2c>
lea    0xea0(%rip),%rdi
call   1060 <err_msg@plt>
xor    %eax,%eax
call   1040 <die@plt>
xor    %eax,%eax
call   1030 <raw_elf_header@plt>
cmpl   $0x0,(%rbx)
je     1193 <output_header+0x53>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rax,%rcx,1),%edx
mov    %dl,(%r14,%rcx,1)
add    $0x1,%rcx
mov    (%rbx),%edx
cmp    %rdx,%rcx
jb     1180 <output_header+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"buf_size too small for output_header\0A\00"
define void @output_header(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = call i32 (...) @raw_elf_header_size()
%10 = load i32*, i32** %6
store i32 %9, i32* %10
%11 = load i32, i32* %5
%12 = load i32*, i32** %6
%13 = load i32, i32* %12
%14 = icmp ult i32 %11, %13
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = call i32 @err_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @die()
br label %18
18: ; preds = %15, %3
%19 = call i8* (...) @raw_elf_header()
store i8* %19, i8** %7
store i32 0, i32* %8
br label %20
20: ; preds = %35, %18
%21 = load i32, i32* %8
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = icmp ult i32 %21, %23
br i1 %24, label %25, label %38
25: ; preds = %20
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %25
%36 = load i32, i32* %8
%37 = add i32 %36, 1
store i32 %37, i32* %8
br label %20
38: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"buf_size too small for output_header\0A\00"
define void @output_header(i8* nocapture writeonly %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32 (...) @raw_elf_header_size()
store i32 %4, i32* %2
%5 = icmp ugt i32 %4, %1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @err_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @die()
br label %9
9: ; preds = %6, %3
%10 = tail call i8* (...) @raw_elf_header()
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9, %13
%14 = phi i64 [ %18, %13 ], [ 0, %9 ]
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %16, i8* %17
%18 = add nuw nsw i64 %14, 1
%19 = load i32, i32* %2
%20 = zext i32 %19 to i64
%21 = icmp ult i64 %18, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %9
ret void
}