#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*/ printf(char *);
float getPrice(int productNumber) {
  float price = 0.0;
  switch (productNumber) {
  case 1:
    price = 2.98;
    break;
  case 2:
    price = 4.50;
    break;
  case 3:
    price = 9.98;
    break;
  case 4:
    price = 4.49;
    break;
  case 5:
    price = 6.87;
    break;
  default:
    printf("Invalid product number!");
    price = -1;
    break;
  }
  return price;
}


x86 assembly (clang, -O0):
<getPrice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     11a5 <getPrice+0x95>
mov    -0x10(%rbp),%rax
lea    0xed6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  0xebd(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11be <getPrice+0xae>
movss  0xea7(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11be <getPrice+0xae>
movss  0xe91(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11be <getPrice+0xae>
movss  0xe7b(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11be <getPrice+0xae>
movss  0xe65(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11be <getPrice+0xae>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
movss  0xe5b(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPrice>:
push   %rax
add    $0xffffffff,%edi
cmp    $0x5,%edi
jae    112a <getPrice+0x1a>
movslq %edi,%rax
lea    0xef9(%rip),%rcx
movss  (%rcx,%rax,4),%xmm0
pop    %rax
ret
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
movss  0xec2(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Invalid product number!\00"
define float @getPrice(i32 %0) {
%2 = alloca i32
%3 = alloca float
store i32 %0, i32* %2
store float 0.000000e+00, float* %3
%4 = load i32, i32* %2
switch i32 %4, label %10 [
i32 1, label %5
i32 2, label %6
i32 3, label %7
i32 4, label %8
i32 5, label %9
]
5: ; preds = %1
store float 0x4007D70A40000000, float* %3
br label %12
6: ; preds = %1
store float 4.500000e+00, float* %3
br label %12
7: ; preds = %1
store float 0x4023F5C280000000, float* %3
br label %12
8: ; preds = %1
store float 0x4011F5C280000000, float* %3
br label %12
9: ; preds = %1
store float 0x401B7AE140000000, float* %3
br label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store float -1.000000e+00, float* %3
br label %12
12: ; preds = %10, %9, %8, %7, %6, %5
%13 = load float, float* %3
ret float %13
}

LLVM IR (-O2):
@.str = [24 x i8] c"Invalid product number!\00"
@switch.table.getPrice = [5 x float] [float 0x4007D70A40000000, float 4.500000e+00, float 0x4023F5C280000000, float 0x4011F5C280000000, float 0x401B7AE140000000]
define float @getPrice(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 5
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %10
6: ; preds = %1
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds [5 x float], [5 x float]* @switch.table.getPrice, i64 0, i64 %7
%9 = load float, float* %8
br label %10
10: ; preds = %6, %4
%11 = phi float [ -1.000000e+00, %4 ], [ %9, %6 ]
ret float %11
}