#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 */
typedef size_t uint32_t;
typedef int /*<<< orphan*/ transitions;

/* Variables and functions */
uint32_t count_words(const uint32_t *transitions, uint32_t pos) {
  uint32_t count = 0;
  if (!pos)
    return 0;
  do {
    if (((transitions[pos]) & 0x2))
      count++;
    count += count_words(
        transitions, (uint32_t)(((transitions[pos]) >> 10) & ((1 << 22) - 1)));
  } while (!((transitions[pos++]) & 0x1));
  return count;
}


x86 assembly (clang, -O0):
<count_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1140 <count_words+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11c7 <count_words+0xb7>
jmp    1145 <count_words+0x35>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     116b <count_words+0x5b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
shr    $0xa,%rsi
and    $0x3fffff,%rsi
call   1030 <count_words@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    (%rax,%rcx,8),%rax
and    $0x1,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1145 <count_words+0x35>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_words>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     115f <count_words+0x4f>
mov    %rdi,%r14
lea    (%rdi,%rsi,8),%r13
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%r12
mov    %r12d,%ebx
shr    %ebx
and    $0x1,%ebx
mov    %r12d,%esi
shr    $0xa,%esi
mov    %r14,%rdi
call   1030 <count_words@plt>
add    %r15,%rax
add    %rbx,%rax
add    $0x8,%r13
mov    %rax,%r15
test   $0x1,%r12b
je     1130 <count_words+0x20>
jmp    1161 <count_words+0x51>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @count_words(i64* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
store i64* %0, i64** %4
store i64 %1, i64* %5
store i64 0, i64* %6
%7 = load i64, i64* %5
%8 = icmp ne i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i64 0, i64* %3
br label %43
10: ; preds = %2
br label %11
11: ; preds = %32, %10
%12 = load i64*, i64** %4
%13 = load i64, i64* %5
%14 = getelementptr inbounds i64, i64* %12, i64 %13
%15 = load i64, i64* %14
%16 = and i64 %15, 2
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i64, i64* %6
%20 = add i64 %19, 1
store i64 %20, i64* %6
br label %21
21: ; preds = %18, %11
%22 = load i64*, i64** %4
%23 = load i64*, i64** %4
%24 = load i64, i64* %5
%25 = getelementptr inbounds i64, i64* %23, i64 %24
%26 = load i64, i64* %25
%27 = lshr i64 %26, 10
%28 = and i64 %27, 4194303
%29 = call i64 @count_words(i64* %22, i64 %28)
%30 = load i64, i64* %6
%31 = add i64 %30, %29
store i64 %31, i64* %6
br label %32
32: ; preds = %21
%33 = load i64*, i64** %4
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
%36 = getelementptr inbounds i64, i64* %33, i64 %34
%37 = load i64, i64* %36
%38 = and i64 %37, 1
%39 = icmp ne i64 %38, 0
%40 = xor i1 %39, true
br i1 %40, label %11, label %41
41: ; preds = %32
%42 = load i64, i64* %6
store i64 %42, i64* %3
br label %43
43: ; preds = %41, %9
%44 = load i64, i64* %3
ret i64 %44
}

LLVM IR (-O2):
define i64 @count_words(i64* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %16, %4 ], [ %1, %2 ]
%6 = phi i64 [ %15, %4 ], [ 0, %2 ]
%7 = getelementptr inbounds i64, i64* %0, i64 %5
%8 = load i64, i64* %7
%9 = lshr i64 %8, 1
%10 = and i64 %9, 1
%11 = lshr i64 %8, 10
%12 = and i64 %11, 4194303
%13 = tail call i64 @count_words(i64* %0, i64 %12)
%14 = add i64 %13, %6
%15 = add i64 %14, %10
%16 = add i64 %5, 1
%17 = and i64 %8, 1
%18 = icmp eq i64 %17, 0
br i1 %18, label %4, label %19
19: ; preds = %4, %2
%20 = phi i64 [ 0, %2 ], [ %15, %4 ]
ret i64 %20
}