#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 pmm_benchmark {
  int dummy;
};

/* Variables and functions */
struct pmm_benchmark *get_next_different_bench(struct pmm_benchmark *);
int count_unique_benchmarks_in_sorted_list(struct pmm_benchmark *first) {
  int count;
  struct pmm_benchmark *b;
  count = 0;
  b = first;
  while (b != NULL) {
    count++;
    b = get_next_different_bench(b);
  }
  return count;
}


x86 assembly (clang, -O0):
<count_unique_benchmarks_in_sorted_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1151 <count_unique_benchmarks_in_sorted_list+0x41>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <get_next_different_bench@plt>
mov    %rax,-0x18(%rbp)
jmp    112b <count_unique_benchmarks_in_sorted_list+0x1b>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_unique_benchmarks_in_sorted_list>:
push   %rbx
test   %rdi,%rdi
je     1132 <count_unique_benchmarks_in_sorted_list+0x22>
mov    %rdi,%rax
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %rax,%rdi
call   1030 <get_next_different_bench@plt>
test   %rax,%rax
jne    1120 <count_unique_benchmarks_in_sorted_list+0x10>
jmp    1134 <count_unique_benchmarks_in_sorted_list+0x24>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.pmm_benchmark = type { i32 }
define i32 @count_unique_benchmarks_in_sorted_list(%struct.pmm_benchmark* %0) {
%2 = alloca %struct.pmm_benchmark*
%3 = alloca i32
%4 = alloca %struct.pmm_benchmark*
store %struct.pmm_benchmark* %0, %struct.pmm_benchmark** %2
store i32 0, i32* %3
%5 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %2
store %struct.pmm_benchmark* %5, %struct.pmm_benchmark** %4
br label %6
6: ; preds = %9, %1
%7 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %4
%8 = icmp ne %struct.pmm_benchmark* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
%12 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %4
%13 = call %struct.pmm_benchmark* @get_next_different_bench(%struct.pmm_benchmark* %12)
store %struct.pmm_benchmark* %13, %struct.pmm_benchmark** %4
br label %6
14: ; preds = %6
%15 = load i32, i32* %3
ret i32 %15
}

LLVM IR (-O2):
%struct.pmm_benchmark = type { i32 }
define i32 @count_unique_benchmarks_in_sorted_list(%struct.pmm_benchmark* %0) {
%2 = icmp eq %struct.pmm_benchmark* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1, %3
%4 = phi %struct.pmm_benchmark* [ %7, %3 ], [ %0, %1 ]
%5 = phi i32 [ %6, %3 ], [ 0, %1 ]
%6 = add nuw nsw i32 %5, 1
%7 = tail call %struct.pmm_benchmark* @get_next_different_bench(%struct.pmm_benchmark* %4)
%8 = icmp eq %struct.pmm_benchmark* %7, null
br i1 %8, label %9, label %3
9: ; preds = %3, %1
%10 = phi i32 [ 0, %1 ], [ %6, %3 ]
ret i32 %10
}