#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 */
char spi_tx(int);
char spi_sendpack(unsigned char a, unsigned int data) {
  spi_tx(a);
  spi_tx((data >> 24) & 0xff);
  spi_tx((data >> 16) & 0xff);
  spi_tx((data >> 8) & 0xff);
  spi_tx(data & 0xff);
  char ret = spi_tx(0x00);
  while (ret == 0xff)
    ret = spi_tx(0xff);
  return ret;
}


x86 assembly (clang, -O0):
<spi_sendpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
movzbl -0x1(%rbp),%edi
call   1030 <spi_tx@plt>
mov    -0x8(%rbp),%edi
shr    $0x18,%edi
and    $0xff,%edi
call   1030 <spi_tx@plt>
mov    -0x8(%rbp),%edi
shr    $0x10,%edi
and    $0xff,%edi
call   1030 <spi_tx@plt>
mov    -0x8(%rbp),%edi
shr    $0x8,%edi
and    $0xff,%edi
call   1030 <spi_tx@plt>
mov    -0x8(%rbp),%edi
and    $0xff,%edi
call   1030 <spi_tx@plt>
xor    %edi,%edi
call   1030 <spi_tx@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xff,%eax
jne    1196 <spi_sendpack+0x86>
mov    $0xff,%edi
call   1030 <spi_tx@plt>
mov    %al,-0x9(%rbp)
jmp    1175 <spi_sendpack+0x65>
movsbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_sendpack>:
push   %rbx
mov    %esi,%ebx
call   1030 <spi_tx@plt>
mov    %ebx,%eax
shr    $0x18,%eax
mov    %eax,%edi
call   1030 <spi_tx@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
call   1030 <spi_tx@plt>
movzbl %bh,%edi
call   1030 <spi_tx@plt>
movzbl %bl,%edi
call   1030 <spi_tx@plt>
xor    %edi,%edi
pop    %rbx
jmp    1030 <spi_tx@plt>

LLVM IR (-O0):
define signext i8 @spi_sendpack(i8 zeroext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8
store i8 %0, i8* %3
store i32 %1, i32* %4
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = call signext i8 @spi_tx(i32 %7)
%9 = load i32, i32* %4
%10 = lshr i32 %9, 24
%11 = and i32 %10, 255
%12 = call signext i8 @spi_tx(i32 %11)
%13 = load i32, i32* %4
%14 = lshr i32 %13, 16
%15 = and i32 %14, 255
%16 = call signext i8 @spi_tx(i32 %15)
%17 = load i32, i32* %4
%18 = lshr i32 %17, 8
%19 = and i32 %18, 255
%20 = call signext i8 @spi_tx(i32 %19)
%21 = load i32, i32* %4
%22 = and i32 %21, 255
%23 = call signext i8 @spi_tx(i32 %22)
%24 = call signext i8 @spi_tx(i32 0)
store i8 %24, i8* %5
br label %25
25: ; preds = %29, %2
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 255
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call signext i8 @spi_tx(i32 255)
store i8 %30, i8* %5
br label %25
31: ; preds = %25
%32 = load i8, i8* %5
ret i8 %32
}

LLVM IR (-O2):
define signext i8 @spi_sendpack(i8 zeroext %0, i32 %1) {
%3 = zext i8 %0 to i32
%4 = tail call signext i8 @spi_tx(i32 %3)
%5 = lshr i32 %1, 24
%6 = tail call signext i8 @spi_tx(i32 %5)
%7 = lshr i32 %1, 16
%8 = and i32 %7, 255
%9 = tail call signext i8 @spi_tx(i32 %8)
%10 = lshr i32 %1, 8
%11 = and i32 %10, 255
%12 = tail call signext i8 @spi_tx(i32 %11)
%13 = and i32 %1, 255
%14 = tail call signext i8 @spi_tx(i32 %13)
%15 = tail call signext i8 @spi_tx(i32 0)
ret i8 %15
}