#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*/ cgcalswtch();
int /*<<< orphan*/ cgcase(int, int);
int /*<<< orphan*/ cgldswtch(int);
int /*<<< orphan*/ gendata();
int /*<<< orphan*/ gendefl(int);
int /*<<< orphan*/ gendefw(int);
int /*<<< orphan*/ genlab(int);
int /*<<< orphan*/ gentext();
int label();
void genswitch(int *vals, int *labs, int nc, int dflt) {
  int i;
  int ltbl = label();
  gentext();
  cgldswtch(ltbl);
  cgcalswtch();
  gendata();
  genlab(ltbl);
  gendefw(nc);
  for (i = 0; i < nc; i++)
    cgcase(vals[i], labs[i]);
  gendefl(dflt);
}


x86 assembly (clang, -O0):
<genswitch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <label@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <gentext@plt>
mov    -0x20(%rbp),%edi
call   10a0 <cgldswtch@plt>
mov    $0x0,%al
call   1060 <cgcalswtch@plt>
mov    $0x0,%al
call   1040 <gendata@plt>
mov    -0x20(%rbp),%edi
call   1070 <genlab@plt>
mov    -0x14(%rbp),%edi
call   10b0 <gendefw@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1219 <genswitch+0x89>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1080 <cgcase@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e4 <genswitch+0x54>
mov    -0x18(%rbp),%edi
call   1050 <gendefl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genswitch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <label@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1090 <gentext@plt>
mov    %r12d,%edi
call   10a0 <cgldswtch@plt>
xor    %eax,%eax
call   1060 <cgcalswtch@plt>
xor    %eax,%eax
call   1040 <gendata@plt>
mov    %r12d,%edi
call   1070 <genlab@plt>
mov    %r15d,%edi
call   10b0 <gendefw@plt>
test   %r15d,%r15d
jle    1207 <genswitch+0x77>
mov    %r15d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r14,%rbp,4),%edi
mov    0x0(%r13,%rbp,4),%esi
call   1080 <cgcase@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11f0 <genswitch+0x60>
mov    0x4(%rsp),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <gendefl@plt>

LLVM IR (-O0):
define void @genswitch(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = call i32 (...) @label()
store i32 %11, i32* %10
%12 = call i32 (...) @gentext()
%13 = load i32, i32* %10
%14 = call i32 @cgldswtch(i32 %13)
%15 = call i32 (...) @cgcalswtch()
%16 = call i32 (...) @gendata()
%17 = load i32, i32* %10
%18 = call i32 @genlab(i32 %17)
%19 = load i32, i32* %7
%20 = call i32 @gendefw(i32 %19)
store i32 0, i32* %9
br label %21
21: ; preds = %37, %4
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = load i32*, i32** %6
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @cgcase(i32 %30, i32 %35)
br label %37
37: ; preds = %25
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %21
40: ; preds = %21
%41 = load i32, i32* %8
%42 = call i32 @gendefl(i32 %41)
ret void
}

LLVM IR (-O2):
define void @genswitch(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 (...) @label()
%6 = tail call i32 (...) @gentext()
%7 = tail call i32 @cgldswtch(i32 %5)
%8 = tail call i32 (...) @cgcalswtch()
%9 = tail call i32 (...) @gendata()
%10 = tail call i32 @genlab(i32 %5)
%11 = tail call i32 @gendefw(i32 %2)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %24
13: ; preds = %4
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %22, %15 ]
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %1, i64 %16
%20 = load i32, i32* %19
%21 = tail call i32 @cgcase(i32 %18, i32 %20)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %14
br i1 %23, label %24, label %15
24: ; preds = %15, %4
%25 = tail call i32 @gendefl(i32 %3)
ret void
}