#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 unsigned long long uint64_t;

/* Variables and functions */
scalar_t__ isdigit(char);
uint64_t str2bin(char **in, int *err) {
  uint64_t rt = 0;
  *err = 1;
  while (isdigit(**in)) {
    if (rt > (-1ULL / 2)) {
      *err = 1;
      break;
    }
    if (**in == '0' || **in == '1') {
      *err = 0;
      rt = (rt << 1) | (**in - '0');
    } else {
      *err = 1;
      break;
    }
    *in += 1;
  }
  return rt;
}


x86 assembly (clang, -O0):
<str2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e4 <str2bin+0xd4>
movabs $0x7fffffffffffffff,%rax
ff ff 7f
cmp    %rax,-0x18(%rbp)
jbe    116e <str2bin+0x5e>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11e4 <str2bin+0xd4>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     1194 <str2bin+0x84>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    11c2 <str2bin+0xb2>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11d1 <str2bin+0xc1>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11e4 <str2bin+0xd4>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1132 <str2bin+0x22>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2bin>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x1,(%rsi)
mov    (%rdi),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1186 <str2bin+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rbx,%rbx
js     117f <str2bin+0x6f>
mov    (%r15),%rax
movzbl (%rax),%ecx
and    $0xfe,%cl
cmp    $0x30,%cl
jne    117f <str2bin+0x6f>
movl   $0x0,(%r14)
add    %rbx,%rbx
movsbq (%rax),%rcx
add    $0xffffffffffffffd0,%rcx
or     %rcx,%rbx
lea    0x1(%rax),%rcx
mov    %rcx,(%r15)
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <str2bin+0x30>
jmp    1186 <str2bin+0x76>
movl   $0x1,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @str2bin(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i64
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i64 0, i64* %5
%6 = load i32*, i32** %4
store i32 1, i32* %6
br label %7
7: ; preds = %43, %2
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = call i64 @isdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %47
13: ; preds = %7
%14 = load i64, i64* %5
%15 = icmp ugt i64 %14, 9223372036854775807
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = load i32*, i32** %4
store i32 1, i32* %17
br label %47
18: ; preds = %13
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 48
br i1 %23, label %30, label %24
24: ; preds = %18
%25 = load i8**, i8*** %3
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 49
br i1 %29, label %30, label %41
30: ; preds = %24, %18
%31 = load i32*, i32** %4
store i32 0, i32* %31
%32 = load i64, i64* %5
%33 = shl i64 %32, 1
%34 = load i8**, i8*** %3
%35 = load i8*, i8** %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 48
%39 = sext i32 %38 to i64
%40 = or i64 %33, %39
store i64 %40, i64* %5
br label %43
41: ; preds = %24
%42 = load i32*, i32** %4
store i32 1, i32* %42
br label %47
43: ; preds = %30
%44 = load i8**, i8*** %3
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8* %46, i8** %44
br label %7
47: ; preds = %41, %16, %7
%48 = load i64, i64* %5
ret i64 %48
}

LLVM IR (-O2):
define i64 @str2bin(i8** nocapture %0, i32* nocapture writeonly %1) {
store i32 1, i32* %1
%3 = load i8*, i8** %0
%4 = load i8, i8* %3
%5 = tail call i64 @isdigit(i8 signext %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %2, %15
%8 = phi i64 [ %20, %15 ], [ 0, %2 ]
%9 = icmp slt i64 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = load i8*, i8** %0
%12 = load i8, i8* %11
%13 = and i8 %12, -2
%14 = icmp eq i8 %13, 48
br i1 %14, label %15, label %25
15: ; preds = %10
store i32 0, i32* %1
%16 = shl nuw i64 %8, 1
%17 = load i8, i8* %11
%18 = sext i8 %17 to i64
%19 = add nsw i64 %18, -48
%20 = or i64 %19, %16
%21 = getelementptr inbounds i8, i8* %11, i64 1
store i8* %21, i8** %0
%22 = load i8, i8* %21
%23 = tail call i64 @isdigit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %7
25: ; preds = %10, %7
store i32 1, i32* %1
br label %26
26: ; preds = %15, %25, %2
%27 = phi i64 [ 0, %2 ], [ %8, %25 ], [ %20, %15 ]
ret i64 %27
}