void count(char *s, int *ret_p) {
  switch (*s) {
  case '\0':
    ++*ret_p;
    return;
  case '0':
    return;
  case '1':
    if (s[1])
      count(s + 2, ret_p);
    break;
  case '2':
    if (s[1] >= '0' && s[1] <= '6')
      count(s + 2, ret_p);
    break;
  }
  count(s + 1, ret_p);
}


x86 assembly (clang, -O0):
<count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     116a <count+0x5a>
jmp    1137 <count+0x27>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
je     117a <count+0x6a>
jmp    1148 <count+0x38>
mov    -0x14(%rbp),%eax
sub    $0x31,%eax
je     117f <count+0x6f>
jmp    1159 <count+0x49>
mov    -0x14(%rbp),%eax
sub    $0x32,%eax
je     11a3 <count+0x93>
jmp    11db <count+0xcb>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11ec <count+0xdc>
jmp    11ec <count+0xdc>
mov    -0x8(%rbp),%rax
cmpb   $0x0,0x1(%rax)
je     119e <count+0x8e>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <count@plt>
jmp    11db <count+0xcb>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x30,%eax
jl     11d6 <count+0xc6>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x36,%eax
jg     11d6 <count+0xc6>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <count@plt>
jmp    11db <count+0xcb>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <count@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x2,%rbx
jmp    112f <count+0x1f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <count@plt>
add    $0x1,%rbx
movsbl -0x2(%rbx),%eax
cmp    $0x31,%eax
jg     1150 <count+0x40>
jne    1161 <count+0x51>
cmpb   $0x0,-0x1(%rbx)
jne    1120 <count+0x10>
jmp    112b <count+0x1b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x32,%eax
jne    112b <count+0x1b>
movzbl -0x1(%rbx),%eax
add    $0xd0,%al
cmp    $0x6,%al
jbe    1120 <count+0x10>
jmp    112b <count+0x1b>
test   %eax,%eax
je     116c <count+0x5c>
cmp    $0x30,%eax
jne    112b <count+0x1b>
jmp    1170 <count+0x60>
addl   $0x1,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @count(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %40 [
i32 0, label %8
i32 48, label %12
i32 49, label %13
i32 50, label %23
]
8: ; preds = %2
%9 = load i32*, i32** %4
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
store i32 %11, i32* %9
br label %44
12: ; preds = %2
br label %44
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i32*, i32** %4
br label %22
22: ; preds = %18, %13
br label %40
23: ; preds = %2
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %39
29: ; preds = %23
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sle i32 %33, 54
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i32*, i32** %4
br label %39
39: ; preds = %35, %29, %23
br label %40
40: ; preds = %2, %39, %22
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i32*, i32** %4
br label %44
44: ; preds = %40, %12, %8
ret void
}

LLVM IR (-O2):
define void @count(i8* %0, i32* %1) {
br label %3
3: ; preds = %21, %2
%4 = phi i8* [ %0, %2 ], [ %22, %21 ]
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %21 [
i32 0, label %7
i32 48, label %23
i32 49, label %10
i32 50, label %14
]
7: ; preds = %3
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
br label %23
10: ; preds = %3
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %21, label %19
14: ; preds = %3
%15 = getelementptr inbounds i8, i8* %4, i64 1
%16 = load i8, i8* %15
%17 = add i8 %16, -48
%18 = icmp ult i8 %17, 7
br i1 %18, label %19, label %21
19: ; preds = %14, %10
%20 = getelementptr inbounds i8, i8* %4, i64 2
tail call void @count(i8* %20, i32* %1)
br label %21
21: ; preds = %19, %14, %10, %3
%22 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
23: ; preds = %3, %7
ret void
}