#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 cdops_exec_cmd(int, int /*<<< orphan*/);
int gdGdcChangeDataType(unsigned int *);
int /*<<< orphan*/ gdGdcGetDrvStat(unsigned int *);
int cdops_init_drive() {
  int i, r = 0;
  unsigned int param[4];
  int cdxa;
  for (i = 0; i < 8; i++)
    if (!(r = cdops_exec_cmd(24, 0)))
      break;
  if (r)
    return r;
  gdGdcGetDrvStat(param);
  cdxa = (param[1] == 32);
  param[0] = 0;
  param[1] = 8192;
  param[2] = (cdxa ? 2048 : 1024);
  param[3] = 2048;
  return gdGdcChangeDataType(param);
}


x86 assembly (clang, -O0):
<cdops_init_drive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1180 <cdops_init_drive+0x50>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    116d <cdops_init_drive+0x3d>
jmp    1180 <cdops_init_drive+0x50>
jmp    1172 <cdops_init_drive+0x42>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <cdops_init_drive+0x16>
cmpl   $0x0,-0xc(%rbp)
je     1195 <cdops_init_drive+0x65>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <cdops_init_drive+0xb4>
lea    -0x20(%rbp),%rdi
call   1050 <gdGdcGetDrvStat@plt>
cmpl   $0x20,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x2000,-0x1c(%rbp)
mov    -0x24(%rbp),%edx
mov    $0x400,%eax
mov    $0x800,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x800,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <gdGdcChangeDataType@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdops_init_drive>:
push   %rbx
sub    $0x10,%rsp
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
je     11b5 <cdops_init_drive+0x85>
mov    $0x18,%edi
xor    %esi,%esi
call   1040 <cdops_exec_cmd@plt>
test   %eax,%eax
jne    11f4 <cdops_init_drive+0xc4>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <gdGdcGetDrvStat@plt>
xor    %eax,%eax
cmpl   $0x20,0x4(%rsp)
sete   %al
movabs $0x200000000000,%rcx
mov    %rcx,(%rsp)
shl    $0xa,%eax
add    $0x400,%eax
mov    %eax,0x8(%rsp)
movl   $0x800,0xc(%rsp)
mov    %rbx,%rdi
call   1030 <gdGdcChangeDataType@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @cdops_init_drive() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4 x i32]
%5 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %2
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call i32 @cdops_exec_cmd(i32 24, i32 0)
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9
br label %17
13: ; preds = %9
br label %14
14: ; preds = %13
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %6
17: ; preds = %12, %6
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32, i32* %3
store i32 %21, i32* %1
br label %39
22: ; preds = %17
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%24 = call i32 @gdGdcGetDrvStat(i32* %23)
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 32
%28 = zext i1 %27 to i32
store i32 %28, i32* %5
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
store i32 0, i32* %29
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
store i32 8192, i32* %30
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 2048, i32 1024
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
store i32 %34, i32* %35
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
store i32 2048, i32* %36
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%38 = call i32 @gdGdcChangeDataType(i32* %37)
store i32 %38, i32* %1
br label %39
39: ; preds = %22, %20
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
define i32 @cdops_init_drive() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %0
%6 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %5
%9 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %8
%12 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %11
%15 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @cdops_exec_cmd(i32 24, i32 0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %0, %5, %8, %11, %14, %17, %20, %23
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%28 = call i32 @gdGdcGetDrvStat(i32* %27)
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 32
store i32 0, i32* %27
store i32 8192, i32* %29
%32 = select i1 %31, i32 2048, i32 1024
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
store i32 %32, i32* %33
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
store i32 2048, i32* %34
%35 = call i32 @gdGdcChangeDataType(i32* %27)
br label %36
36: ; preds = %23, %26
%37 = phi i32 [ %35, %26 ], [ %24, %23 ]
ret i32 %37
}