#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__ toupper(char);
int valid_base_char(char digit, int base) {
  char *valid_digits = "0123456789ABCDEF";
  int i;
  for (i = 0; i < base; i++)
    if (toupper(digit) == toupper(valid_digits[i]))
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<valid_base_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xed8(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118c <valid_base_char+0x7c>
movsbl -0x5(%rbp),%edi
call   1030 <toupper@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    1179 <valid_base_char+0x69>
movl   $0x1,-0x4(%rbp)
jmp    1193 <valid_base_char+0x83>
jmp    117e <valid_base_char+0x6e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1133 <valid_base_char+0x23>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_base_char>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1154 <valid_base_char+0x44>
mov    %esi,%r14d
xor    %ebp,%ebp
movsbl %dil,%r15d
lea    0xed4(%rip),%r12
nopl   0x0(%rax)
mov    %r15d,%edi
call   1030 <toupper@plt>
mov    %rax,%rbx
movsbl 0x0(%rbp,%r12,1),%edi
call   1030 <toupper@plt>
cmp    %rax,%rbx
je     1158 <valid_base_char+0x48>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1130 <valid_base_char+0x20>
xor    %eax,%eax
jmp    115d <valid_base_char+0x4d>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define i32 @valid_base_char(i8 signext %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %7
br label %8
8: ; preds = %24, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load i8, i8* %4
%14 = call i64 @toupper(i8 signext %13)
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @toupper(i8 signext %19)
%21 = icmp eq i64 %14, %20
br i1 %21, label %22, label %23
22: ; preds = %12
store i32 1, i32* %3
br label %28
23: ; preds = %12
br label %24
24: ; preds = %23
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %8
27: ; preds = %8
store i32 0, i32* %3
br label %28
28: ; preds = %27, %22
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define i32 @valid_base_char(i8 signext %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %8
%7 = icmp eq i64 %15, %5
br i1 %7, label %16, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %15, %6 ]
%10 = tail call i64 @toupper(i8 signext %0)
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%12 = load i8, i8* %11
%13 = tail call i64 @toupper(i8 signext %12)
%14 = icmp eq i64 %10, %13
%15 = add nuw nsw i64 %9, 1
br i1 %14, label %16, label %6
16: ; preds = %8, %6, %2
%17 = phi i32 [ 0, %2 ], [ 0, %6 ], [ 1, %8 ]
ret i32 %17
}