#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 */
int /*<<< orphan*/ sprintf(char *, char *, ...);
void c_hex(int c, char *ret) {
  if (c >= 10) {
    switch (c) {
    case 10:
      sprintf(ret, "a");
      break;
    case 11:
      sprintf(ret, "b");
      break;
    case 12:
      sprintf(ret, "c");
      break;
    case 13:
      sprintf(ret, "d");
      break;
    case 14:
      sprintf(ret, "e");
      break;
    case 15:
      sprintf(ret, "f");
      break;
    }
    return;
  } else {
    sprintf(ret, "%d", c);
    return;
  }
}


x86 assembly (clang, -O0):
<c_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0xa,-0x4(%rbp)
jl     11dc <c_hex+0xcc>
mov    -0x4(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11d7 <c_hex+0xc7>
mov    -0x18(%rbp),%rax
lea    0xeb7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xebb(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11d7 <c_hex+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11d7 <c_hex+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11d7 <c_hex+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11d7 <c_hex+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11d7 <c_hex+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f1 <c_hex+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_hex>:
mov    %edi,%edx
cmp    $0xa,%edi
jl     1135 <c_hex+0x25>
add    $0xfffffff6,%edx
cmp    $0x5,%edx
ja     1134 <c_hex+0x24>
lea    0xeda(%rip),%rax
movslq (%rax,%rdx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movw   $0x61,(%rsi)
ret
lea    0xedc(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
movw   $0x62,(%rsi)
ret
movw   $0x63,(%rsi)
ret
movw   $0x64,(%rsi)
ret
movw   $0x65,(%rsi)
ret
movw   $0x66,(%rsi)
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [2 x i8] c"c\00"
@.str.3 = [2 x i8] c"d\00"
@.str.4 = [2 x i8] c"e\00"
@.str.5 = [2 x i8] c"f\00"
@.str.6 = [3 x i8] c"%d\00"
define void @c_hex(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 10
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = load i32, i32* %3
switch i32 %8, label %27 [
i32 10, label %9
i32 11, label %12
i32 12, label %15
i32 13, label %18
i32 14, label %21
i32 15, label %24
]
9: ; preds = %7
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %27
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %27
15: ; preds = %7
%16 = load i8*, i8** %4
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
18: ; preds = %7
%19 = load i8*, i8** %4
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %27
21: ; preds = %7
%22 = load i8*, i8** %4
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %27
24: ; preds = %7
%25 = load i8*, i8** %4
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %7, %24, %21, %18, %15, %12, %9
br label %32
28: ; preds = %2
%29 = load i8*, i8** %4
%30 = load i32, i32* %3
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %27
ret void
}

LLVM IR (-O2):
@.str.6 = [3 x i8] c"%d\00"
define void @c_hex(i32 %0, i8* nocapture writeonly %1) {
%3 = icmp sgt i32 %0, 9
br i1 %3, label %4, label %17
4: ; preds = %2
switch i32 %0, label %19 [
i32 10, label %5
i32 11, label %7
i32 12, label %9
i32 13, label %11
i32 14, label %13
i32 15, label %15
]
5: ; preds = %4
%6 = bitcast i8* %1 to i16*
store i16 97, i16* %6
br label %19
7: ; preds = %4
%8 = bitcast i8* %1 to i16*
store i16 98, i16* %8
br label %19
9: ; preds = %4
%10 = bitcast i8* %1 to i16*
store i16 99, i16* %10
br label %19
11: ; preds = %4
%12 = bitcast i8* %1 to i16*
store i16 100, i16* %12
br label %19
13: ; preds = %4
%14 = bitcast i8* %1 to i16*
store i16 101, i16* %14
br label %19
15: ; preds = %4
%16 = bitcast i8* %1 to i16*
store i16 102, i16* %16
br label %19
17: ; preds = %2
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %5, %7, %9, %11, %13, %15, %4, %17
ret void
}