#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
char toupper(char);
void validateBase(char num[], int frombase, int tobase) {
  if (frombase < 2 || frombase > 35) {
    printf("The bases should lie between 2 and 35\n");
    exit(0);
  }
  if (tobase < 2 || tobase > 35) {
    printf("The bases should lie between 2 and 35\n");
    exit(0);
  }
  if (strlen(num) > 32) {
    printf("The entered number is longer than 32 digits, please enter a "
           "smaller number\n");
    exit(0);
  }
  if (frombase > 10) {
    char base_digits[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                            '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                            'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                            'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    int i;
    i = 0;
    do {
      int j;
      int invalid = 1;
      for (j = 0; j < frombase; j++) {
        if (toupper(num[i]) == base_digits[j]) {
          invalid = 0;
        }
      }
      if (invalid == 1) {
        printf("Quitting for %c with base %d\n", num[i], frombase);
        printf("The entered number is invalid for the given base\n");
        exit(0);
      }
      i++;
    } while (num[i] != '\0');
  }
}


x86 assembly (clang, -O0):
<validateBase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     1176 <validateBase+0x26>
cmpl   $0x23,-0xc(%rbp)
jle    118b <validateBase+0x3b>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
cmpl   $0x2,-0x10(%rbp)
jl     119f <validateBase+0x4f>
cmpl   $0x23,-0x10(%rbp)
jle    11b4 <validateBase+0x64>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x20,%eax
jle    11db <validateBase+0x8b>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
cmpl   $0xa,-0xc(%rbp)
jle    12b9 <validateBase+0x169>
lea    -0x40(%rbp),%rdi
lea    0xee0(%rip),%rsi
mov    $0x24,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125a <validateBase+0x10a>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
movslq -0x48(%rbp),%rcx
movsbl -0x40(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1247 <validateBase+0xf7>
movl   $0x0,-0x4c(%rbp)
jmp    124c <validateBase+0xfc>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    120f <validateBase+0xbf>
cmpl   $0x1,-0x4c(%rbp)
jne    1296 <validateBase+0x146>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0xc(%rbp),%edx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1201 <validateBase+0xb1>
jmp    12b9 <validateBase+0x169>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateBase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
lea    -0x24(%rbx),%eax
cmp    $0xffffffdd,%eax
jbe    121d <validateBase+0xcd>
add    $0xffffffdc,%edx
cmp    $0xffffffdd,%edx
jbe    121d <validateBase+0xcd>
mov    %rdi,%r15
call   1050 <strlen@plt>
cmp    $0x21,%eax
jge    1226 <validateBase+0xd6>
mov    %rbx,(%rsp)
cmp    $0xb,%ebx
jb     11e2 <validateBase+0x92>
mov    (%rsp),%r13d
lea    0xe66(%rip),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    $0x1,%r14d
xor    %r12d,%r12d
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
cmp    (%r12,%rbp,1),%al
mov    $0x0,%eax
cmove  %eax,%r14d
add    $0x1,%r12
cmp    %r12,%r13
jne    11b0 <validateBase+0x60>
cmp    $0x1,%r14d
je     11f1 <validateBase+0xa1>
cmpb   $0x0,0x1(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    11a0 <validateBase+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%eax
movsbl (%r15,%rax,1),%esi
lea    0xe25(%rip),%rdi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe9a(%rip),%rdi
jmp    1211 <validateBase+0xc1>
lea    0xe46(%rip),%rdi
jmp    1211 <validateBase+0xc1>

LLVM IR (-O0):
@.str = [39 x i8] c"The bases should lie between 2 and 35\0A\00"
@.str.1 = [76 x i8] c"The entered number is longer than 32 digits, please enter a smaller number\0A\00"
@__const.validateBase.base_digits = [36 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@.str.2 = [30 x i8] c"Quitting for %c with base %d\0A\00"
@.str.3 = [50 x i8] c"The entered number is invalid for the given base\0A\00"
define void @validateBase(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [36 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 2
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 35
br i1 %15, label %16, label %19
16: ; preds = %13, %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %13
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 2
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp sgt i32 %23, 35
br i1 %24, label %25, label %28
25: ; preds = %22, %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
%31 = icmp sgt i32 %30, 32
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %28
%36 = load i32, i32* %5
%37 = icmp sgt i32 %36, 10
br i1 %37, label %38, label %90
38: ; preds = %35
%39 = bitcast [36 x i8]* %7 to i8*
store i32 0, i32* %8
br label %40
40: ; preds = %81, %38
store i32 1, i32* %10
store i32 0, i32* %9
br label %41
41: ; preds = %61, %40
%42 = load i32, i32* %9
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %64
45: ; preds = %41
%46 = load i8*, i8** %4
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = call signext i8 @toupper(i8 signext %50)
%52 = sext i8 %51 to i32
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [36 x i8], [36 x i8]* %7, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %52, %57
br i1 %58, label %59, label %60
59: ; preds = %45
store i32 0, i32* %10
br label %60
60: ; preds = %59, %45
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %41
64: ; preds = %41
%65 = load i32, i32* %10
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %78
67: ; preds = %64
%68 = load i8*, i8** %4
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = load i32, i32* %5
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %73, i32 %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %64
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %81
81: ; preds = %78
%82 = load i8*, i8** %4
%83 = load i32, i32* %8
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp ne i32 %87, 0
br i1 %88, label %40, label %89
89: ; preds = %81
br label %90
90: ; preds = %89, %35
ret void
}

LLVM IR (-O2):
@__const.validateBase.base_digits = [36 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@.str.2 = [30 x i8] c"Quitting for %c with base %d\0A\00"
@str = [49 x i8] c"The entered number is invalid for the given base\00"
@str.4 = [75 x i8] c"The entered number is longer than 32 digits, please enter a smaller number\00"
@str.6 = [38 x i8] c"The bases should lie between 2 and 35\00"
define void @validateBase(i8* %0, i32 %1, i32 %2) {
%4 = add i32 %1, -36
%5 = icmp ult i32 %4, -34
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %3
%10 = add i32 %2, -36
%11 = icmp ult i32 %10, -34
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %9
%16 = tail call i32 @strlen(i8* %0)
%17 = icmp sgt i32 %16, 32
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.4, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %15
%22 = icmp ugt i32 %1, 10
br i1 %22, label %23, label %54
23: ; preds = %21
%24 = zext i32 %1 to i64
br label %25
25: ; preds = %23, %49
%26 = phi i64 [ 0, %23 ], [ %50, %49 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ 0, %25 ], [ %37, %28 ]
%30 = phi i32 [ 1, %25 ], [ %36, %28 ]
%31 = load i8, i8* %27
%32 = tail call signext i8 @toupper(i8 signext %31)
%33 = getelementptr inbounds [36 x i8], [36 x i8]* @__const.validateBase.base_digits, i64 0, i64 %29
%34 = load i8, i8* %33
%35 = icmp eq i8 %32, %34
%36 = select i1 %35, i32 0, i32 %30
%37 = add nuw nsw i64 %29, 1
%38 = icmp eq i64 %37, %24
br i1 %38, label %39, label %28
39: ; preds = %28
%40 = icmp eq i32 %36, 1
br i1 %40, label %41, label %49
41: ; preds = %39
%42 = and i64 %26, 4294967295
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %1)
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%48 = tail call i32 @exit(i32 0)
unreachable
49: ; preds = %39
%50 = add nuw i64 %26, 1
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
br i1 %53, label %54, label %25
54: ; preds = %49, %21
ret void
}