#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 */
void *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, size_t);
char **ht_create_n_elements(size_t n) {
  char **elements = malloc((sizeof(char *) * n));
  size_t i;
  for (i = 0; i < n; i++) {
    elements[i] = malloc((sizeof(char) * 10));
    sprintf(elements[i], "%zu", i);
  }
  return elements;
}


x86 assembly (clang, -O0):
<ht_create_n_elements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    119b <ht_create_n_elements+0x7b>
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1147 <ht_create_n_elements+0x27>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ht_create_n_elements>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x0(,%rdi,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %r14,%r14
je     1175 <ht_create_n_elements+0x55>
xor    %ebx,%ebx
lea    0xeb8(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <ht_create_n_elements+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%zu\00"
define i8** @ht_create_n_elements(i64 %0) {
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = mul i64 8, %5
%7 = trunc i64 %6 to i32
%8 = call i8* @malloc(i32 %7)
%9 = bitcast i8* %8 to i8**
store i8** %9, i8*** %3
store i64 0, i64* %4
br label %10
10: ; preds = %25, %1
%11 = load i64, i64* %4
%12 = load i64, i64* %2
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = call i8* @malloc(i32 10)
%16 = load i8**, i8*** %3
%17 = load i64, i64* %4
%18 = getelementptr inbounds i8*, i8** %16, i64 %17
store i8* %15, i8** %18
%19 = load i8**, i8*** %3
%20 = load i64, i64* %4
%21 = getelementptr inbounds i8*, i8** %19, i64 %20
%22 = load i8*, i8** %21
%23 = load i64, i64* %4
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %14
%26 = load i64, i64* %4
%27 = add i64 %26, 1
store i64 %27, i64* %4
br label %10
28: ; preds = %10
%29 = load i8**, i8*** %3
ret i8** %29
}

LLVM IR (-O2):
@.str = [4 x i8] c"%zu\00"
define noalias i8** @ht_create_n_elements(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = shl i32 %2, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8* %4 to i8**
%6 = icmp eq i64 %0, 0
br i1 %6, label %14, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %12, %7 ], [ 0, %1 ]
%9 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%10 = getelementptr inbounds i8*, i8** %5, i64 %8
store i8* %9, i8** %10
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %8)
%12 = add nuw i64 %8, 1
%13 = icmp eq i64 %12, %0
br i1 %13, label %14, label %7
14: ; preds = %7, %1
ret i8** %5
}