#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
int is_valid_const(const char *c) {
  const char *p;
  char ch;
  assert(c != NULL);
  for (p = c; (ch = *p); p++)
    if (ch != '0' && ch != '1')
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_const>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
cmp    $0x0,%al
je     1183 <is_valid_const+0x73>
movsbl -0x19(%rbp),%eax
cmp    $0x30,%eax
je     116d <is_valid_const+0x5d>
movsbl -0x19(%rbp),%eax
cmp    $0x31,%eax
je     116d <is_valid_const+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    118a <is_valid_const+0x7a>
jmp    1172 <is_valid_const+0x62>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1136 <is_valid_const+0x26>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_const>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    (%rbx),%cl
mov    $0x1,%eax
test   %cl,%cl
je     1153 <is_valid_const+0x43>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
and    $0xfe,%cl
cmp    $0x30,%cl
jne    1155 <is_valid_const+0x45>
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1140 <is_valid_const+0x30>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @is_valid_const(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
store i8* %10, i8** %4
br label %11
11: ; preds = %25, %1
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8, i8* %5
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 48
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 49
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %2
br label %29
24: ; preds = %19, %15
br label %25
25: ; preds = %24
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %11
28: ; preds = %11
store i32 1, i32* %2
br label %29
29: ; preds = %28, %23
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @is_valid_const(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %16, label %10
7: ; preds = %10
%8 = load i8, i8* %15
%9 = icmp eq i8 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %1, %7
%11 = phi i8 [ %8, %7 ], [ %5, %1 ]
%12 = phi i8* [ %15, %7 ], [ %0, %1 ]
%13 = and i8 %11, -2
%14 = icmp eq i8 %13, 48
%15 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %14, label %7, label %16
16: ; preds = %10, %7, %1
%17 = phi i32 [ 1, %1 ], [ 1, %7 ], [ 0, %10 ]
ret i32 %17
}