char IntToChar(int X) {
  if (X == 1) {
    return '1';
  } else if (X == 2) {
    return '2';
  } else if (X == 3) {
    return '3';
  } else if (X == 4) {
    return '4';
  } else if (X == 5) {
    return '5';
  } else if (X == 6) {
    return '6';
  } else if (X == 7) {
    return '7';
  } else if (X == 8) {
    return '8';
  } else if (X == 9) {
    return '9';
  } else {
    return '0';
  }
}


x86 assembly (clang, -O0):
<IntToChar>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    111a <IntToChar+0x1a>
movb   $0x31,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x2,-0x8(%rbp)
jne    112d <IntToChar+0x2d>
movb   $0x32,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x3,-0x8(%rbp)
jne    1140 <IntToChar+0x40>
movb   $0x33,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x4,-0x8(%rbp)
jne    1153 <IntToChar+0x53>
movb   $0x34,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x5,-0x8(%rbp)
jne    1166 <IntToChar+0x66>
movb   $0x35,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x6,-0x8(%rbp)
jne    1179 <IntToChar+0x79>
movb   $0x36,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x7,-0x8(%rbp)
jne    118c <IntToChar+0x8c>
movb   $0x37,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x8,-0x8(%rbp)
jne    119f <IntToChar+0x9f>
movb   $0x38,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
cmpl   $0x9,-0x8(%rbp)
jne    11b2 <IntToChar+0xb2>
movb   $0x39,-0x1(%rbp)
jmp    11b6 <IntToChar+0xb6>
movb   $0x30,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<IntToChar>:
add    $0xffffffff,%edi
lea    0x31(%rdi),%eax
cmp    $0x9,%edi
movzbl %al,%ecx
mov    $0x30,%eax
cmovb  %ecx,%eax
ret

LLVM IR (-O0):
define signext i8 @IntToChar(i32 %0) {
%2 = alloca i8
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
store i8 49, i8* %2
br label %40
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %7
store i8 50, i8* %2
br label %40
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %15
14: ; preds = %11
store i8 51, i8* %2
br label %40
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 4
br i1 %17, label %18, label %19
18: ; preds = %15
store i8 52, i8* %2
br label %40
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 5
br i1 %21, label %22, label %23
22: ; preds = %19
store i8 53, i8* %2
br label %40
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 6
br i1 %25, label %26, label %27
26: ; preds = %23
store i8 54, i8* %2
br label %40
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 7
br i1 %29, label %30, label %31
30: ; preds = %27
store i8 55, i8* %2
br label %40
31: ; preds = %27
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 8
br i1 %33, label %34, label %35
34: ; preds = %31
store i8 56, i8* %2
br label %40
35: ; preds = %31
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 9
br i1 %37, label %38, label %39
38: ; preds = %35
store i8 57, i8* %2
br label %40
39: ; preds = %35
store i8 48, i8* %2
br label %40
40: ; preds = %39, %38, %34, %30, %26, %22, %18, %14, %10, %6
%41 = load i8, i8* %2
ret i8 %41
}

LLVM IR (-O2):
define signext i8 @IntToChar(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 9
%4 = trunc i32 %2 to i8
%5 = add i8 %4, 49
%6 = select i1 %3, i8 %5, i8 48
ret i8 %6
}