#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_sendpackcrc(unsigned char a, unsigned int data, unsigned char crc) {
  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(crc);
  while (ret == 0xff)
    ret = spi_tx(0xff);
  return ret;
}


x86 assembly (clang, -O0):
<spi_sendpackcrc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%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>
movzbl -0x9(%rbp),%edi
call   1030 <spi_tx@plt>
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
cmp    $0xff,%eax
jne    119d <spi_sendpackcrc+0x8d>
mov    $0xff,%edi
call   1030 <spi_tx@plt>
mov    %al,-0xa(%rbp)
jmp    117c <spi_sendpackcrc+0x6c>
movsbl -0xa(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_sendpackcrc>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
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>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <spi_tx@plt>

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

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