#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char *str;
  str = (char *)calloc(10, sizeof(char));
  for (short i = 0; i < 10; i++) {
    str[i] = 97 + i;
  }
  printf("%s\n", str);
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
movswl -0x12(%rbp),%eax
cmp    $0xa,%eax
jge    118b <main+0x5b>
movswl -0x12(%rbp),%eax
add    $0x61,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movswq -0x12(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
jmp    1158 <main+0x28>
mov    -0x10(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
movabs $0x6867666564636261,%rax
66 67 68
mov    %rax,(%rbx)
movw   $0x6a69,0x8(%rbx)
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = tail call i64 @calloc(i32 10, i32 1)
%2 = inttoptr i64 %1 to i8*
store i8 97, i8* %2
%3 = getelementptr inbounds i8, i8* %2, i64 1
store i8 98, i8* %3
%4 = getelementptr inbounds i8, i8* %2, i64 2
store i8 99, i8* %4
%5 = getelementptr inbounds i8, i8* %2, i64 3
store i8 100, i8* %5
%6 = getelementptr inbounds i8, i8* %2, i64 4
store i8 101, i8* %6
%7 = getelementptr inbounds i8, i8* %2, i64 5
store i8 102, i8* %7
%8 = getelementptr inbounds i8, i8* %2, i64 6
store i8 103, i8* %8
%9 = getelementptr inbounds i8, i8* %2, i64 7
store i8 104, i8* %9
%10 = getelementptr inbounds i8, i8* %2, i64 8
store i8 105, i8* %10
%11 = getelementptr inbounds i8, i8* %2, i64 9
store i8 106, i8* %11
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%13 = tail call i32 @free(i8* %2)
ret i32 0
}