#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);
int nibble_from_string(char *);
int /*<<< orphan*/ printf(char *, int, char *, int const);
int /*<<< orphan*/ to_bin_naive(int, char *);
void verify() {
  char buf[5];
  for (int x = 0; x < 16; x++) {
    to_bin_naive(x, buf);
    const int parsed = nibble_from_string(buf);
    printf("%d => '%s' => %d\n", x, buf, parsed);
    assert(x == parsed);
  }
  buf[0] = '?';
  assert(nibble_from_string(buf) < 0);
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    11a8 <verify+0x68>
mov    -0xc(%rbp),%edi
lea    -0x5(%rbp),%rsi
call   1060 <to_bin_naive@plt>
lea    -0x5(%rbp),%rdi
call   1030 <nibble_from_string@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
lea    -0x5(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <verify+0xf>
movb   $0x3f,-0x5(%rbp)
lea    -0x5(%rbp),%rdi
call   1030 <nibble_from_string@plt>
cmp    $0x0,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
lea    0x3(%rsp),%r14
lea    0xeab(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <to_bin_naive@plt>
mov    %r14,%rdi
call   1030 <nibble_from_string@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %edi,%edi
cmp    %ebp,%ebx
sete   %dil
call   1050 <assert@plt>
add    $0x1,%ebx
cmp    $0x10,%ebx
jne    1160 <verify+0x20>
movb   $0x3f,0x3(%rsp)
lea    0x3(%rsp),%rdi
call   1030 <nibble_from_string@plt>
shr    $0x1f,%eax
mov    %eax,%edi
call   1050 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%d => '%s' => %d\0A\00"
define void @verify() {
%1 = alloca [5 x i8]
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
br label %4
4: ; preds = %22, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 16
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = load i32, i32* %2
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%10 = call i32 @to_bin_naive(i32 %8, i8* %9)
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%12 = call i32 @nibble_from_string(i8* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %14, i32 %15)
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = icmp eq i32 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
br label %22
22: ; preds = %7
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %4
25: ; preds = %4
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
store i8 63, i8* %26
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%28 = call i32 @nibble_from_string(i8* %27)
%29 = icmp slt i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"%d => '%s' => %d\0A\00"
define void @verify() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
br label %7
3: ; preds = %7
store i8 63, i8* %2
%4 = call i32 @nibble_from_string(i8* %2)
%5 = lshr i32 %4, 31
%6 = call i32 @assert(i32 %5)
ret void
7: ; preds = %0, %7
%8 = phi i32 [ 0, %0 ], [ %15, %7 ]
%9 = call i32 @to_bin_naive(i32 %8, i8* %2)
%10 = call i32 @nibble_from_string(i8* %2)
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %2, i32 %10)
%12 = icmp eq i32 %8, %10
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, 16
br i1 %16, label %3, label %7
}