#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 */
typedef int /*<<< orphan*/ command;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int write(int, unsigned char *, int);
int maestroSetTarget(int fd, unsigned char channel, unsigned short target) {
  unsigned char command[] = {0x84, channel, target & 0x7F, target >> 7 & 0x7F};
  if (write(fd, command, sizeof(command)) == -1) {
    perror("error writing");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<maestroSetTarget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dx,%ax
mov    %sil,%cl
mov    %edi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %ax,-0xc(%rbp)
movb   $0x84,-0x10(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0xf(%rbp)
movzwl -0xc(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0xe(%rbp)
movzwl -0xc(%rbp),%eax
sar    $0x7,%eax
and    $0x7f,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    118b <maestroSetTarget+0x6b>
lea    0xe86(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <maestroSetTarget+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maestroSetTarget>:
push   %rax
movb   $0x84,0x4(%rsp)
mov    %sil,0x5(%rsp)
mov    %edx,%eax
and    $0x7f,%al
mov    %al,0x6(%rsp)
shr    $0x7,%edx
and    $0x7f,%dl
mov    %dl,0x7(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1157 <maestroSetTarget+0x37>
pop    %rcx
ret
lea    0xea2(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"error writing\00"
define i32 @maestroSetTarget(i32 %0, i8 zeroext %1, i16 zeroext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i16
%8 = alloca [4 x i8]
store i32 %0, i32* %5
store i8 %1, i8* %6
store i16 %2, i16* %7
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
store i8 -124, i8* %9
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %6
store i8 %11, i8* %10
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = load i16, i16* %7
%14 = zext i16 %13 to i32
%15 = and i32 %14, 127
%16 = trunc i32 %15 to i8
store i8 %16, i8* %12
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = load i16, i16* %7
%19 = zext i16 %18 to i32
%20 = ashr i32 %19, 7
%21 = and i32 %20, 127
%22 = trunc i32 %21 to i8
store i8 %22, i8* %17
%23 = load i32, i32* %5
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%25 = call i32 @write(i32 %23, i8* %24, i32 4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %3
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %30
29: ; preds = %3
store i32 0, i32* %4
br label %30
30: ; preds = %29, %27
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"error writing\00"
define i32 @maestroSetTarget(i32 %0, i8 zeroext %1, i16 zeroext %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 -124, i8* %5
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %1, i8* %6
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%8 = trunc i16 %2 to i8
%9 = and i8 %8, 127
store i8 %9, i8* %7
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%11 = lshr i16 %2, 7
%12 = trunc i16 %11 to i8
%13 = and i8 %12, 127
store i8 %13, i8* %10
%14 = call i32 @write(i32 %0, i8* %5, i32 4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %3, %16
%19 = phi i32 [ -1, %16 ], [ 0, %3 ]
ret i32 %19
}