#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sld_memory_pool_add(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
char *sld_string_multiply(char *string, int factor, char separator) {
  int i;
  char separator_string[2];
  char *concat_string = NULL;
  concat_string = (char *)malloc(strlen(string) * factor + factor + 1);
  if (concat_string == NULL) {
    printf("Unable to allocate memory for string: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else {
    *concat_string = '\0';
    separator_string[0] = separator;
    separator_string[1] = '\0';
    for (i = 0; i < factor; i++) {
      strcat(concat_string, string);
      if (i == factor - 1)
        break;
      strcat(concat_string, separator_string);
    }
    sld_memory_pool_add(concat_string);
  }
  return concat_string;
}


x86 assembly (clang, -O0):
<sld_string_multiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
imul   -0xc(%rbp),%edi
add    -0xc(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <sld_string_multiply+0x70>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xd(%rbp),%al
mov    %al,-0x16(%rbp)
movb   $0x0,-0x15(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1242 <sld_string_multiply+0xd2>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1227 <sld_string_multiply+0xb7>
jmp    1242 <sld_string_multiply+0xd2>
mov    -0x20(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f8 <sld_string_multiply+0x88>
mov    -0x20(%rbp),%rdi
call   1070 <sld_memory_pool_add@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sld_string_multiply>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
imul   %ebx,%eax
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11f1 <sld_string_multiply+0x81>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %bpl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
test   %ebx,%ebx
jle    11db <sld_string_multiply+0x6b>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
add    $0xffffffff,%ebx
je     11db <sld_string_multiply+0x6b>
lea    0x6(%rsp),%rbp
nop
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
add    $0xffffffff,%ebx
jne    11c0 <sld_string_multiply+0x50>
mov    %r15,%rdi
call   1070 <sld_memory_pool_add@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfa(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Unable to allocate memory for string: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @sld_string_multiply(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca [2 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8 %2, i8* %6
store i8* null, i8** %9
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = load i32, i32* %5
%13 = mul nsw i32 %11, %12
%14 = load i32, i32* %5
%15 = add nsw i32 %13, %14
%16 = add nsw i32 %15, 1
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %3
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %3
%28 = load i8*, i8** %9
store i8 0, i8* %28
%29 = load i8, i8* %6
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %29, i8* %30
%31 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 0, i8* %31
store i32 0, i32* %7
br label %32
32: ; preds = %49, %27
%33 = load i32, i32* %7
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %52
36: ; preds = %32
%37 = load i8*, i8** %9
%38 = load i8*, i8** %4
%39 = call i32 @strcat(i8* %37, i8* %38)
%40 = load i32, i32* %7
%41 = load i32, i32* %5
%42 = sub nsw i32 %41, 1
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %45
44: ; preds = %36
br label %52
45: ; preds = %36
%46 = load i8*, i8** %9
%47 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%48 = call i32 @strcat(i8* %46, i8* %47)
br label %49
49: ; preds = %45
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %32
52: ; preds = %44, %32
%53 = load i8*, i8** %9
%54 = call i32 @sld_memory_pool_add(i8* %53)
br label %55
55: ; preds = %52
%56 = load i8*, i8** %9
ret i8* %56
}

LLVM IR (-O2):
@.str = [42 x i8] c"Unable to allocate memory for string: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @sld_string_multiply(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = mul nsw i32 %6, %1
%8 = add i32 %1, 1
%9 = add i32 %8, %7
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
store i8 0, i8* %11
store i8 %2, i8* %5
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %20
%21 = icmp sgt i32 %1, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = add nsw i32 %1, -1
%24 = call i32 @strcat(i8* %11, i8* %0)
%25 = icmp eq i32 %23, 0
br i1 %25, label %32, label %26
26: ; preds = %22, %26
%27 = phi i32 [ %29, %26 ], [ 0, %22 ]
%28 = call i32 @strcat(i8* %11, i8* %5)
%29 = add nuw nsw i32 %27, 1
%30 = call i32 @strcat(i8* %11, i8* %0)
%31 = icmp eq i32 %29, %23
br i1 %31, label %32, label %26
32: ; preds = %26, %22, %19
%33 = call i32 @sld_memory_pool_add(i8* %11)
ret i8* %11
}