#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 find_first_matching_tune_bar(int, int, int);
int count_matched_template_bars(int tpbars, int inbars, int transpose) {
  int i, count, bar;
  count = 0;
  for (i = 0; i < tpbars; i++) {
    bar = find_first_matching_tune_bar(i, inbars, transpose);
    if (bar >= 0)
      count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<count_matched_template_bars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1172 <count_matched_template_bars+0x62>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <find_first_matching_tune_bar@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     115f <count_matched_template_bars+0x4f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <count_matched_template_bars+0x54>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112f <count_matched_template_bars+0x1f>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_matched_template_bars>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    114e <count_matched_template_bars+0x3e>
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <find_first_matching_tune_bar@plt>
not    %eax
shr    $0x1f,%eax
add    %eax,%ebp
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1130 <count_matched_template_bars+0x20>
jmp    1150 <count_matched_template_bars+0x40>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_matched_template_bars(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %10
10: ; preds = %25, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @find_first_matching_tune_bar(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %24
24: ; preds = %21, %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %10
28: ; preds = %10
%29 = load i32, i32* %8
ret i32 %29
}

LLVM IR (-O2):
define i32 @count_matched_template_bars(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %14
5: ; preds = %3, %5
%6 = phi i32 [ %12, %5 ], [ 0, %3 ]
%7 = phi i32 [ %11, %5 ], [ 0, %3 ]
%8 = tail call i32 @find_first_matching_tune_bar(i32 %6, i32 %1, i32 %2)
%9 = xor i32 %8, -1
%10 = lshr i32 %9, 31
%11 = add nuw nsw i32 %10, %7
%12 = add nuw nsw i32 %6, 1
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %5
14: ; preds = %5, %3
%15 = phi i32 [ 0, %3 ], [ %11, %5 ]
ret i32 %15
}