#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*/ clxns_free(void *, int /*<<< orphan*/);
int /*<<< orphan*/ clxns_iter_free(void *);
int /*<<< orphan*/ clxns_iter_get_next(void *);
scalar_t__ clxns_iter_move_next(void *);
void *clxns_iter_new(void *);
void *hash_table(int /*<<< orphan*/);
int /*<<< orphan*/ hash_table_add(void *, char *, char *);
char *ht_iterate_sparse_ish() {
  void *ht = hash_table(0);
  hash_table_add(ht, "AAA", "aaa");
  hash_table_add(ht, "BBB", "bbb");
  hash_table_add(ht, "XXX", "xxx");
  hash_table_add(ht, "GGG", "ggg");
  hash_table_add(ht, "QQQ", "qqq");
  int i = 0;
  void *iter = clxns_iter_new(ht);
  while (clxns_iter_move_next(iter)) {
    clxns_iter_get_next(iter);
    i++;
  }
  do {
    if (!(i == 5))
      return "Incorrect iter count for sparse-ish table";
  } while (0);
  clxns_iter_free(iter);
  clxns_free(ht, 0);
  return 0;
}


x86 assembly (clang, -O0):
<ht_iterate_sparse_ish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
call   1030 <hash_table@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    0xe6f(%rip),%rdx
call   1090 <hash_table_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
lea    0xe60(%rip),%rdx
call   1090 <hash_table_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
lea    0xe51(%rip),%rdx
call   1090 <hash_table_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
lea    0xe42(%rip),%rdx
call   1090 <hash_table_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe36(%rip),%rsi
lea    0xe33(%rip),%rdx
call   1090 <hash_table_add@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <clxns_iter_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <clxns_iter_move_next@plt>
cmp    $0x0,%rax
je     1234 <ht_iterate_sparse_ish+0xc4>
mov    -0x20(%rbp),%rdi
call   1080 <clxns_iter_get_next@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120a <ht_iterate_sparse_ish+0x9a>
jmp    1239 <ht_iterate_sparse_ish+0xc9>
cmpl   $0x5,-0x14(%rbp)
je     1253 <ht_iterate_sparse_ish+0xe3>
lea    0xdde(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1274 <ht_iterate_sparse_ish+0x104>
jmp    1258 <ht_iterate_sparse_ish+0xe8>
mov    -0x20(%rbp),%rdi
call   1050 <clxns_iter_free@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <clxns_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ht_iterate_sparse_ish>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <hash_table@plt>
mov    %rax,%r15
lea    0xe78(%rip),%rsi
lea    0xe75(%rip),%rdx
mov    %rax,%rdi
call   1090 <hash_table_add@plt>
lea    0xe6a(%rip),%rsi
lea    0xe67(%rip),%rdx
mov    %r15,%rdi
call   1090 <hash_table_add@plt>
lea    0xe5c(%rip),%rsi
lea    0xe59(%rip),%rdx
mov    %r15,%rdi
call   1090 <hash_table_add@plt>
lea    0xe4e(%rip),%rsi
lea    0xe4b(%rip),%rdx
mov    %r15,%rdi
call   1090 <hash_table_add@plt>
lea    0xe40(%rip),%rsi
lea    0xe3d(%rip),%rdx
mov    %r15,%rdi
call   1090 <hash_table_add@plt>
mov    %r15,%rdi
call   1040 <clxns_iter_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <clxns_iter_move_next@plt>
lea    0xe1f(%rip),%r14
test   %rax,%rax
je     1251 <ht_iterate_sparse_ish+0xe1>
mov    $0x5,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <clxns_iter_get_next@plt>
mov    %rbx,%rdi
call   1060 <clxns_iter_move_next@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1220 <ht_iterate_sparse_ish+0xb0>
test   %ebp,%ebp
jne    1251 <ht_iterate_sparse_ish+0xe1>
mov    %rbx,%rdi
call   1050 <clxns_iter_free@plt>
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <clxns_free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"AAA\00"
@.str.1 = [4 x i8] c"aaa\00"
@.str.2 = [4 x i8] c"BBB\00"
@.str.3 = [4 x i8] c"bbb\00"
@.str.4 = [4 x i8] c"XXX\00"
@.str.5 = [4 x i8] c"xxx\00"
@.str.6 = [4 x i8] c"GGG\00"
@.str.7 = [4 x i8] c"ggg\00"
@.str.8 = [4 x i8] c"QQQ\00"
@.str.9 = [4 x i8] c"qqq\00"
@.str.10 = [42 x i8] c"Incorrect iter count for sparse-ish table\00"
define i8* @ht_iterate_sparse_ish() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = call i8* @hash_table(i32 0)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @hash_table_add(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call i32 @hash_table_add(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%10 = load i8*, i8** %2
%11 = call i32 @hash_table_add(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%12 = load i8*, i8** %2
%13 = call i32 @hash_table_add(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @hash_table_add(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
%16 = load i8*, i8** %2
%17 = call i8* @clxns_iter_new(i8* %16)
store i8* %17, i8** %4
br label %18
18: ; preds = %22, %0
%19 = load i8*, i8** %4
%20 = call i64 @clxns_iter_move_next(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = call i32 @clxns_iter_get_next(i8* %23)
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %18
27: ; preds = %18
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 5
br i1 %30, label %32, label %31
31: ; preds = %28
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i8** %1
br label %38
32: ; preds = %28
br label %33
33: ; preds = %32
%34 = load i8*, i8** %4
%35 = call i32 @clxns_iter_free(i8* %34)
%36 = load i8*, i8** %2
%37 = call i32 @clxns_free(i8* %36, i32 0)
store i8* null, i8** %1
br label %38
38: ; preds = %33, %31
%39 = load i8*, i8** %1
ret i8* %39
}

LLVM IR (-O2):
@.str = [4 x i8] c"AAA\00"
@.str.1 = [4 x i8] c"aaa\00"
@.str.2 = [4 x i8] c"BBB\00"
@.str.3 = [4 x i8] c"bbb\00"
@.str.4 = [4 x i8] c"XXX\00"
@.str.5 = [4 x i8] c"xxx\00"
@.str.6 = [4 x i8] c"GGG\00"
@.str.7 = [4 x i8] c"ggg\00"
@.str.8 = [4 x i8] c"QQQ\00"
@.str.9 = [4 x i8] c"qqq\00"
@.str.10 = [42 x i8] c"Incorrect iter count for sparse-ish table\00"
define i8* @ht_iterate_sparse_ish() {
%1 = tail call i8* @hash_table(i32 0)
%2 = tail call i32 @hash_table_add(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @hash_table_add(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call i32 @hash_table_add(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%5 = tail call i32 @hash_table_add(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%6 = tail call i32 @hash_table_add(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%7 = tail call i8* @clxns_iter_new(i8* %1)
%8 = tail call i64 @clxns_iter_move_next(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %0, %10
%11 = phi i32 [ %13, %10 ], [ 0, %0 ]
%12 = tail call i32 @clxns_iter_get_next(i8* %7)
%13 = add nuw nsw i32 %11, 1
%14 = tail call i64 @clxns_iter_move_next(i8* %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %10
%17 = icmp eq i32 %13, 5
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = tail call i32 @clxns_iter_free(i8* %7)
%20 = tail call i32 @clxns_free(i8* %1, i32 0)
br label %21
21: ; preds = %0, %16, %18
%22 = phi i8* [ null, %18 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), %16 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), %0 ]
ret i8* %22
}