#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*/ abort();
int foo(int code) {
  if (code >= 3)
    switch (code) {
    case 3:
      return 4;
    case 4:
      return 3;
    case 5:
      return 6;
    case 6:
      return 7;
    case 7:
      return 8;
    case 8:
      return 5;
    default:
      abort();
    }
  switch (code) {
  case 3:
    return 4;
  case 4:
    return 3;
  case 5:
    return 6;
  case 6:
    return 7;
  case 7:
    return 8;
  case 8:
    return 5;
  default:
    abort();
  }
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     119d <foo+0x8d>
mov    -0x8(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x5,%eax
ja     1196 <foo+0x86>
mov    -0x10(%rbp),%rax
lea    0xed3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x4,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x3,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x6,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x7,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x8,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x5,-0x4(%rbp)
jmp    1215 <foo+0x105>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     120e <foo+0xfe>
mov    -0x18(%rbp),%rax
lea    0xe43(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x4,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x3,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x6,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x7,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x8,-0x4(%rbp)
jmp    1215 <foo+0x105>
movl   $0x5,-0x4(%rbp)
jmp    1215 <foo+0x105>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rax
cmp    $0x3,%edi
jl     112d <foo+0x1d>
add    $0xfffffffd,%edi
cmp    $0x6,%edi
jae    112d <foo+0x1d>
movslq %edi,%rax
lea    0xed8(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 3
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = load i32, i32* %3
switch i32 %7, label %14 [
i32 3, label %8
i32 4, label %9
i32 5, label %10
i32 6, label %11
i32 7, label %12
i32 8, label %13
]
8: ; preds = %6
store i32 4, i32* %2
br label %26
9: ; preds = %6
store i32 3, i32* %2
br label %26
10: ; preds = %6
store i32 6, i32* %2
br label %26
11: ; preds = %6
store i32 7, i32* %2
br label %26
12: ; preds = %6
store i32 8, i32* %2
br label %26
13: ; preds = %6
store i32 5, i32* %2
br label %26
14: ; preds = %6
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %1
%17 = load i32, i32* %3
switch i32 %17, label %24 [
i32 3, label %18
i32 4, label %19
i32 5, label %20
i32 6, label %21
i32 7, label %22
i32 8, label %23
]
18: ; preds = %16
store i32 4, i32* %2
br label %26
19: ; preds = %16
store i32 3, i32* %2
br label %26
20: ; preds = %16
store i32 6, i32* %2
br label %26
21: ; preds = %16
store i32 7, i32* %2
br label %26
22: ; preds = %16
store i32 8, i32* %2
br label %26
23: ; preds = %16
store i32 5, i32* %2
br label %26
24: ; preds = %16
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %23, %22, %21, %20, %19, %18, %13, %12, %11, %10, %9, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@switch.table.foo = [6 x i32] [i32 4, i32 3, i32 6, i32 7, i32 8, i32 5]
define i32 @foo(i32 %0) {
%2 = icmp sgt i32 %0, 2
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = add i32 %0, -3
%5 = icmp ult i32 %4, 6
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %1
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %3
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.foo, i64 0, i64 %11
%13 = load i32, i32* %12
ret i32 %13
}