#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 */
struct cdrom_device_info {
  int dummy;
};

/* Variables and functions */
int type_0_command(int, int);
int cm206_select_speed(struct cdrom_device_info *cdi, int speed) {
  int r;
  {
    switch (speed) {
    case 0:
      r = type_0_command(35, 1);
      break;
    case 1:
      r = type_0_command(33, 1);
      break;
    case 2:
      r = type_0_command(34, 1);
      break;
    default:
      return (-1);
    }
    if (r < 0) {
      return (r);
    } else {
      return (1);
    }
  }
}


x86 assembly (clang, -O0):
<cm206_select_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     1154 <cm206_select_speed+0x44>
jmp    1132 <cm206_select_speed+0x22>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     116b <cm206_select_speed+0x5b>
jmp    1143 <cm206_select_speed+0x33>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1182 <cm206_select_speed+0x72>
jmp    1199 <cm206_select_speed+0x89>
mov    $0x23,%edi
mov    $0x1,%esi
call   1030 <type_0_command@plt>
mov    %eax,-0x18(%rbp)
jmp    11a5 <cm206_select_speed+0x95>
mov    $0x21,%edi
mov    $0x1,%esi
call   1030 <type_0_command@plt>
mov    %eax,-0x18(%rbp)
jmp    11a5 <cm206_select_speed+0x95>
mov    $0x22,%edi
mov    $0x1,%esi
call   1030 <type_0_command@plt>
mov    %eax,-0x18(%rbp)
jmp    11a5 <cm206_select_speed+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <cm206_select_speed+0xb1>
cmpl   $0x0,-0x18(%rbp)
jge    11ba <cm206_select_speed+0xaa>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c1 <cm206_select_speed+0xb1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm206_select_speed>:
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0x2,%esi
ja     113c <cm206_select_speed+0x2c>
movslq %esi,%rax
lea    0xedb(%rip),%rcx
mov    (%rcx,%rax,4),%edi
mov    $0x1,%ebx
mov    $0x1,%esi
call   1030 <type_0_command@plt>
test   %eax,%eax
cmovs  %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.cdrom_device_info = type { i32 }
define i32 @cm206_select_speed(%struct.cdrom_device_info* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.cdrom_device_info*
%5 = alloca i32
%6 = alloca i32
store %struct.cdrom_device_info* %0, %struct.cdrom_device_info** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
switch i32 %7, label %14 [
i32 0, label %8
i32 1, label %10
i32 2, label %12
]
8: ; preds = %2
%9 = call i32 @type_0_command(i32 35, i32 1)
store i32 %9, i32* %6
br label %15
10: ; preds = %2
%11 = call i32 @type_0_command(i32 33, i32 1)
store i32 %11, i32* %6
br label %15
12: ; preds = %2
%13 = call i32 @type_0_command(i32 34, i32 1)
store i32 %13, i32* %6
br label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %21
15: ; preds = %12, %10, %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* %6
store i32 %19, i32* %3
br label %21
20: ; preds = %15
store i32 1, i32* %3
br label %21
21: ; preds = %20, %18, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.cdrom_device_info = type { i32 }
@switch.table.cm206_select_speed = [3 x i32] [i32 35, i32 33, i32 34]
define i32 @cm206_select_speed(%struct.cdrom_device_info* nocapture readnone %0, i32 %1) {
%3 = icmp ult i32 %1, 3
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.cm206_select_speed, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = tail call i32 @type_0_command(i32 %7, i32 1)
%9 = icmp slt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 1
br label %11
11: ; preds = %2, %4
%12 = phi i32 [ -1, %2 ], [ %10, %4 ]
ret i32 %12
}