#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 m_count_canna_mode(int);
int m_get_canna_mode(int, int);
int m_count_valid_canna_mode(int mode) {
  int ret = 0;
  int i, max, cmode;
  max = m_count_canna_mode(mode);
  for (i = 0; i < max; i++) {
    cmode = m_get_canna_mode(mode, i);
    if (cmode == 1 || cmode == 3)
      ret++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<m_count_valid_canna_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <m_count_canna_mode@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118e <m_count_valid_canna_mode+0x6e>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <m_get_canna_mode@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     1172 <m_count_valid_canna_mode+0x52>
cmpl   $0x3,-0x14(%rbp)
jne    117b <m_count_valid_canna_mode+0x5b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1180 <m_count_valid_canna_mode+0x60>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <m_count_valid_canna_mode+0x24>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_count_valid_canna_mode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1040 <m_count_canna_mode@plt>
test   %eax,%eax
jle    1161 <m_count_valid_canna_mode+0x41>
mov    %eax,%r15d
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <m_get_canna_mode@plt>
and    $0xfffffffd,%eax
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%ebp
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    1140 <m_count_valid_canna_mode+0x20>
jmp    1163 <m_count_valid_canna_mode+0x43>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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