#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*/ sendcmd(int, int);
scalar_t__ sgetc(int);
int /*<<< orphan*/ sputc(unsigned char, int);
int setdrive(unsigned char drive, unsigned char side, int dbldense, int s) {
  unsigned char arg;
  arg = drive & 0x03;
  arg += (side & 0x01) << 2;
  if (dbldense)
    arg += 8;
  sendcmd(1, s);
  sputc(arg, s);
  return sgetc(s) == 0;
}


x86 assembly (clang, -O0):
<setdrive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    %edx,-0x8(%rbp)
mov    %ecx,-0xc(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x3,%eax
mov    %al,-0xd(%rbp)
movzbl -0x2(%rbp),%ecx
and    $0x1,%ecx
shl    $0x2,%ecx
movzbl -0xd(%rbp),%eax
add    %ecx,%eax
mov    %al,-0xd(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     117c <setdrive+0x4c>
movzbl -0xd(%rbp),%eax
add    $0x8,%eax
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
call   1050 <sendcmd@plt>
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%esi
movzbl %al,%edi
call   1030 <sputc@plt>
mov    -0xc(%rbp),%edi
call   1040 <sgetc@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setdrive>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebx
and    $0x3,%dil
shl    $0x2,%sil
and    $0x4,%sil
or     %dil,%sil
lea    0x8(%rsi),%eax
test   %edx,%edx
movzbl %sil,%ecx
movzbl %al,%ebp
cmove  %ecx,%ebp
mov    $0x1,%edi
mov    %ebx,%esi
call   1050 <sendcmd@plt>
movzbl %bpl,%edi
mov    %ebx,%esi
call   1030 <sputc@plt>
mov    %ebx,%edi
call   1040 <sgetc@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @setdrive(i8 zeroext %0, i8 zeroext %1, i32 %2, i32 %3) {
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8 %0, i8* %5
store i8 %1, i8* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8, i8* %5
%11 = zext i8 %10 to i32
%12 = and i32 %11, 3
%13 = trunc i32 %12 to i8
store i8 %13, i8* %9
%14 = load i8, i8* %6
%15 = zext i8 %14 to i32
%16 = and i32 %15, 1
%17 = shl i32 %16, 2
%18 = load i8, i8* %9
%19 = zext i8 %18 to i32
%20 = add nsw i32 %19, %17
%21 = trunc i32 %20 to i8
store i8 %21, i8* %9
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %4
%25 = load i8, i8* %9
%26 = zext i8 %25 to i32
%27 = add nsw i32 %26, 8
%28 = trunc i32 %27 to i8
store i8 %28, i8* %9
br label %29
29: ; preds = %24, %4
%30 = load i32, i32* %8
%31 = call i32 @sendcmd(i32 1, i32 %30)
%32 = load i8, i8* %9
%33 = load i32, i32* %8
%34 = call i32 @sputc(i8 zeroext %32, i32 %33)
%35 = load i32, i32* %8
%36 = call i64 @sgetc(i32 %35)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
ret i32 %38
}

LLVM IR (-O2):
define i32 @setdrive(i8 zeroext %0, i8 zeroext %1, i32 %2, i32 %3) {
%5 = and i8 %0, 3
%6 = shl i8 %1, 2
%7 = and i8 %6, 4
%8 = or i8 %7, %5
%9 = icmp eq i32 %2, 0
%10 = or i8 %8, 8
%11 = select i1 %9, i8 %8, i8 %10
%12 = tail call i32 @sendcmd(i32 1, i32 %3)
%13 = tail call i32 @sputc(i8 zeroext %11, i32 %3)
%14 = tail call i64 @sgetc(i32 %3)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
ret i32 %16
}