#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 */
void __assert(char *, int);
char digittoascii(unsigned n, int uppercase) {
  ((n < 36) ? (void)0
            : __assert("/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/ElvisLouis/"
                       "code/refs/heads/master/bin/nachos/test/printf.c",
                       5));
  if (n <= 9)
    return '0' + n;
  else if (uppercase)
    return 'A' + n - 10;
  else
    return 'a' + n - 10;
}


x86 assembly (clang, -O0):
<digittoascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x24,-0x8(%rbp)
jae    112d <digittoascii+0x1d>
jmp    113e <digittoascii+0x2e>
lea    0xecc(%rip),%rdi
mov    $0x5,%esi
call   1030 <__assert@plt>
cmpl   $0x9,-0x8(%rbp)
ja     1156 <digittoascii+0x46>
mov    -0x8(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    117d <digittoascii+0x6d>
cmpl   $0x0,-0xc(%rbp)
je     1171 <digittoascii+0x61>
mov    -0x8(%rbp),%eax
add    $0x41,%eax
sub    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    117d <digittoascii+0x6d>
mov    -0x8(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digittoascii>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
cmp    $0x24,%edi
jae    1126 <digittoascii+0x16>
cmp    $0x9,%ebx
ja     1137 <digittoascii+0x27>
add    $0x30,%bl
jmp    1143 <digittoascii+0x33>
lea    0xed3(%rip),%rdi
mov    $0x5,%esi
call   1030 <__assert@plt>
test   %ebp,%ebp
je     1140 <digittoascii+0x30>
add    $0x37,%bl
jmp    1143 <digittoascii+0x33>
add    $0x57,%bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ElvisLouis/code/refs/heads/master/bin/nachos/test/printf.c\00"
define signext i8 @digittoascii(i32 %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = icmp ult i32 %6, 36
br i1 %7, label %8, label %9
8: ; preds = %2
br label %10
9: ; preds = %2
br label %10
10: ; preds = %9, %8
%11 = load i32, i32* %4
%12 = icmp ule i32 %11, 9
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %4
%15 = add i32 48, %14
%16 = trunc i32 %15 to i8
store i8 %16, i8* %3
br label %30
17: ; preds = %10
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %4
%22 = add i32 65, %21
%23 = sub i32 %22, 10
%24 = trunc i32 %23 to i8
store i8 %24, i8* %3
br label %30
25: ; preds = %17
%26 = load i32, i32* %4
%27 = add i32 97, %26
%28 = sub i32 %27, 10
%29 = trunc i32 %28 to i8
store i8 %29, i8* %3
br label %30
30: ; preds = %25, %20, %13
%31 = load i8, i8* %3
ret i8 %31
}

LLVM IR (-O2):
@.str = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ElvisLouis/code/refs/heads/master/bin/nachos/test/printf.c\00"
define signext i8 @digittoascii(i32 %0, i32 %1) {
%3 = icmp ult i32 %0, 36
br i1 %3, label %5, label %4
4: ; preds = %2
tail call void @__assert(i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str, i64 0, i64 0), i32 5)
br label %10
5: ; preds = %2
%6 = icmp ult i32 %0, 10
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = trunc i32 %0 to i8
%9 = add nuw nsw i8 %8, 48
br label %17
10: ; preds = %4, %5
%11 = icmp eq i32 %1, 0
%12 = trunc i32 %0 to i8
br i1 %11, label %15, label %13
13: ; preds = %10
%14 = add i8 %12, 55
br label %17
15: ; preds = %10
%16 = add i8 %12, 87
br label %17
17: ; preds = %15, %13, %7
%18 = phi i8 [ %9, %7 ], [ %14, %13 ], [ %16, %15 ]
ret i8 %18
}