#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 *hash_table(int);
int /*<<< orphan*/ hash_table_add(void *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void *populate(int init, int num) {
  char *k, *v;
  void *ht = hash_table(init);
  for (int i = 0; i < num; i++) {
    k = (char *)malloc(9);
    sprintf(k, "string%d", i);
    v = (char *)malloc(9);
    sprintf(v, "STRING%d", i);
    hash_table_add(ht, k, v);
  }
  return ht;
}


x86 assembly (clang, -O0):
<populate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <hash_table@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ce <populate+0x8e>
mov    $0x9,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe77(%rip),%rsi
call   1060 <sprintf@plt>
mov    $0x9,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe5f(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <hash_table_add@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <populate+0x21>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<populate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
call   1030 <hash_table@plt>
mov    %rax,%r13
test   %r14d,%r14d
jle    11be <populate+0x7e>
xor    %ebp,%ebp
lea    0xea5(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x9,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xe79(%rip),%rsi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    $0x9,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <hash_table_add@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1170 <populate+0x30>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"string%d\00"
@.str.1 = [9 x i8] c"STRING%d\00"
define i8* @populate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %3
%10 = call i8* @hash_table(i32 %9)
store i8* %10, i8** %7
store i32 0, i32* %8
br label %11
11: ; preds = %30, %2
%12 = load i32, i32* %8
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = call i64 @malloc(i32 9)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i64 @malloc(i32 9)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = load i32, i32* %8
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %7
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = call i32 @hash_table_add(i8* %26, i8* %27, i8* %28)
br label %30
30: ; preds = %15
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %11
33: ; preds = %11
%34 = load i8*, i8** %7
ret i8* %34
}

LLVM IR (-O2):
@.str = [9 x i8] c"string%d\00"
@.str.1 = [9 x i8] c"STRING%d\00"
define i8* @populate(i32 %0, i32 %1) {
%3 = tail call i8* @hash_table(i32 %0)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %6, label %5
5: ; preds = %6, %2
ret i8* %3
6: ; preds = %2, %6
%7 = phi i32 [ %15, %6 ], [ 0, %2 ]
%8 = tail call i64 @malloc(i32 9)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
%11 = tail call i64 @malloc(i32 9)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%14 = tail call i32 @hash_table_add(i8* %3, i8* %9, i8* %12)
%15 = add nuw nsw i32 %7, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %5, label %6
}