#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ CC_SPI_Transfer(int, char *, char *, char);
void TI_CC_SPIReadBurstReg(int fd, char addr, char *buffer, char count) {
  uint8_t txBuf[count + 1];
  uint8_t rxBuf[count + 1];
  uint8_t i = 0;
  txBuf[0] = (addr | 0xC0);
  while (i < count) {
    txBuf[i + 1] = 0;
    i++;
  }
  CC_SPI_Transfer(fd, txBuf, rxBuf, count + 1);
  i = 0;
  while (i < count) {
    buffer[i] = rxBuf[i + 1];
    i++;
  }
}


x86 assembly (clang, -O0):
<TI_CC_SPIReadBurstReg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cl,%al
mov    %sil,%cl
mov    %edi,-0x4(%rbp)
mov    %cl,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x48(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
movsbl -0x11(%rbp),%ecx
add    $0x1,%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
movsbl -0x5(%rbp),%ecx
or     $0xc0,%ecx
mov    %cl,(%rax)
movsbl -0x31(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    11b8 <TI_CC_SPIReadBurstReg+0xa8>
mov    -0x48(%rbp),%rax
movsbl -0x31(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    1189 <TI_CC_SPIReadBurstReg+0x79>
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rsi
mov    -0x4(%rbp),%edi
movsbl -0x11(%rbp),%eax
add    $0x1,%eax
movsbl %al,%ecx
call   1030 <CC_SPI_Transfer@plt>
movb   $0x0,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    1210 <TI_CC_SPIReadBurstReg+0x100>
mov    -0x40(%rbp),%rax
movsbl -0x31(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movsbq -0x31(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    11d6 <TI_CC_SPIReadBurstReg+0xc6>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TI_CC_SPIReadBurstReg>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
add    $0x1,%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
or     $0xc0,%sil
mov    %sil,(%rbx)
test   %cl,%cl
jle    11aa <TI_CC_SPIReadBurstReg+0x7a>
mov    %edi,%r15d
lea    0x1(%rbx),%rdi
movzbl %cl,%r13d
xor    %esi,%esi
mov    %rdx,-0x30(%rbp)
mov    %r13,%rdx
call   1030 <memset@plt>
movsbl %r14b,%ecx
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <CC_SPI_Transfer@plt>
add    $0x1,%r12
mov    -0x30(%rbp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
jmp    11b9 <TI_CC_SPIReadBurstReg+0x89>
movsbl %r14b,%ecx
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <CC_SPI_Transfer@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @TI_CC_SPIReadBurstReg(i32 %0, i8 signext %1, i8* %2, i8 signext %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8* %2, i8** %7
store i8 %3, i8* %8
%13 = load i8, i8* %8
%14 = sext i8 %13 to i32
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
%19 = load i8, i8* %8
%20 = sext i8 %19 to i32
%21 = add nsw i32 %20, 1
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %11
store i8 0, i8* %12
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = or i32 %25, 192
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %18, i64 0
store i8 %27, i8* %28
br label %29
29: ; preds = %35, %4
%30 = load i8, i8* %12
%31 = sext i8 %30 to i32
%32 = load i8, i8* %8
%33 = sext i8 %32 to i32
%34 = icmp slt i32 %31, %33
br i1 %34, label %35, label %43
35: ; preds = %29
%36 = load i8, i8* %12
%37 = sext i8 %36 to i32
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %18, i64 %39
store i8 0, i8* %40
%41 = load i8, i8* %12
%42 = add i8 %41, 1
store i8 %42, i8* %12
br label %29
43: ; preds = %29
%44 = load i32, i32* %5
%45 = load i8, i8* %8
%46 = sext i8 %45 to i32
%47 = add nsw i32 %46, 1
%48 = trunc i32 %47 to i8
%49 = call i32 @CC_SPI_Transfer(i32 %44, i8* %18, i8* %23, i8 signext %48)
store i8 0, i8* %12
br label %50
50: ; preds = %56, %43
%51 = load i8, i8* %12
%52 = sext i8 %51 to i32
%53 = load i8, i8* %8
%54 = sext i8 %53 to i32
%55 = icmp slt i32 %52, %54
br i1 %55, label %56, label %69
56: ; preds = %50
%57 = load i8, i8* %12
%58 = sext i8 %57 to i32
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %23, i64 %60
%62 = load i8, i8* %61
%63 = load i8*, i8** %7
%64 = load i8, i8* %12
%65 = sext i8 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 %62, i8* %66
%67 = load i8, i8* %12
%68 = add i8 %67, 1
store i8 %68, i8* %12
br label %50
69: ; preds = %50
%70 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
define void @TI_CC_SPIReadBurstReg(i32 %0, i8 signext %1, i8* nocapture writeonly %2, i8 signext %3) {
%5 = sext i8 %3 to i32
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = alloca i8, i64 %7
%10 = or i8 %1, -64
store i8 %10, i8* %8
%11 = icmp sgt i8 %3, 0
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = trunc i32 %6 to i8
%14 = call i32 @CC_SPI_Transfer(i32 %0, i8* %8, i8* %9, i8 signext %13)
br label %22
15: ; preds = %4
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = zext i8 %3 to i64
%18 = trunc i32 %6 to i8
%19 = call i32 @CC_SPI_Transfer(i32 %0, i8* %8, i8* %9, i8 signext %18)
%20 = getelementptr inbounds i8, i8* %9, i64 1
%21 = zext i8 %3 to i64
br label %22
22: ; preds = %12, %15
ret void
}