#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 dblcmp(double, double);
int fltcmp(float, float);
int intcmp(int, int);
int strcmp(void *, void *);
int cmp_values(int value_type, void *v1, void *v2) {
  switch (value_type) {
  case 0:
    return intcmp(*(int *)v1, *(int *)v2);
  case 1:
    return fltcmp(*(float *)v1, *(float *)v2);
  case 2:
    return dblcmp(*(double *)v1, *(double *)v2);
  case 3:
    return strcmp(v1, v2);
  default:
    return -2;
  }
}


x86 assembly (clang, -O0):
<cmp_values>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%rax
ja     11e0 <cmp_values+0xa0>
mov    -0x20(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <intcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <cmp_values+0xa7>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm1
call   1060 <fltcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <cmp_values+0xa7>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
call   1040 <dblcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <cmp_values+0xa7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <cmp_values+0xa7>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_values>:
cmp    $0x3,%edi
ja     1160 <cmp_values+0x20>
mov    %edi,%eax
lea    0xeb2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    (%rsi),%edi
mov    (%rdx),%esi
jmp    1030 <intcmp@plt>
mov    $0xfffffffe,%eax
ret
movss  (%rsi),%xmm0
movss  (%rdx),%xmm1
jmp    1060 <fltcmp@plt>
movsd  (%rsi),%xmm0
movsd  (%rdx),%xmm1
jmp    1040 <dblcmp@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
jmp    1050 <strcmp@plt>

LLVM IR (-O0):
define i32 @cmp_values(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32, i32* %5
switch i32 %8, label %37 [
i32 0, label %9
i32 1, label %17
i32 2, label %25
i32 3, label %33
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
%13 = load i8*, i8** %7
%14 = bitcast i8* %13 to i32*
%15 = load i32, i32* %14
%16 = call i32 @intcmp(i32 %12, i32 %15)
store i32 %16, i32* %4
br label %38
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = bitcast i8* %18 to float*
%20 = load float, float* %19
%21 = load i8*, i8** %7
%22 = bitcast i8* %21 to float*
%23 = load float, float* %22
%24 = call i32 @fltcmp(float %20, float %23)
store i32 %24, i32* %4
br label %38
25: ; preds = %3
%26 = load i8*, i8** %6
%27 = bitcast i8* %26 to double*
%28 = load double, double* %27
%29 = load i8*, i8** %7
%30 = bitcast i8* %29 to double*
%31 = load double, double* %30
%32 = call i32 @dblcmp(double %28, double %31)
store i32 %32, i32* %4
br label %38
33: ; preds = %3
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i32 @strcmp(i8* %34, i8* %35)
store i32 %36, i32* %4
br label %38
37: ; preds = %3
store i32 -2, i32* %4
br label %38
38: ; preds = %37, %33, %25, %17, %9
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @cmp_values(i32 %0, i8* nocapture %1, i8* nocapture %2) {
switch i32 %0, label %24 [
i32 0, label %4
i32 1, label %10
i32 2, label %16
i32 3, label %22
]
4: ; preds = %3
%5 = bitcast i8* %1 to i32*
%6 = load i32, i32* %5
%7 = bitcast i8* %2 to i32*
%8 = load i32, i32* %7
%9 = tail call i32 @intcmp(i32 %6, i32 %8)
br label %24
10: ; preds = %3
%11 = bitcast i8* %1 to float*
%12 = load float, float* %11
%13 = bitcast i8* %2 to float*
%14 = load float, float* %13
%15 = tail call i32 @fltcmp(float %12, float %14)
br label %24
16: ; preds = %3
%17 = bitcast i8* %1 to double*
%18 = load double, double* %17
%19 = bitcast i8* %2 to double*
%20 = load double, double* %19
%21 = tail call i32 @dblcmp(double %18, double %20)
br label %24
22: ; preds = %3
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
br label %24
24: ; preds = %3, %22, %16, %10, %4
%25 = phi i32 [ %23, %22 ], [ %21, %16 ], [ %15, %10 ], [ %9, %4 ], [ -2, %3 ]
ret i32 %25
}