#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 rand();
char randchar() {
  switch (rand() % 3) {
  case 0:
    return rand() % 11 + '0';
    break;
  case 1:
    return rand() % 27 + 'A';
    break;
  case 2:
    return rand() % 26 + 'a';
    break;
  }
  return 'X';
}


x86 assembly (clang, -O0):
<randchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
je     116d <randchar+0x5d>
jmp    114b <randchar+0x3b>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
je     1189 <randchar+0x79>
jmp    115c <randchar+0x4c>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
je     11a5 <randchar+0x95>
jmp    11c1 <randchar+0xb1>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xb,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
jmp    11c5 <randchar+0xb5>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x1b,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
jmp    11c5 <randchar+0xb5>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
jmp    11c5 <randchar+0xb5>
movb   $0x58,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randchar>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rax
add    %edx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ecx
mov    $0x58,%al
cmp    $0x2,%ecx
ja     1163 <randchar+0x53>
movslq %ecx,%rbx
lea    0xeb8(%rip),%r14
shl    $0x3,%ecx
mov    $0x614130,%ebp
shr    %cl,%ebp
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idivl  (%r14,%rbx,4)
mov    %edx,%eax
add    %bpl,%al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @randchar() {
%1 = alloca i8
%2 = call i32 (...) @rand()
%3 = srem i32 %2, 3
switch i32 %3, label %19 [
i32 0, label %4
i32 1, label %9
i32 2, label %14
]
4: ; preds = %0
%5 = call i32 (...) @rand()
%6 = srem i32 %5, 11
%7 = add nsw i32 %6, 48
%8 = trunc i32 %7 to i8
store i8 %8, i8* %1
br label %20
9: ; preds = %0
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 27
%12 = add nsw i32 %11, 65
%13 = trunc i32 %12 to i8
store i8 %13, i8* %1
br label %20
14: ; preds = %0
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 26
%17 = add nsw i32 %16, 97
%18 = trunc i32 %17 to i8
store i8 %18, i8* %1
br label %20
19: ; preds = %0
store i8 88, i8* %1
br label %20
20: ; preds = %19, %14, %9, %4
%21 = load i8, i8* %1
ret i8 %21
}

LLVM IR (-O2):
@switch.table.randchar = [3 x i32] [i32 11, i32 27, i32 26]
define signext i8 @randchar() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 3
%3 = icmp ult i32 %2, 3
br i1 %3, label %4, label %16
4: ; preds = %0
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.randchar, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = trunc i32 %2 to i24
%9 = shl i24 %8, 3
%10 = lshr i24 6373680, %9
%11 = trunc i24 %10 to i8
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, %7
%14 = trunc i32 %13 to i8
%15 = add nsw i8 %11, %14
br label %16
16: ; preds = %0, %4
%17 = phi i8 [ 88, %0 ], [ %15, %4 ]
ret i8 %17
}