#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*/ sprintf(char *, char *, char *);
char *strdup(char *);
char *string_repeat(char *string, int number_times) {
  char return_buffer[2048];
  char *ptr = return_buffer;
  *ptr = '\0';
  for (; number_times; number_times--) {
    ptr += sprintf(ptr, "%s", string);
  }
  return strdup(return_buffer);
}


x86 assembly (clang, -O0):
<string_repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     118f <string_repeat+0x6f>
mov    -0x818(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe9a(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x818(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x818(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <string_repeat+0x2a>
lea    -0x810(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_repeat>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
movb   $0x0,(%rsp)
test   %esi,%esi
je     1157 <string_repeat+0x37>
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stpcpy@plt>
sub    %ebx,%eax
cltq
add    %rax,%rbx
add    $0xffffffff,%ebp
jne    1140 <string_repeat+0x20>
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8* @string_repeat(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
store i8* %7, i8** %6
%8 = load i8*, i8** %6
store i8 0, i8* %8
br label %9
9: ; preds = %19, %2
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i8*, i8** %6
%14 = load i8*, i8** %3
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %6
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %6
br label %19
19: ; preds = %12
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
br label %9
22: ; preds = %9
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%24 = call i8* @strdup(i8* %23)
ret i8* %24
}

LLVM IR (-O2):
define noalias i8* @string_repeat(i8* nocapture %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
%5 = icmp eq i32 %1, 0
br i1 %5, label %18, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %15, %6 ], [ %4, %2 ]
%8 = phi i32 [ %16, %6 ], [ %1, %2 ]
%9 = call i8* @stpcpy(i8* %7, i8* %0)
%10 = ptrtoint i8* %9 to i64
%11 = ptrtoint i8* %7 to i64
%12 = sub i64 %10, %11
%13 = shl i64 %12, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %7, i64 %14
%16 = add nsw i32 %8, -1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6, %2
%19 = call i8* @strdup(i8* %4)
ret i8* %19
}