#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void GenerateString(int x, char *s1) {
  int i;
  char *s2;
  s2 = (char *)malloc(sizeof(char) * (1 << (x - 1)));
  for (i = 1; i < x; i++) {
    strcpy(s2, s1);
    s2[strlen(s1)] = 'a' + i;
    strcat(s2, s1);
    strcpy(s1, s2);
  }
  free(s2);
}


x86 assembly (clang, -O0):
<GenerateString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ec <GenerateString+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x61,%eax
mov    %al,-0x29(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <GenerateString+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenerateString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
lea    -0x1(%r14),%ecx
mov    $0x1,%ebx
mov    $0x1,%edi
shl    %cl,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
cmp    $0x2,%r14d
jl     11b8 <GenerateString+0x68>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x61(%rbx),%ecx
mov    %cl,(%r12,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1180 <GenerateString+0x30>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @GenerateString(i32 %0, i8* %1) {
%3 = add nsw i32 %0, -1
%4 = shl nuw i32 1, %3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %19
8: ; preds = %2, %8
%9 = phi i32 [ %17, %8 ], [ 1, %2 ]
%10 = tail call i32 @strcpy(i8* %6, i8* %1)
%11 = trunc i32 %9 to i8
%12 = add i8 %11, 97
%13 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%14 = getelementptr inbounds i8, i8* %6, i64 %13
store i8 %12, i8* %14
%15 = tail call i32 @strcat(i8* %6, i8* %1)
%16 = tail call i32 @strcpy(i8* %1, i8* %6)
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, %0
br i1 %18, label %19, label %8
19: ; preds = %8, %2
%20 = tail call i32 @free(i8* %6)
ret void
}