#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*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
void repeat(char *restrict target, const char *restrict val,
            const char separator, size_t repeats) {
  size_t val_length = strlen(val);
  for (unsigned int r = 0; r < repeats; r++) {
    if (r > 0) {
      *target++ = separator;
    }
    memcpy(target, val, val_length);
    target += val_length;
  }
  *target = '\0';
}


x86 assembly (clang, -O0):
<repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    11a3 <repeat+0x83>
cmpl   $0x0,-0x2c(%rbp)
jbe    1178 <repeat+0x58>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114d <repeat+0x2d>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<repeat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %r14,%r14
je     1179 <repeat+0x59>
mov    %rax,%r13
mov    $0x1,%ebp
jmp    116b <repeat+0x4b>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
add    %r13,%rbx
mov    %ebp,%eax
add    $0x1,%ebp
cmp    %r14,%rax
jae    1179 <repeat+0x59>
cmp    $0x1,%ebp
je     1150 <repeat+0x30>
mov    %r15b,(%rbx)
add    $0x1,%rbx
jmp    1150 <repeat+0x30>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @repeat(i8* noalias %0, i8* noalias %1, i8 signext %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i64 %3, i64* %8
%11 = load i8*, i8** %6
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %9
store i32 0, i32* %10
br label %13
13: ; preds = %33, %4
%14 = load i32, i32* %10
%15 = zext i32 %14 to i64
%16 = load i64, i64* %8
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = load i32, i32* %10
%20 = icmp ugt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8, i8* %7
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 %22, i8* %23
br label %25
25: ; preds = %21, %18
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i64, i64* %9
%29 = call i32 @memcpy(i8* %26, i8* %27, i64 %28)
%30 = load i64, i64* %9
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 %30
store i8* %32, i8** %5
br label %33
33: ; preds = %25
%34 = load i32, i32* %10
%35 = add i32 %34, 1
store i32 %35, i32* %10
br label %13
36: ; preds = %13
%37 = load i8*, i8** %5
store i8 0, i8* %37
ret void
}

LLVM IR (-O2):
define void @repeat(i8* noalias %0, i8* noalias %1, i8 signext %2, i64 %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = icmp eq i64 %3, 0
br i1 %6, label %7, label %9
7: ; preds = %15, %4
%8 = phi i8* [ %0, %4 ], [ %18, %15 ]
store i8 0, i8* %8
ret void
9: ; preds = %4, %15
%10 = phi i32 [ %19, %15 ], [ 0, %4 ]
%11 = phi i8* [ %18, %15 ], [ %0, %4 ]
%12 = icmp eq i32 %10, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %2, i8* %11
br label %15
15: ; preds = %13, %9
%16 = phi i8* [ %14, %13 ], [ %11, %9 ]
%17 = tail call i32 @memcpy(i8* %16, i8* %1, i64 %5)
%18 = getelementptr inbounds i8, i8* %16, i64 %5
%19 = add i32 %10, 1
%20 = zext i32 %19 to i64
%21 = icmp ult i64 %20, %3
br i1 %21, label %9, label %7
}