#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 */
scalar_t__ isdigit(int);
char toupper(int);
int isdigit_b(int ch, int base) {
  if (isdigit(ch))
    return 1;
  if (base > 10) {
    ch = toupper(ch) - 'A';
    if (ch >= 0 && ch < (base - 10))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<isdigit_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     114c <isdigit_b+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    119a <isdigit_b+0x7a>
cmpl   $0xa,-0xc(%rbp)
jle    1193 <isdigit_b+0x73>
mov    -0x8(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     118e <isdigit_b+0x6e>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0xa,%ecx
cmp    %ecx,%eax
jge    118e <isdigit_b+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    119a <isdigit_b+0x7a>
jmp    1193 <isdigit_b+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isdigit_b>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
call   1030 <isdigit@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1156 <isdigit_b+0x36>
cmp    $0xb,%r14d
jl     1154 <isdigit_b+0x34>
mov    %ebp,%edi
call   1040 <toupper@plt>
cmp    $0x41,%al
jl     1154 <isdigit_b+0x34>
movzbl %al,%eax
add    $0xffffffc9,%eax
cmp    %r14d,%eax
jb     1156 <isdigit_b+0x36>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isdigit_b(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = call i64 @isdigit(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %28
10: ; preds = %2
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 10
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i32, i32* %4
%15 = call signext i8 @toupper(i32 %14)
%16 = sext i8 %15 to i32
%17 = sub nsw i32 %16, 65
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 10
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %3
br label %28
26: ; preds = %20, %13
br label %27
27: ; preds = %26, %10
store i32 0, i32* %3
br label %28
28: ; preds = %27, %25, %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @isdigit_b(i32 %0, i32 %1) {
%3 = tail call i64 @isdigit(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = icmp sgt i32 %1, 10
br i1 %6, label %7, label %14
7: ; preds = %5
%8 = tail call signext i8 @toupper(i32 %0)
%9 = icmp sgt i8 %8, 64
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = zext i8 %8 to i32
%12 = add nsw i32 %11, -55
%13 = icmp ult i32 %12, %1
br i1 %13, label %15, label %14
14: ; preds = %7, %10, %5
br label %15
15: ; preds = %10, %2, %14
%16 = phi i32 [ 0, %14 ], [ 1, %2 ], [ 1, %10 ]
ret i32 %16
}