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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int snprintf(char *, int, char *, int, int);
int /*<<< orphan*/ stderr;
void build_content(char *p, size_t n) {
  char line_buffer[80];
  int k;
  int i = 0;
  while (n > 0) {
    k = snprintf(
        line_buffer, sizeof(line_buffer),
        "%04d_ABCDEFGHIJKL_This_line_is_64_bytes_long_ABCDEFGHIJKL_%04d\r\n", i,
        i);
    if (k != 64) {
      fprintf(stderr, "snprintf() returned %d in build_content()\n", k);
    }
    ++i;
    if (n >= 64) {
      memcpy(p, line_buffer, 64);
      p += 64;
      n -= 64;
    } else {
      memcpy(p, line_buffer, n);
      p += n;
      n = 0;
    }
  }
}


x86 assembly (clang, -O0):
<build_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x68(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    1200 <build_content+0xd0>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%ecx
mov    -0x68(%rbp),%r8d
mov    $0x50,%esi
lea    0xe97(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x40,-0x64(%rbp)
je     1193 <build_content+0x63>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x64(%rbp),%edx
lea    0xeb3(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
cmpq   $0x40,-0x10(%rbp)
jb     11d6 <build_content+0xa6>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x40,%rax
mov    %rax,-0x10(%rbp)
jmp    11fb <build_content+0xcb>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
jmp    1147 <build_content+0x17>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_content>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %rsi,%rsi
je     11c0 <build_content+0x90>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xeae(%rip),%r15
mov    %rsp,%r12
lea    0xee5(%rip),%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    %ebp,%r8d
call   1030 <snprintf@plt>
cmp    $0x40,%eax
je     118d <build_content+0x5d>
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
cmp    $0x3f,%r14
jbe    11b2 <build_content+0x82>
add    $0x1,%ebp
mov    $0x40,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <memcpy@plt>
add    $0x40,%rbx
add    $0xffffffffffffffc0,%r14
jne    1160 <build_content+0x30>
jmp    11c0 <build_content+0x90>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <memcpy@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"%04d_ABCDEFGHIJKL_This_line_is_64_bytes_long_ABCDEFGHIJKL_%04d\0D\0A\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"snprintf() returned %d in build_content()\0A\00"
define void @build_content(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %7
br label %8
8: ; preds = %43, %2
%9 = load i64, i64* %4
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %8
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* %7
%14 = load i32, i32* %7
%15 = call i32 @snprintf(i8* %12, i32 80, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 64
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* %6
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %11
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = load i64, i64* %4
%26 = icmp uge i64 %25, 64
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%30 = call i32 @memcpy(i8* %28, i8* %29, i64 64)
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 64
store i8* %32, i8** %3
%33 = load i64, i64* %4
%34 = sub i64 %33, 64
store i64 %34, i64* %4
br label %43
35: ; preds = %22
%36 = load i8*, i8** %3
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%38 = load i64, i64* %4
%39 = call i32 @memcpy(i8* %36, i8* %37, i64 %38)
%40 = load i64, i64* %4
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 %40
store i8* %42, i8** %3
store i64 0, i64* %4
br label %43
43: ; preds = %35, %27
br label %8
44: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"%04d_ABCDEFGHIJKL_This_line_is_64_bytes_long_ABCDEFGHIJKL_%04d\0D\0A\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"snprintf() returned %d in build_content()\0A\00"
define void @build_content(i8* %0, i64 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp eq i64 %1, 0
br i1 %5, label %25, label %6
6: ; preds = %2, %19
%7 = phi i32 [ %20, %19 ], [ 0, %2 ]
%8 = phi i8* [ %22, %19 ], [ %0, %2 ]
%9 = phi i64 [ %23, %19 ], [ %1, %2 ]
%10 = call i32 @snprintf(i8* %4, i32 80, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %7)
%11 = icmp eq i32 %10, 64
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %15
15: ; preds = %12, %6
%16 = icmp ugt i64 %9, 63
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = call i32 @memcpy(i8* %8, i8* %4, i64 %9)
br label %25
19: ; preds = %15
%20 = add nuw nsw i32 %7, 1
%21 = call i32 @memcpy(i8* %8, i8* %4, i64 64)
%22 = getelementptr inbounds i8, i8* %8, i64 64
%23 = add i64 %9, -64
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %6
25: ; preds = %19, %17, %2
ret void
}