#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 *, int);
void build_crap(char *p, int n) {
  static const char crap[] = "_CRAP_\r\n";
  int 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    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1176 <build_crap+0x66>
movl   $0x8,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1142 <build_crap+0x32>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xeb0(%rip),%rsi
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    111f <build_crap+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_crap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    114f <build_crap+0x3f>
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xed9(%rip),%r15
nopw   0x0(%rax,%rax,1)
cmp    $0x8,%ebp
mov    $0x8,%ebx
cmovb  %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    %rbx,%r14
sub    %ebx,%ebp
jg     1130 <build_crap+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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