#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 */
struct hash_table {
  int dummy;
};
struct hash_entry {
  int dummy;
};

/* Variables and functions */
struct hash_entry *next_hash_entry(struct hash_table *);
int /*<<< orphan*/ reset_hash_iterator(struct hash_table *);
void count_hash(struct hash_table *hash, unsigned int *total,
                unsigned int *max_val) {
  int counter = 0;
  struct hash_entry *fh;
  reset_hash_iterator(hash);
  while ((fh = next_hash_entry(hash)))
    counter++;
  *total += counter;
  *max_val = ((*max_val) > (counter) ? (*max_val) : (counter));
}


x86 assembly (clang, -O0):
<count_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <reset_hash_iterator@plt>
mov    -0x8(%rbp),%rdi
call   1040 <next_hash_entry@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1169 <count_hash+0x49>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1144 <count_hash+0x24>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jbe    1191 <count_hash+0x71>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1197 <count_hash+0x77>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_hash>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <reset_hash_iterator@plt>
mov    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <next_hash_entry@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1140 <count_hash+0x20>
add    %ebp,(%r14)
mov    (%r15),%eax
cmp    %ebp,%eax
cmova  %eax,%ebp
mov    %ebp,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hash_table = type { i32 }
%struct.hash_entry = type { i32 }
define void @count_hash(%struct.hash_table* %0, i32* %1, i32* %2) {
%4 = alloca %struct.hash_table*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.hash_entry*
store %struct.hash_table* %0, %struct.hash_table** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%9 = load %struct.hash_table*, %struct.hash_table** %4
%10 = call i32 @reset_hash_iterator(%struct.hash_table* %9)
br label %11
11: ; preds = %15, %3
%12 = load %struct.hash_table*, %struct.hash_table** %4
%13 = call %struct.hash_entry* @next_hash_entry(%struct.hash_table* %12)
store %struct.hash_entry* %13, %struct.hash_entry** %8
%14 = icmp ne %struct.hash_entry* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
br label %11
18: ; preds = %11
%19 = load i32, i32* %7
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = add i32 %21, %19
store i32 %22, i32* %20
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = load i32, i32* %7
%26 = icmp ugt i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %18
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
br label %32
30: ; preds = %18
%31 = load i32, i32* %7
br label %32
32: ; preds = %30, %27
%33 = phi i32 [ %29, %27 ], [ %31, %30 ]
%34 = load i32*, i32** %6
store i32 %33, i32* %34
ret void
}

LLVM IR (-O2):
%struct.hash_table = type { i32 }
%struct.hash_entry = type { i32 }
define void @count_hash(%struct.hash_table* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = tail call i32 @reset_hash_iterator(%struct.hash_table* %0)
br label %5
5: ; preds = %5, %3
%6 = phi i32 [ 0, %3 ], [ %9, %5 ]
%7 = tail call %struct.hash_entry* @next_hash_entry(%struct.hash_table* %0)
%8 = icmp eq %struct.hash_entry* %7, null
%9 = add nuw nsw i32 %6, 1
br i1 %8, label %10, label %5
10: ; preds = %5
%11 = load i32, i32* %1
%12 = add i32 %11, %6
store i32 %12, i32* %1
%13 = load i32, i32* %2
%14 = icmp ugt i32 %13, %6
%15 = select i1 %14, i32 %13, i32 %6
store i32 %15, i32* %2
ret void
}