int ata_prot_to_cmd(int protocol, int lba48) {
  int rcmd;
  int wcmd;
  {
    rcmd = 0;
    wcmd = 0;
    switch (protocol) {
    case 2:
      if (lba48) {
        rcmd = 36;
        wcmd = 52;
      } else {
        rcmd = 32;
        wcmd = 48;
      }
      break;
    case 4:
      if (lba48) {
        rcmd = 37;
        wcmd = 53;
      } else {
        rcmd = 200;
        wcmd = 202;
      }
      break;
    default:;
      return (-1);
    }
    return (rcmd | (wcmd << 8));
  }
}


x86 assembly (clang, -O0):
<ata_prot_to_cmd>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x2,%eax
je     113d <ata_prot_to_cmd+0x3d>
jmp    112c <ata_prot_to_cmd+0x2c>
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
je     116d <ata_prot_to_cmd+0x6d>
jmp    119d <ata_prot_to_cmd+0x9d>
cmpl   $0x0,-0xc(%rbp)
je     115a <ata_prot_to_cmd+0x5a>
movl   $0x24,-0x10(%rbp)
movl   $0x34,-0x14(%rbp)
jmp    1168 <ata_prot_to_cmd+0x68>
movl   $0x20,-0x10(%rbp)
movl   $0x30,-0x14(%rbp)
jmp    11a9 <ata_prot_to_cmd+0xa9>
cmpl   $0x0,-0xc(%rbp)
je     118a <ata_prot_to_cmd+0x8a>
movl   $0x25,-0x10(%rbp)
movl   $0x35,-0x14(%rbp)
jmp    1198 <ata_prot_to_cmd+0x98>
movl   $0xc8,-0x10(%rbp)
movl   $0xca,-0x14(%rbp)
jmp    11a9 <ata_prot_to_cmd+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <ata_prot_to_cmd+0xb7>
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ata_prot_to_cmd>:
cmp    $0x4,%edi
je     1125 <ata_prot_to_cmd+0x25>
mov    $0xffffffff,%eax
cmp    $0x2,%edi
jne    1143 <ata_prot_to_cmd+0x43>
xor    %ecx,%ecx
test   %esi,%esi
setne  %cl
lea    0x20(,%rcx,4),%eax
or     $0xc,%ecx
shl    $0xa,%ecx
jmp    1141 <ata_prot_to_cmd+0x41>
test   %esi,%esi
mov    $0xc8,%ecx
mov    $0x25,%eax
cmove  %ecx,%eax
mov    $0xca00,%edx
mov    $0x3500,%ecx
cmove  %edx,%ecx
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @ata_prot_to_cmd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %4
switch i32 %8, label %21 [
i32 2, label %9
i32 4, label %15
]
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 36, i32* %6
store i32 52, i32* %7
br label %14
13: ; preds = %9
store i32 32, i32* %6
store i32 48, i32* %7
br label %14
14: ; preds = %13, %12
br label %22
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 37, i32* %6
store i32 53, i32* %7
br label %20
19: ; preds = %15
store i32 200, i32* %6
store i32 202, i32* %7
br label %20
20: ; preds = %19, %18
br label %22
21: ; preds = %2
store i32 -1, i32* %3
br label %27
22: ; preds = %20, %14
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = shl i32 %24, 8
%26 = or i32 %23, %25
store i32 %26, i32* %3
br label %27
27: ; preds = %22, %21
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @ata_prot_to_cmd(i32 %0, i32 %1) {
switch i32 %0, label %15 [
i32 2, label %3
i32 4, label %7
]
3: ; preds = %2
%4 = icmp eq i32 %1, 0
%5 = select i1 %4, i32 32, i32 36
%6 = select i1 %4, i32 12288, i32 13312
br label %11
7: ; preds = %2
%8 = icmp eq i32 %1, 0
%9 = select i1 %8, i32 200, i32 37
%10 = select i1 %8, i32 51712, i32 13568
br label %11
11: ; preds = %7, %3
%12 = phi i32 [ %5, %3 ], [ %9, %7 ]
%13 = phi i32 [ %6, %3 ], [ %10, %7 ]
%14 = or i32 %13, %12
br label %15
15: ; preds = %2, %11
%16 = phi i32 [ %14, %11 ], [ -1, %2 ]
ret i32 %16
}