char char2hex(char value, char *name) {
  if (value < '0' || value > 'f' || value < 'A' && value > '9' ||
      value < 'a' && value > 'F')
    printf("\nInvalid character %c or '%s' not exists\n", value, name),
        exit(-1);
  return value > '9' ? 9 + (value & 7) : value - '0';
}


x86 assembly (clang, -O0):
<char2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jl     1180 <char2hex+0x60>
movsbl -0x1(%rbp),%eax
cmp    $0x66,%eax
jg     1180 <char2hex+0x60>
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jge    1166 <char2hex+0x46>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     1180 <char2hex+0x60>
movsbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jge    11a0 <char2hex+0x80>
movsbl -0x1(%rbp),%eax
cmp    $0x46,%eax
jle    11a0 <char2hex+0x80>
movsbl -0x1(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jle    11bf <char2hex+0x9f>
movsbl -0x1(%rbp),%eax
and    $0x7,%eax
add    $0x9,%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <char2hex+0xa9>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movsbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char2hex>:
mov    %rsi,%rdx
lea    -0x67(%rdi),%eax
cmp    $0xc9,%al
jb     114f <char2hex+0x2f>
lea    -0x3a(%rdi),%eax
cmp    $0x7,%al
jb     114f <char2hex+0x2f>
lea    -0x47(%rdi),%eax
cmp    $0x19,%al
jbe    114f <char2hex+0x2f>
mov    %edi,%eax
and    $0x7,%al
add    $0x9,%al
lea    -0x30(%rdi),%ecx
cmp    $0x3a,%dil
movzbl %cl,%ecx
movzbl %al,%eax
cmovb  %ecx,%eax
ret
push   %rax
movsbl %dil,%esi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"\0AInvalid character %c or '%s' not exists\0A\00"
define signext i8 @char2hex(i8 signext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
store i8 %0, i8* %3
store i8* %1, i8** %4
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
%7 = icmp slt i32 %6, 48
br i1 %7, label %28, label %8
8: ; preds = %2
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp sgt i32 %10, 102
br i1 %11, label %28, label %12
12: ; preds = %8
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp slt i32 %14, 65
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = icmp sgt i32 %18, 57
br i1 %19, label %28, label %20
20: ; preds = %16, %12
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp slt i32 %22, 97
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = icmp sgt i32 %26, 70
br i1 %27, label %28, label %33
28: ; preds = %24, %16, %8, %2
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = load i8*, i8** %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %30, i8* %31)
unreachable
33: ; preds = %24, %20
%34 = load i8, i8* %3
%35 = sext i8 %34 to i32
%36 = icmp sgt i32 %35, 57
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8, i8* %3
%39 = sext i8 %38 to i32
%40 = and i32 %39, 7
%41 = add nsw i32 9, %40
br label %46
42: ; preds = %33
%43 = load i8, i8* %3
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 48
br label %46
46: ; preds = %42, %37
%47 = phi i32 [ %41, %37 ], [ %45, %42 ]
%48 = trunc i32 %47 to i8
ret i8 %48
}

LLVM IR (-O2):
@.str = [42 x i8] c"\0AInvalid character %c or '%s' not exists\0A\00"
define signext i8 @char2hex(i8 signext %0, i8* %1) {
%3 = add i8 %0, -103
%4 = icmp ult i8 %3, -55
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = add nsw i8 %0, -58
%7 = icmp ult i8 %6, 7
%8 = add nsw i8 %0, -71
%9 = icmp ult i8 %8, 26
%10 = or i1 %7, %9
br i1 %10, label %11, label %14
11: ; preds = %5, %2
%12 = sext i8 %0 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %1)
tail call void @exit(i32 -1)
unreachable
14: ; preds = %5
%15 = icmp ugt i8 %0, 57
%16 = and i8 %0, 7
%17 = add nuw nsw i8 %16, 9
%18 = add nsw i8 %0, -48
%19 = select i1 %15, i8 %17, i8 %18
ret i8 %19
}