#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*/ assert(int);
char toupper(char);
char s_val2ch(int v, int caps) {
  assert(v >= 0);
  if (v < 10)
    return v + '0';
  else {
    char out = (v - 10) + 'a';
    if (caps)
      return toupper(out);
    else
      return out;
  }
}


x86 assembly (clang, -O0):
<s_val2ch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0xa,-0x8(%rbp)
jge    1157 <s_val2ch+0x37>
mov    -0x8(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    1184 <s_val2ch+0x64>
mov    -0x8(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %al,-0xd(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117e <s_val2ch+0x5e>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x1(%rbp)
jmp    1184 <s_val2ch+0x64>
mov    -0xd(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_val2ch>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
cmp    $0x9,%ebx
jg     113b <s_val2ch+0x1b>
add    $0x30,%bl
jmp    1150 <s_val2ch+0x30>
add    $0x57,%bl
test   %ebp,%ebp
je     1150 <s_val2ch+0x30>
movsbl %bl,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <toupper@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @s_val2ch(i32 %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 48
%16 = trunc i32 %15 to i8
store i8 %16, i8* %3
br label %29
17: ; preds = %2
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 10
%20 = add nsw i32 %19, 97
%21 = trunc i32 %20 to i8
store i8 %21, i8* %6
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i8, i8* %6
%26 = call signext i8 @toupper(i8 signext %25)
store i8 %26, i8* %3
br label %29
27: ; preds = %17
%28 = load i8, i8* %6
store i8 %28, i8* %3
br label %29
29: ; preds = %27, %24, %13
%30 = load i8, i8* %3
ret i8 %30
}

LLVM IR (-O2):
define signext i8 @s_val2ch(i32 %0, i32 %1) {
%3 = xor i32 %0, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = icmp slt i32 %0, 10
%7 = trunc i32 %0 to i8
br i1 %6, label %8, label %10
8: ; preds = %2
%9 = add i8 %7, 48
br label %15
10: ; preds = %2
%11 = add i8 %7, 87
%12 = icmp eq i32 %1, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call signext i8 @toupper(i8 signext %11)
br label %15
15: ; preds = %13, %10, %8
%16 = phi i8 [ %9, %8 ], [ %14, %13 ], [ %11, %10 ]
ret i8 %16
}