#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 */
void getCommand(bool state, int device, int index, char *c) {
  char commandByte, addressByte;
  if (state) {
    if (index == 0) {
      commandByte = 0x84;
    } else {
      commandByte = 0x88;
    }
  } else {
    if (index == 0) {
      commandByte = 0x44;
    } else {
      commandByte = 0x48;
    }
  }
  addressByte = (char)(device << 3);
  switch (index) {
  case 1:
    (1 ? ((addressByte) |= (1UL << (2))) : ((addressByte) &= ~(1UL << (2))));
    break;
  case 2:
    (1 ? ((addressByte) |= (1UL << (1))) : ((addressByte) &= ~(1UL << (1))));
    break;
  case 3:
    (1 ? ((addressByte) |= (1UL << (2))) : ((addressByte) &= ~(1UL << (2))));
    (1 ? ((addressByte) |= (1UL << (1))) : ((addressByte) &= ~(1UL << (1))));
    break;
  }
  c[0] = commandByte;
  c[1] = addressByte;
  c[2] = 5;
}


x86 assembly (clang, -O0):
<getCommand>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1137 <getCommand+0x37>
cmpl   $0x0,-0xc(%rbp)
jne    112e <getCommand+0x2e>
movb   $0x84,-0x19(%rbp)
jmp    1132 <getCommand+0x32>
movb   $0x88,-0x19(%rbp)
jmp    1153 <getCommand+0x53>
cmpl   $0x0,-0xc(%rbp)
jne    114a <getCommand+0x4a>
movb   $0x44,-0x19(%rbp)
jmp    114e <getCommand+0x4e>
movb   $0x48,-0x19(%rbp)
jmp    1153 <getCommand+0x53>
mov    -0x8(%rbp),%al
shl    $0x3,%al
mov    %al,-0x1a(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     1192 <getCommand+0x92>
jmp    1170 <getCommand+0x70>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     11a3 <getCommand+0xa3>
jmp    1181 <getCommand+0x81>
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
je     11b4 <getCommand+0xb4>
jmp    11cc <getCommand+0xcc>
movsbq -0x1a(%rbp),%rax
or     $0x4,%rax
mov    %al,-0x1a(%rbp)
jmp    11cc <getCommand+0xcc>
movsbq -0x1a(%rbp),%rax
or     $0x2,%rax
mov    %al,-0x1a(%rbp)
jmp    11cc <getCommand+0xcc>
movsbq -0x1a(%rbp),%rax
or     $0x4,%rax
mov    %al,-0x1a(%rbp)
movsbq -0x1a(%rbp),%rax
or     $0x2,%rax
mov    %al,-0x1a(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1a(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x5,0x2(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCommand>:
shl    $0x3,%sil
cmp    $0x3,%edx
je     1119 <getCommand+0x19>
cmp    $0x2,%edx
je     111f <getCommand+0x1f>
cmp    $0x1,%edx
jne    1123 <getCommand+0x23>
or     $0x4,%sil
jmp    1123 <getCommand+0x23>
or     $0x6,%sil
jmp    1123 <getCommand+0x23>
or     $0x2,%sil
test   %edx,%edx
setne  %al
shl    $0x2,%al
test   %edi,%edi
mov    $0x44,%edx
mov    $0x84,%edi
cmove  %edx,%edi
add    %al,%dil
mov    %dil,(%rcx)
mov    %sil,0x1(%rcx)
movb   $0x5,0x2(%rcx)
ret

LLVM IR (-O0):
define void @getCommand(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %4
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i8 -124, i8* %9
br label %18
17: ; preds = %13
store i8 -120, i8* %9
br label %18
18: ; preds = %17, %16
br label %25
19: ; preds = %4
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i8 68, i8* %9
br label %24
23: ; preds = %19
store i8 72, i8* %9
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* %6
%27 = shl i32 %26, 3
%28 = trunc i32 %27 to i8
store i8 %28, i8* %10
%29 = load i32, i32* %7
switch i32 %29, label %53 [
i32 1, label %30
i32 2, label %36
i32 3, label %42
]
30: ; preds = %25
%31 = load i8, i8* %10
%32 = sext i8 %31 to i64
%33 = or i64 %32, 4
%34 = trunc i64 %33 to i8
store i8 %34, i8* %10
%35 = sext i8 %34 to i32
br label %53
36: ; preds = %25
%37 = load i8, i8* %10
%38 = sext i8 %37 to i64
%39 = or i64 %38, 2
%40 = trunc i64 %39 to i8
store i8 %40, i8* %10
%41 = sext i8 %40 to i32
br label %53
42: ; preds = %25
%43 = load i8, i8* %10
%44 = sext i8 %43 to i64
%45 = or i64 %44, 4
%46 = trunc i64 %45 to i8
store i8 %46, i8* %10
%47 = sext i8 %46 to i32
%48 = load i8, i8* %10
%49 = sext i8 %48 to i64
%50 = or i64 %49, 2
%51 = trunc i64 %50 to i8
store i8 %51, i8* %10
%52 = sext i8 %51 to i32
br label %53
53: ; preds = %25, %42, %36, %30
%54 = load i8, i8* %9
%55 = load i8*, i8** %8
%56 = getelementptr inbounds i8, i8* %55, i64 0
store i8 %54, i8* %56
%57 = load i8, i8* %10
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i64 1
store i8 %57, i8* %59
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i64 2
store i8 5, i8* %61
ret void
}

LLVM IR (-O2):
define void @getCommand(i32 %0, i32 %1, i32 %2, i8* nocapture writeonly %3) {
%5 = icmp eq i32 %2, 0
%6 = trunc i32 %1 to i8
%7 = shl i8 %6, 3
switch i32 %2, label %14 [
i32 1, label %8
i32 2, label %10
i32 3, label %12
]
8: ; preds = %4
%9 = or i8 %7, 4
br label %14
10: ; preds = %4
%11 = or i8 %7, 2
br label %14
12: ; preds = %4
%13 = or i8 %7, 6
br label %14
14: ; preds = %4, %12, %10, %8
%15 = phi i8 [ %7, %4 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ]
%16 = icmp eq i32 %0, 0
%17 = select i1 %5, i8 68, i8 72
%18 = select i1 %5, i8 -124, i8 -120
%19 = select i1 %16, i8 %17, i8 %18
store i8 %19, i8* %3
%20 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %15, i8* %20
%21 = getelementptr inbounds i8, i8* %3, i64 2
store i8 5, i8* %21
ret void
}