#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*/ strcpy(char *, char *);
int strlen(char *);
int copy_err_header_to_buffer(int err_type, char *err_message, char *buffer) {
  if (!(err_type >= 0 && err_type <= 7))
    return 0;
  if (strlen(err_message) >= 512)
    return 0;
  buffer[0] = '\0';
  buffer[1] = '\5';
  buffer[2] = '\0';
  buffer[3] = (char)err_type;
  strcpy(buffer + 4, err_message);
  return 1;
}


x86 assembly (clang, -O0):
<copy_err_header_to_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1147 <copy_err_header_to_buffer+0x27>
cmpl   $0x7,-0x8(%rbp)
jle    1153 <copy_err_header_to_buffer+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11ae <copy_err_header_to_buffer+0x8e>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x200,%eax
jl     1173 <copy_err_header_to_buffer+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11ae <copy_err_header_to_buffer+0x8e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x5,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_err_header_to_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
cmp    $0x7,%edi
ja     1168 <copy_err_header_to_buffer+0x48>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    $0x1ff,%eax
jg     1168 <copy_err_header_to_buffer+0x48>
movw   $0x500,(%rbx)
movb   $0x0,0x2(%rbx)
mov    %bpl,0x3(%rbx)
add    $0x4,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @copy_err_header_to_buffer(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 7
br i1 %12, label %14, label %13
13: ; preds = %10, %3
store i32 0, i32* %4
br label %34
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = icmp sge i32 %16, 512
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %4
br label %34
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 5, i8* %23
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8 0, i8* %25
%26 = load i32, i32* %5
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 3
store i8 %27, i8* %29
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i8*, i8** %6
%33 = call i32 @strcpy(i8* %31, i8* %32)
store i32 1, i32* %4
br label %34
34: ; preds = %19, %18, %13
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @copy_err_header_to_buffer(i32 %0, i8* %1, i8* %2) {
%4 = icmp ult i32 %0, 8
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp sgt i32 %6, 511
br i1 %7, label %15, label %8
8: ; preds = %5
store i8 0, i8* %2
%9 = getelementptr inbounds i8, i8* %2, i64 1
store i8 5, i8* %9
%10 = getelementptr inbounds i8, i8* %2, i64 2
store i8 0, i8* %10
%11 = trunc i32 %0 to i8
%12 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %11, i8* %12
%13 = getelementptr inbounds i8, i8* %2, i64 4
%14 = tail call i32 @strcpy(i8* %13, i8* %1)
br label %15
15: ; preds = %5, %3, %8
%16 = phi i32 [ 1, %8 ], [ 0, %3 ], [ 0, %5 ]
ret i32 %16
}