#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ stdout;
int strlen(char const *);
void repeat(const char *alu, const char *title, int n) {
  int len = strlen(alu);
  char buffer[len + 60];
  int pos = 0;
  memcpy(buffer, alu, len);
  memcpy(buffer + len, alu, 60);
  fputs(title, stdout);
  while (n > 0) {
    int bytes = n > 60 ? 60 : n;
    fwrite(buffer + pos, bytes, 1, stdout);
    pos += bytes;
    if (pos > len) {
      pos -= len;
    }
    fputc('\n', stdout);
    n -= bytes;
  }
}


x86 assembly (clang, -O0):
<repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x3c,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3c,%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1267 <repeat+0x117>
cmpl   $0x3c,-0x14(%rbp)
jle    11f7 <repeat+0xa7>
mov    $0x3c,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fd <repeat+0xad>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%esi
mov    0x2dc8(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1244 <repeat+0xf4>
mov    -0x18(%rbp),%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <repeat+0x86>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<repeat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    0x3c(%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1060 <memcpy@plt>
movslq %r14d,%rdi
mov    %rbx,-0x30(%rbp)
add    %rbx,%rdi
mov    %r13,%rsi
mov    $0x3c,%edx
call   1060 <memcpy@plt>
mov    0x2e30(%rip),%r13
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1040 <fputs@plt>
test   %r12d,%r12d
jle    121d <repeat+0xcd>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x3c,%r12d
mov    $0x3c,%ebx
cmovb  %r12d,%ebx
movslq %r15d,%r15
mov    -0x30(%rbp),%rax
lea    (%rax,%r15,1),%rdi
mov    0x0(%r13),%ecx
mov    %ebx,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
add    %ebx,%r15d
cmp    %r14d,%r15d
mov    $0x0,%eax
cmovg  %r14d,%eax
sub    %eax,%r15d
mov    0x0(%r13),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
sub    %ebx,%r12d
jg     11d0 <repeat+0x80>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define void @repeat(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 60
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
store i32 0, i32* %10
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %18, i64 %23
%25 = load i8*, i8** %4
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 60)
%27 = load i8*, i8** %5
%28 = load i32, i32* @stdout
%29 = call i32 @fputs(i8* %27, i32 %28)
br label %30
30: ; preds = %57, %3
%31 = load i32, i32* %6
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %63
33: ; preds = %30
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 60
br i1 %35, label %36, label %37
36: ; preds = %33
br label %39
37: ; preds = %33
%38 = load i32, i32* %6
br label %39
39: ; preds = %37, %36
%40 = phi i32 [ 60, %36 ], [ %38, %37 ]
store i32 %40, i32* %11
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %18, i64 %42
%44 = load i32, i32* %11
%45 = load i32, i32* @stdout
%46 = call i32 @fwrite(i8* %43, i32 %44, i32 1, i32 %45)
%47 = load i32, i32* %11
%48 = load i32, i32* %10
%49 = add nsw i32 %48, %47
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = load i32, i32* %7
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %39
%54 = load i32, i32* %7
%55 = load i32, i32* %10
%56 = sub nsw i32 %55, %54
store i32 %56, i32* %10
br label %57
57: ; preds = %53, %39
%58 = load i32, i32* @stdout
%59 = call i32 @fputc(i8 signext 10, i32 %58)
%60 = load i32, i32* %11
%61 = load i32, i32* %6
%62 = sub nsw i32 %61, %60
store i32 %62, i32* %6
br label %30
63: ; preds = %30
%64 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @repeat(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 60
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @memcpy(i8* %7, i8* %0, i32 %4)
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = call i32 @memcpy(i8* %10, i8* %0, i32 60)
%12 = load i32, i32* @stdout
%13 = call i32 @fputs(i8* %1, i32 %12)
%14 = icmp sgt i32 %2, 0
br i1 %14, label %15, label %32
15: ; preds = %3, %15
%16 = phi i32 [ %30, %15 ], [ %2, %3 ]
%17 = phi i32 [ %27, %15 ], [ 0, %3 ]
%18 = icmp ult i32 %16, 60
%19 = select i1 %18, i32 %16, i32 60
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i8, i8* %7, i64 %20
%22 = load i32, i32* @stdout
%23 = call i32 @fwrite(i8* %21, i32 %19, i32 1, i32 %22)
%24 = add nsw i32 %19, %17
%25 = icmp sgt i32 %24, %4
%26 = select i1 %25, i32 %4, i32 0
%27 = sub nsw i32 %24, %26
%28 = load i32, i32* @stdout
%29 = call i32 @fputc(i8 signext 10, i32 %28)
%30 = sub nsw i32 %16, %19
%31 = icmp sgt i32 %30, 0
br i1 %31, label %15, label %32
32: ; preds = %15, %3
ret void
}