#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 zgb_hal_tx(unsigned char *, int);
int zgb_tx_data(int data) {
  unsigned char SndPacket[6];
  unsigned short word = (unsigned short)data;
  unsigned char lowbyte = (unsigned char)(word & 0xff);
  unsigned char highbyte = (unsigned char)((word >> 8) & 0xff);
  SndPacket[0] = 0xff;
  SndPacket[1] = 0x55;
  SndPacket[2] = lowbyte;
  SndPacket[3] = ~lowbyte;
  SndPacket[4] = highbyte;
  SndPacket[5] = ~highbyte;
  if (zgb_hal_tx(SndPacket, 6) != 6)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<zgb_tx_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %ax,-0x10(%rbp)
movzwl -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
movzwl -0x10(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x12(%rbp)
movb   $0xff,-0xe(%rbp)
movb   $0x55,-0xd(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0xc(%rbp)
movzbl -0x11(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0xb(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0xa(%rbp)
movzbl -0x12(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x9(%rbp)
lea    -0xe(%rbp),%rdi
mov    $0x6,%esi
call   1030 <zgb_hal_tx@plt>
cmp    $0x6,%eax
je     1188 <zgb_tx_data+0x78>
movl   $0x0,-0x4(%rbp)
jmp    118f <zgb_tx_data+0x7f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zgb_tx_data>:
push   %rax
mov    %edi,%eax
shr    $0x8,%eax
movw   $0x55ff,0x2(%rsp)
mov    %dil,0x4(%rsp)
not    %dil
mov    %dil,0x5(%rsp)
mov    %al,0x6(%rsp)
not    %al
mov    %al,0x7(%rsp)
lea    0x2(%rsp),%rdi
mov    $0x6,%esi
call   1030 <zgb_hal_tx@plt>
xor    %ecx,%ecx
cmp    $0x6,%eax
sete   %cl
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @zgb_tx_data(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
%5 = alloca i16
%6 = alloca i8
%7 = alloca i8
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = trunc i32 %8 to i16
store i16 %9, i16* %5
%10 = load i16, i16* %5
%11 = zext i16 %10 to i32
%12 = and i32 %11, 255
%13 = trunc i32 %12 to i8
store i8 %13, i8* %6
%14 = load i16, i16* %5
%15 = zext i16 %14 to i32
%16 = ashr i32 %15, 8
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
store i8 %18, i8* %7
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
store i8 -1, i8* %19
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 1
store i8 85, i8* %20
%21 = load i8, i8* %6
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 2
store i8 %21, i8* %22
%23 = load i8, i8* %6
%24 = zext i8 %23 to i32
%25 = xor i32 %24, -1
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
store i8 %26, i8* %27
%28 = load i8, i8* %7
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
store i8 %28, i8* %29
%30 = load i8, i8* %7
%31 = zext i8 %30 to i32
%32 = xor i32 %31, -1
%33 = trunc i32 %32 to i8
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
store i8 %33, i8* %34
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%36 = call i32 @zgb_hal_tx(i8* %35, i32 6)
%37 = icmp ne i32 %36, 6
br i1 %37, label %38, label %39
38: ; preds = %1
store i32 0, i32* %2
br label %40
39: ; preds = %1
store i32 1, i32* %2
br label %40
40: ; preds = %39, %38
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @zgb_tx_data(i32 %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = trunc i32 %0 to i8
%5 = lshr i32 %0, 8
%6 = trunc i32 %5 to i8
store i8 -1, i8* %3
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 1
store i8 85, i8* %7
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 2
store i8 %4, i8* %8
%9 = xor i8 %4, -1
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 3
store i8 %9, i8* %10
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 4
store i8 %6, i8* %11
%12 = xor i8 %6, -1
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 5
store i8 %12, i8* %13
%14 = call i32 @zgb_hal_tx(i8* %3, i32 6)
%15 = icmp eq i32 %14, 6
%16 = zext i1 %15 to i32
ret i32 %16
}