#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 */
char *needMem(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *mkString(int len) {
  static char *base = "abcdefghijklmnopABCDEFGHIJKLMNOP";
  int baseLen = strlen(base);
  int numRep = (len + 2 * baseLen) / baseLen;
  int i;
  char *p, *str = needMem((numRep * baseLen) + 1);
  for (p = str, i = 0; i < numRep; i++, p += baseLen)
    strcpy(p, base);
  str[len] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<mkString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ef6(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
imul   -0x8(%rbp),%edi
add    $0x1,%edi
call   1050 <needMem@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b9 <mkString+0x89>
mov    -0x18(%rbp),%rdi
mov    0x2ea3(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    117e <mkString+0x4e>
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0xebb(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    (%r14,%rbx,2),%eax
cltd
idiv   %ebx
mov    %eax,%ebp
mov    %eax,%edi
imul   %ebx,%edi
add    $0x1,%edi
call   1050 <needMem@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    1193 <mkString+0x63>
movslq %ebx,%r13
lea    0xe8d(%rip),%r12
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    %r13,%rbx
add    $0xffffffff,%ebp
jne    1180 <mkString+0x50>
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [33 x i8] c"abcdefghijklmnopABCDEFGHIJKLMNOP\00"
define i8* @mkString(i32 %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%3 = shl nsw i32 %2, 1
%4 = add nsw i32 %3, %0
%5 = sdiv i32 %4, %2
%6 = mul nsw i32 %5, %2
%7 = add nsw i32 %6, 1
%8 = tail call i8* @needMem(i32 %7)
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = sext i32 %2 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ 0, %10 ], [ %16, %12 ]
%14 = phi i8* [ %8, %10 ], [ %17, %12 ]
%15 = tail call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%16 = add nuw nsw i32 %13, 1
%17 = getelementptr inbounds i8, i8* %14, i64 %11
%18 = icmp eq i32 %16, %5
br i1 %18, label %19, label %12
19: ; preds = %12, %1
%20 = sext i32 %0 to i64
%21 = getelementptr inbounds i8, i8* %8, i64 %20
store i8 0, i8* %21
ret i8* %8
}