#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*/ calculateRequiredMemory(int);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void generateString(int lineCount) {
  int i;
  int length = 0;
  char *str;
  char letter_num = 0;
  str = malloc(calculateRequiredMemory(lineCount));
  str[0] = 0;
  for (i = 0; i < lineCount; i++) {
    str[length] = 'a' + letter_num % 26;
    letter_num++;
    if (length != 0)
      strncpy(str + length + 1, str, length * sizeof(char));
    length = length * 2 + 1;
    str[length] = 0;
    printf("%s\n", str);
  }
}


x86 assembly (clang, -O0):
<generateString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <calculateRequiredMemory@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1207 <generateString+0xc7>
movsbl -0x19(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d1 <generateString+0x91>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1177 <generateString+0x37>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
call   1040 <calculateRequiredMemory@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
movb   $0x0,(%rax)
test   %r15d,%r15d
jle    11d5 <generateString+0x95>
mov    %rax,%r12
xor    %ebp,%ebp
lea    0xe95(%rip),%r14
xor    %ebx,%ebx
jmp    118f <generateString+0x4f>
nop
add    %ebx,%ebx
movslq %ebx,%rbx
movb   $0x0,0x1(%r12,%rbx,1)
or     $0x1,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
cmp    %ebp,%r15d
je     11d5 <generateString+0x95>
movsbl %bpl,%eax
imul   $0x4f,%eax,%eax
movzwl %ax,%eax
movswl %ax,%ecx
shr    $0xf,%eax
shr    $0xb,%ecx
add    %al,%cl
movzbl %cl,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
mov    %ebp,%eax
sub    %cl,%al
add    $0x61,%al
movslq %ebx,%rdx
mov    %al,(%r12,%rdx,1)
add    $0x1,%ebp
test   %edx,%edx
je     1170 <generateString+0x30>
lea    (%r12,%rdx,1),%rdi
add    $0x1,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
jmp    1170 <generateString+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @generateString(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %4
store i8 0, i8* %6
%7 = load i32, i32* %2
%8 = call i32 @calculateRequiredMemory(i32 %7)
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
store i32 0, i32* %3
br label %12
12: ; preds = %52, %1
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %55
16: ; preds = %12
%17 = load i8, i8* %6
%18 = sext i8 %17 to i32
%19 = srem i32 %18, 26
%20 = add nsw i32 97, %19
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %5
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i8, i8* %6
%27 = add i8 %26, 1
store i8 %27, i8* %6
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %16
%31 = load i8*, i8** %5
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8*, i8** %5
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = call i32 @strncpy(i8* %35, i8* %36, i32 %40)
br label %42
42: ; preds = %30, %16
%43 = load i32, i32* %4
%44 = mul nsw i32 %43, 2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
%46 = load i8*, i8** %5
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %5
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %42
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %12
55: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @generateString(i32 %0) {
%2 = tail call i32 @calculateRequiredMemory(i32 %0)
%3 = tail call i8* @malloc(i32 %2)
store i8 0, i8* %3
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %25
5: ; preds = %1, %18
%6 = phi i32 [ %13, %18 ], [ 0, %1 ]
%7 = phi i32 [ %20, %18 ], [ 0, %1 ]
%8 = trunc i32 %6 to i8
%9 = srem i8 %8, 26
%10 = add nsw i8 %9, 97
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i8, i8* %3, i64 %11
store i8 %10, i8* %12
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %7, 0
br i1 %14, label %18, label %15
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %12, i64 1
%17 = tail call i32 @strncpy(i8* %16, i8* %3, i32 %7)
br label %18
18: ; preds = %15, %5
%19 = shl nsw i32 %7, 1
%20 = or i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %3, i64 %21
store i8 0, i8* %22
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
%24 = icmp eq i32 %13, %0
br i1 %24, label %25, label %5
25: ; preds = %18, %1
ret void
}