#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 strlen(char *);
char *fill_buf(char *buf, char *s, int size) {
  int i, j;
  char *cbuf = buf;
  for (i = 0; i < size; i += strlen(s)) {
    for (j = 0; j < strlen(s); j++) {
      cbuf[i + j] = s[j];
    }
  }
  return (char *)buf;
}


x86 assembly (clang, -O0):
<fill_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <fill_buf+0x93>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    118a <fill_buf+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <fill_buf+0x35>
jmp    118f <fill_buf+0x7f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <fill_buf+0x22>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %edx,%edx
jle    117e <fill_buf+0x6e>
mov    %edx,%r15d
mov    %rsi,%rbx
xor    %r12d,%r12d
jmp    1140 <fill_buf+0x30>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %eax,%r12d
cmp    %r15d,%r12d
jge    117e <fill_buf+0x6e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1130 <fill_buf+0x20>
movslq %r12d,%r13
add    %r14,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rbp,1),%eax
mov    %al,0x0(%r13,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1160 <fill_buf+0x50>
jmp    1130 <fill_buf+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @fill_buf(i8* returned writeonly %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %25
5: ; preds = %3, %21
%6 = phi i32 [ %23, %21 ], [ 0, %3 ]
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = sext i32 %6 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %17, %11 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = add nsw i64 %12, %10
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 %14, i8* %16
%17 = add nuw nsw i64 %12, 1
%18 = tail call i32 @strlen(i8* %1)
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %5
%22 = tail call i32 @strlen(i8* %1)
%23 = add nsw i32 %22, %6
%24 = icmp slt i32 %23, %2
br i1 %24, label %5, label %25
25: ; preds = %21, %3
ret i8* %0
}