#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 */
char *strchr(char const *, char);
int getbits(const char *src, int *bitsp) {
  static const char digits[] = "0123456789";
  int n;
  int val;
  char ch;
  val = 0;
  n = 0;
  while ((ch = *src++) != '\0') {
    const char *pch;
    pch = strchr(digits, ch);
    if (pch != NULL) {
      if (n++ != 0 && val == 0)
        return (0);
      val *= 10;
      val += (pch - digits);
      if (val > 128)
        return (0);
      continue;
    }
    return (0);
  }
  if (n == 0)
    return (0);
  *bitsp = val;
  return (1);
}


x86 assembly (clang, -O0):
<getbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11e0 <getbits+0xd0>
lea    0xeab(%rip),%rdi
movsbl -0x21(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11d4 <getbits+0xc4>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1197 <getbits+0x87>
cmpl   $0x0,-0x20(%rbp)
jne    1197 <getbits+0x87>
movl   $0x0,-0x4(%rbp)
jmp    1206 <getbits+0xf6>
imul   $0xa,-0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rcx
lea    0xe57(%rip),%rax
sub    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x80,-0x20(%rbp)
jle    11cf <getbits+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    1206 <getbits+0xf6>
jmp    112e <getbits+0x1e>
movl   $0x0,-0x4(%rbp)
jmp    1206 <getbits+0xf6>
cmpl   $0x0,-0x1c(%rbp)
jne    11f6 <getbits+0xe6>
movl   $0x0,-0x4(%rbp)
jmp    1206 <getbits+0xf6>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbits>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xed8(%rip),%r15
xor    %r13d,%r13d
jmp    1149 <getbits+0x39>
nopl   (%rax)
lea    0x0(%r13,%r13,4),%edx
sub    %r15d,%ecx
lea    (%rcx,%rdx,2),%r13d
add    $0x1,%rbx
cmp    $0x81,%r13d
jge    1182 <getbits+0x72>
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     1172 <getbits+0x62>
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1182 <getbits+0x72>
test   %ebx,%ebx
je     1130 <getbits+0x20>
test   %r13d,%r13d
jne    1130 <getbits+0x20>
jmp    1182 <getbits+0x72>
test   %ebx,%ebx
je     1180 <getbits+0x70>
mov    %r13d,(%r14)
mov    $0x1,%eax
jmp    1182 <getbits+0x72>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@getbits.digits = internal constant [11 x i8] c"0123456789\00"
define i32 @getbits(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %7
store i32 0, i32* %6
br label %10
10: ; preds = %42, %2
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %4
%13 = load i8, i8* %11
store i8 %13, i8* %8
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %44
16: ; preds = %10
%17 = load i8, i8* %8
%18 = call i8* @strchr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @getbits.digits, i64 0, i64 0), i8 signext %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %43
21: ; preds = %16
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = icmp ne i32 %22, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %3
br label %51
29: ; preds = %25, %21
%30 = load i32, i32* %7
%31 = mul nsw i32 %30, 10
store i32 %31, i32* %7
%32 = load i8*, i8** %9
%33 = ptrtoint i8* %32 to i64
%34 = sub i64 %33, ptrtoint ([11 x i8]* @getbits.digits to i64)
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp sgt i32 %39, 128
br i1 %40, label %41, label %42
41: ; preds = %29
store i32 0, i32* %3
br label %51
42: ; preds = %29
br label %10
43: ; preds = %16
store i32 0, i32* %3
br label %51
44: ; preds = %10
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 0, i32* %3
br label %51
48: ; preds = %44
%49 = load i32, i32* %7
%50 = load i32*, i32** %5
store i32 %49, i32* %50
store i32 1, i32* %3
br label %51
51: ; preds = %48, %47, %43, %41, %28
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@getbits.digits = internal constant [11 x i8] c"0123456789\00"
define i32 @getbits(i8* nocapture %0, i32* nocapture writeonly %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i32 [ 0, %2 ], [ %18, %17 ]
%5 = phi i32 [ 0, %2 ], [ %23, %17 ]
%6 = phi i8* [ %0, %2 ], [ %7, %17 ]
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %3
%11 = tail call i8* @strchr(i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @getbits.digits, i64 0, i64 0), i8 signext %8)
%12 = icmp eq i8* %11, null
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = icmp ne i32 %4, 0
%15 = icmp eq i32 %5, 0
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %28, label %17
17: ; preds = %13
%18 = add nuw nsw i32 %4, 1
%19 = mul nsw i32 %5, 10
%20 = ptrtoint i8* %11 to i64
%21 = trunc i64 %20 to i32
%22 = sub i32 %21, ptrtoint ([11 x i8]* @getbits.digits to i32)
%23 = add i32 %22, %19
%24 = icmp slt i32 %23, 129
br i1 %24, label %3, label %28
25: ; preds = %3
%26 = icmp eq i32 %4, 0
br i1 %26, label %28, label %27
27: ; preds = %25
store i32 %5, i32* %1
br label %28
28: ; preds = %10, %13, %17, %25, %27
%29 = phi i32 [ 1, %27 ], [ 0, %25 ], [ 0, %17 ], [ 0, %13 ], [ 0, %10 ]
ret i32 %29
}