int to_digit(char c) {
  if (is_digit(c))
    return c - '0';
  err("WARNING", __func__, 308, "Non-digit passed to %s, returning zero\n",
      __func__);
  return 0;
}


x86 assembly (clang, -O0):
<to_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
mov    $0x0,%al
call   1040 <is_digit@plt>
cmp    $0x0,%eax
je     1151 <to_digit+0x31>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    117c <to_digit+0x5c>
lea    0xea8(%rip),%rdi
lea    0xea9(%rip),%r8
mov    $0x134,%edx
lea    0xea6(%rip),%rcx
mov    %r8,%rsi
mov    $0x0,%al
call   1030 <err@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_digit>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <is_digit@plt>
test   %eax,%eax
je     1139 <to_digit+0x19>
add    $0xffffffd0,%ebp
mov    %ebp,%ebx
jmp    115d <to_digit+0x3d>
lea    0xec0(%rip),%rdi
lea    0xeca(%rip),%rcx
lea    0xeba(%rip),%rsi
mov    $0x134,%edx
mov    %rsi,%r8
xor    %eax,%eax
call   1030 <err@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"WARNING\00"
@__func__.to_digit = [9 x i8] c"to_digit\00"
@.str.1 = [40 x i8] c"Non-digit passed to %s, returning zero\0A\00"
define i32 @to_digit(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = call i32 (i32, ...) bitcast (i32 (...)* @is_digit to i32 (i32, ...)*)(i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = sub nsw i32 %10, 48
store i32 %11, i32* %2
br label %14
12: ; preds = %1
%13 = call i32 (i8*, i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @err to i32 (i8*, i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.to_digit, i64 0, i64 0), i32 308, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.to_digit, i64 0, i64 0))
store i32 0, i32* %2
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@.str = [8 x i8] c"WARNING\00"
@__func__.to_digit = [9 x i8] c"to_digit\00"
@.str.1 = [40 x i8] c"Non-digit passed to %s, returning zero\0A\00"
define i32 @to_digit(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @is_digit to i32 (i32, ...)*)(i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = add nsw i32 %2, -48
br label %9
7: ; preds = %1
%8 = tail call i32 (i8*, i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @err to i32 (i8*, i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.to_digit, i64 0, i64 0), i32 308, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.to_digit, i64 0, i64 0))
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ %6, %5 ], [ 0, %7 ]
ret i32 %10
}