#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 /*<<< orphan*/ spi_emit_buf(unsigned char *, int);
int /*<<< orphan*/ spi_emit_buf_reverse(char const *, unsigned int);
void spi_emit_data(unsigned addr, const char *buf, unsigned len) {
  unsigned char otmp[3];
  if (len < 4 || len > 128)
    return;
  len /= 4;
  otmp[0] = (len - 1) | 0xE0;
  otmp[1] = (addr >> 8) & 0xFF;
  otmp[2] = addr & 0xFF;
  spi_emit_buf(otmp, 3);
  spi_emit_buf_reverse(buf, len * 4);
}


x86 assembly (clang, -O0):
<spi_emit_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jb     1149 <spi_emit_data+0x29>
cmpl   $0x80,-0x14(%rbp)
jbe    114e <spi_emit_data+0x2e>
jmp    119b <spi_emit_data+0x7b>
mov    -0x14(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
or     $0xe0,%eax
mov    %al,-0x17(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x16(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x15(%rbp)
lea    -0x17(%rbp),%rdi
mov    $0x3,%esi
call   1040 <spi_emit_buf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x2,%esi
call   1030 <spi_emit_buf_reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_emit_data>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
lea    -0x81(%rbx),%ecx
cmp    $0xffffff83,%ecx
jb     1169 <spi_emit_data+0x49>
mov    %rsi,%r14
mov    %edi,%eax
mov    %ebx,%ecx
shr    $0x2,%cl
add    $0xff,%cl
or     $0xe0,%cl
mov    %cl,0x5(%rsp)
mov    %ah,0x6(%rsp)
mov    %al,0x7(%rsp)
lea    0x5(%rsp),%rdi
mov    $0x3,%esi
call   1040 <spi_emit_buf@plt>
and    $0xfffffffc,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <spi_emit_buf_reverse@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @spi_emit_data(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [3 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp ult i32 %8, 4
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %6
%12 = icmp ugt i32 %11, 128
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %37
14: ; preds = %10
%15 = load i32, i32* %6
%16 = udiv i32 %15, 4
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sub i32 %17, 1
%19 = or i32 %18, 224
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
store i8 %20, i8* %21
%22 = load i32, i32* %4
%23 = lshr i32 %22, 8
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
store i8 %25, i8* %26
%27 = load i32, i32* %4
%28 = and i32 %27, 255
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 2
store i8 %29, i8* %30
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%32 = call i32 @spi_emit_buf(i8* %31, i32 3)
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = mul i32 %34, 4
%36 = call i32 @spi_emit_buf_reverse(i8* %33, i32 %35)
br label %37
37: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
define void @spi_emit_data(i32 %0, i8* %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = add i32 %2, -129
%7 = icmp ult i32 %6, -125
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = trunc i32 %2 to i8
%10 = lshr i8 %9, 2
%11 = add nuw nsw i8 %10, 31
%12 = or i8 %11, -32
store i8 %12, i8* %5
%13 = lshr i32 %0, 8
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 %14, i8* %15
%16 = trunc i32 %0 to i8
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 %16, i8* %17
%18 = call i32 @spi_emit_buf(i8* %5, i32 3)
%19 = and i32 %2, -4
%20 = call i32 @spi_emit_buf_reverse(i8* %1, i32 %19)
br label %21
21: ; preds = %3, %8
ret void
}