#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*/ gdc_exec_server();
int gdc_get_cmd_stat(int, int *);
int gdc_req_cmd(int, void *);
int cdrom_exec_cmd(int cmd, void *param) {
  int status[4] = {0};
  int f, n;
  f = gdc_req_cmd(cmd, param);
  do {
    gdc_exec_server();
    n = gdc_get_cmd_stat(f, status);
  } while (n == 1);
  if (n == 2)
    return 0;
  else if (n == 3)
    return 4;
  else if (n == 0)
    return 5;
  else {
    switch (status[0]) {
    case 2:
      return 1;
    case 6:
      return 2;
    default:
      return 3;
    }
  }
}


x86 assembly (clang, -O0):
<cdrom_exec_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <gdc_req_cmd@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <gdc_exec_server@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <gdc_get_cmd_stat@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     116e <cdrom_exec_cmd+0x2e>
cmpl   $0x2,-0x28(%rbp)
jne    11a4 <cdrom_exec_cmd+0x64>
movl   $0x0,-0x4(%rbp)
jmp    1214 <cdrom_exec_cmd+0xd4>
cmpl   $0x3,-0x28(%rbp)
jne    11ba <cdrom_exec_cmd+0x7a>
movl   $0x4,-0x4(%rbp)
jmp    1214 <cdrom_exec_cmd+0xd4>
cmpl   $0x0,-0x28(%rbp)
jne    11d0 <cdrom_exec_cmd+0x90>
movl   $0x5,-0x4(%rbp)
jmp    1214 <cdrom_exec_cmd+0xd4>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2,%eax
je     11f5 <cdrom_exec_cmd+0xb5>
jmp    11e4 <cdrom_exec_cmd+0xa4>
mov    -0x2c(%rbp),%eax
sub    $0x6,%eax
je     1201 <cdrom_exec_cmd+0xc1>
jmp    120d <cdrom_exec_cmd+0xcd>
movl   $0x1,-0x4(%rbp)
jmp    1214 <cdrom_exec_cmd+0xd4>
movl   $0x2,-0x4(%rbp)
jmp    1214 <cdrom_exec_cmd+0xd4>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdrom_exec_cmd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
call   1050 <gdc_req_cmd@plt>
mov    %eax,%ebx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <gdc_exec_server@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <gdc_get_cmd_stat@plt>
cmp    $0x1,%eax
je     1150 <cdrom_exec_cmd+0x20>
test   %eax,%eax
je     117b <cdrom_exec_cmd+0x4b>
cmp    $0x2,%eax
je     1182 <cdrom_exec_cmd+0x52>
cmp    $0x3,%eax
jne    1186 <cdrom_exec_cmd+0x56>
mov    $0x4,%eax
jmp    119f <cdrom_exec_cmd+0x6f>
mov    $0x5,%eax
jmp    119f <cdrom_exec_cmd+0x6f>
xor    %eax,%eax
jmp    119f <cdrom_exec_cmd+0x6f>
mov    (%rsp),%eax
xor    %ecx,%ecx
cmp    $0x6,%eax
sete   %cl
xor    $0x3,%ecx
cmp    $0x2,%eax
mov    $0x1,%eax
cmovne %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @cdrom_exec_cmd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [4 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = bitcast [4 x i32]* %6 to i8*
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = call i32 @gdc_req_cmd(i32 %10, i8* %11)
store i32 %12, i32* %7
br label %13
13: ; preds = %18, %2
%14 = call i32 (...) @gdc_exec_server()
%15 = load i32, i32* %7
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%17 = call i32 @gdc_get_cmd_stat(i32 %15, i32* %16)
store i32 %17, i32* %8
br label %18
18: ; preds = %13
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 1
br i1 %20, label %13, label %21
21: ; preds = %18
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 0, i32* %3
br label %39
25: ; preds = %21
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 4, i32* %3
br label %39
29: ; preds = %25
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 5, i32* %3
br label %39
33: ; preds = %29
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%35 = load i32, i32* %34
switch i32 %35, label %38 [
i32 2, label %36
i32 6, label %37
]
36: ; preds = %33
store i32 1, i32* %3
br label %39
37: ; preds = %33
store i32 2, i32* %3
br label %39
38: ; preds = %33
store i32 3, i32* %3
br label %39
39: ; preds = %38, %37, %36, %32, %28, %24
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @cdrom_exec_cmd(i32 %0, i8* %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = tail call i32 @gdc_req_cmd(i32 %0, i8* %1)
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
br label %7
7: ; preds = %7, %2
%8 = call i32 (...) @gdc_exec_server()
%9 = call i32 @gdc_get_cmd_stat(i32 %5, i32* %6)
switch i32 %9, label %10 [
i32 1, label %7
i32 2, label %16
i32 3, label %17
i32 0, label %18
]
10: ; preds = %7
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 6
%13 = select i1 %12, i32 2, i32 3
%14 = icmp eq i32 %11, 2
%15 = select i1 %14, i32 1, i32 %13
br label %18
16: ; preds = %7
br label %18
17: ; preds = %7
br label %18
18: ; preds = %7, %17, %16, %10
%19 = phi i32 [ %15, %10 ], [ 0, %16 ], [ 4, %17 ], [ 5, %7 ]
ret i32 %19
}