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

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
void build_crap(char *p, size_t n) {
  static const char crap[] = "_CRAP_\r\n";
  size_t i;
  while (n > 0) {
    i = sizeof(crap) - 1;
    if (i > n)
      i = n;
    memcpy(p, crap, i);
    p += i;
    n -= i;
  }
}


x86 assembly (clang, -O0):
<build_crap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    117d <build_crap+0x6d>
movq   $0x8,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    1149 <build_crap+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xea8(%rip),%rsi
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <build_crap+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_crap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1153 <build_crap+0x43>
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xed6(%rip),%r15
nopw   0x0(%rax,%rax,1)
cmp    $0x8,%r12
mov    $0x8,%ebx
cmovb  %r12,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
add    %rbx,%r14
sub    %rbx,%r12
jne    1130 <build_crap+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@build_crap.crap = internal constant [9 x i8] c"_CRAP_\0D\0A\00"
define void @build_crap(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
br label %6
6: ; preds = %15, %2
%7 = load i64, i64* %4
%8 = icmp ugt i64 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %6
store i64 8, i64* %5
%10 = load i64, i64* %5
%11 = load i64, i64* %4
%12 = icmp ugt i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i64, i64* %4
store i64 %14, i64* %5
br label %15
15: ; preds = %13, %9
%16 = load i8*, i8** %3
%17 = load i64, i64* %5
%18 = call i32 @memcpy(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @build_crap.crap, i64 0, i64 0), i64 %17)
%19 = load i64, i64* %5
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 %19
store i8* %21, i8** %3
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = sub i64 %23, %22
store i64 %24, i64* %4
br label %6
25: ; preds = %6
ret void
}

LLVM IR (-O2):
@build_crap.crap = internal constant [9 x i8] c"_CRAP_\0D\0A\00"
define void @build_crap(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %13, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %11, %4 ], [ %1, %2 ]
%6 = phi i8* [ %10, %4 ], [ %0, %2 ]
%7 = icmp ult i64 %5, 8
%8 = select i1 %7, i64 %5, i64 8
%9 = tail call i32 @memcpy(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @build_crap.crap, i64 0, i64 0), i64 %8)
%10 = getelementptr inbounds i8, i8* %6, i64 %8
%11 = sub i64 %5, %8
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4, %2
ret void
}