int digit_to_num(char d) {
  int num = ((int)d) - (int)'0';
  (void)({
    if (__builtin_expect(!!(!(num <= 9 && num >= 0)), 0)) {
      tor_assertion_failed_(("/scratch/repos/new/home/jordi_armengol_estape/"
                             "c-scraper/outputs/2022-01-22/02-19-57/repos/5mil/"
                             "lulz/refs/heads/master/src/tor/tor_util.c"),
                            2773, __func__, "num <= 9 && num >= 0");
      abort();
    }
  });
  return num;
}


x86 assembly (clang, -O0):
<digit_to_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x9,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jg     1151 <digit_to_num+0x31>
cmpl   $0x0,-0x8(%rbp)
setge  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
xor    $0xff,%al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cltq
cmp    $0x0,%rax
je     1191 <digit_to_num+0x71>
lea    0xe8e(%rip),%rdi
mov    $0xad5,%esi
lea    0xf0b(%rip),%rdx
lea    0xf11(%rip),%rcx
mov    $0x0,%al
call   1030 <tor_assertion_failed_@plt>
call   1040 <abort@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digit_to_num>:
lea    -0x3a(%rdi),%eax
cmp    $0xf5,%al
jbe    112f <digit_to_num+0xf>
movzbl %dil,%eax
add    $0xffffffd0,%eax
ret
push   %rax
lea    0xec9(%rip),%rdi
lea    0xf4b(%rip),%rdx
lea    0xf51(%rip),%rcx
mov    $0xad5,%esi
xor    %eax,%eax
call   1030 <tor_assertion_failed_@plt>
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/5mil/lulz/refs/heads/master/src/tor/tor_util.c\00"
@__func__.digit_to_num = [13 x i8] c"digit_to_num\00"
@.str.1 = [21 x i8] c"num <= 9 && num >= 0\00"
define i32 @digit_to_num(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = sub nsw i32 %5, 48
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 9
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 0
br label %12
12: ; preds = %9, %1
%13 = phi i1 [ false, %1 ], [ %11, %9 ]
%14 = xor i1 %13, true
%15 = xor i1 %14, true
%16 = xor i1 %15, true
%17 = zext i1 %16 to i32
%18 = sext i32 %17 to i64
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 (i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @tor_assertion_failed_ to i32 (i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 2773, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__func__.digit_to_num, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
unreachable
22: ; preds = %12
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/5mil/lulz/refs/heads/master/src/tor/tor_util.c\00"
@__func__.digit_to_num = [13 x i8] c"digit_to_num\00"
@.str.1 = [21 x i8] c"num <= 9 && num >= 0\00"
define i32 @digit_to_num(i8 signext %0) {
%2 = add i8 %0, -58
%3 = icmp ult i8 %2, -10
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @tor_assertion_failed_ to i32 (i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 2773, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__func__.digit_to_num, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
tail call void @abort()
unreachable
6: ; preds = %1
%7 = zext i8 %0 to i32
%8 = add nsw i32 %7, -48
ret i32 %8
}