#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*/ free(char *);
int /*<<< orphan*/ fwrite_unlocked(char *, int, size_t, int /*<<< orphan*/);
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ putchar_unlocked(char);
int /*<<< orphan*/ stdout;
size_t strlen(char const *);
void repeat_fasta(char const *s, size_t count) {
  size_t pos = 0;
  size_t len = strlen(s);
  char *s2 = malloc(len + 60);
  memcpy(s2, s, len);
  memcpy(s2 + len, s, 60);
  do {
    size_t line = ((60) <= (count) ? (60) : (count));
    fwrite_unlocked(s2 + pos, 1, line, stdout);
    putchar_unlocked('\n');
    pos += line;
    if (pos >= len)
      pos -= len;
    count -= line;
  } while (count);
  free(s2);
}


x86 assembly (clang, -O0):
<repeat_fasta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x3c,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3c,%edx
call   1050 <memcpy@plt>
mov    $0x3c,%eax
cmp    -0x10(%rbp),%rax
ja     11dc <repeat_fasta+0x7c>
mov    $0x3c,%eax
mov    %rax,-0x38(%rbp)
jmp    11e4 <repeat_fasta+0x84>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    0x2de1(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1080 <fwrite_unlocked@plt>
mov    $0xa,%edi
call   1060 <putchar_unlocked@plt>
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     123e <repeat_fasta+0xde>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bf <repeat_fasta+0x5f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<repeat_fasta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%r14
lea    0x3c(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
lea    (%r15,%r14,1),%rdi
mov    %r12,%rsi
mov    $0x3c,%edx
call   1050 <memcpy@plt>
xor    %ebx,%ebx
mov    0x2e33(%rip),%rbp
nopl   (%rax)
cmp    $0x3c,%r13
mov    $0x3c,%r12d
cmovb  %r13,%r12
lea    (%r15,%rbx,1),%rdi
mov    0x0(%rbp),%ecx
mov    $0x1,%esi
mov    %r12,%rdx
call   1080 <fwrite_unlocked@plt>
mov    $0xa,%edi
call   1060 <putchar_unlocked@plt>
add    %r12,%rbx
cmp    %r14,%rbx
mov    $0x0,%eax
cmovae %r14,%rax
sub    %rax,%rbx
sub    %r12,%r13
jne    11b0 <repeat_fasta+0x50>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@stdout = global i32 0
define void @repeat_fasta(i8* %0, i64 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, 60
%5 = tail call i8* @malloc(i64 %4)
%6 = trunc i64 %3 to i32
%7 = tail call i32 @memcpy(i8* %5, i8* %0, i32 %6)
%8 = getelementptr inbounds i8, i8* %5, i64 %3
%9 = tail call i32 @memcpy(i8* %8, i8* %0, i32 60)
br label %10
10: ; preds = %10, %2
%11 = phi i64 [ 0, %2 ], [ %22, %10 ]
%12 = phi i64 [ %1, %2 ], [ %23, %10 ]
%13 = icmp ult i64 %12, 60
%14 = select i1 %13, i64 %12, i64 60
%15 = getelementptr inbounds i8, i8* %5, i64 %11
%16 = load i32, i32* @stdout
%17 = tail call i32 @fwrite_unlocked(i8* %15, i32 1, i64 %14, i32 %16)
%18 = tail call i32 @putchar_unlocked(i8 signext 10)
%19 = add i64 %14, %11
%20 = icmp ult i64 %19, %3
%21 = select i1 %20, i64 0, i64 %3
%22 = sub i64 %19, %21
%23 = sub i64 %12, %14
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %10
25: ; preds = %10
%26 = tail call i32 @free(i8* %5)
ret void
}