#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 *, int /*<<< orphan*/, char);
void TI_CC_SPIWriteBurstReg(int fd, char addr, char *buffer, char count) {
  uint8_t buf[count + 1];
  uint8_t i = 0;
  buf[0] = (addr | 0x40);
  while (i < count) {
    buf[i + 1] = buffer[i];
    i++;
  }
  CC_SPI_Transfer(fd, buf, 0, count + 1);
}


x86 assembly (clang, -O0):
<TI_CC_SPIWriteBurstReg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x38(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movsbl -0x5(%rbp),%ecx
or     $0x40,%ecx
mov    %cl,(%rax)
movsbl -0x29(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    119d <TI_CC_SPIWriteBurstReg+0x8d>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbq -0x29(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movsbl -0x29(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x29(%rbp),%al
add    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    1163 <TI_CC_SPIWriteBurstReg+0x53>
mov    -0x38(%rbp),%rsi
mov    -0x4(%rbp),%edi
movsbl -0x11(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
movsbl %al,%ecx
call   1030 <CC_SPI_Transfer@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TI_CC_SPIWriteBurstReg>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    %ecx,%r15d
add    $0x1,%r15d
mov    %rsp,%rax
lea    0xf(%r15),%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rax,%rbx
sub    %rdi,%rbx
mov    %rbx,%rsp
neg    %rdi
or     $0x40,%sil
mov    %sil,(%rax,%rdi,1)
test   %cl,%cl
jle    1169 <TI_CC_SPIWriteBurstReg+0x49>
lea    0x1(%rbx),%rdi
movzbl %cl,%eax
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <memcpy@plt>
movsbl %r15b,%ecx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <CC_SPI_Transfer@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @TI_CC_SPIWriteBurstReg(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 i8
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8* %2, i8** %7
store i8 %3, i8* %8
%12 = load i8, i8* %8
%13 = sext i8 %12 to i32
%14 = add nsw i32 %13, 1
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i8, i64 %15
store i64 %15, i64* %10
store i8 0, i8* %11
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = or i32 %19, 64
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %17, i64 0
store i8 %21, i8* %22
br label %23
23: ; preds = %29, %4
%24 = load i8, i8* %11
%25 = sext i8 %24 to i32
%26 = load i8, i8* %8
%27 = sext i8 %26 to i32
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %42
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = load i8, i8* %11
%32 = sext i8 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = load i8, i8* %11
%36 = sext i8 %35 to i32
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %17, i64 %38
store i8 %34, i8* %39
%40 = load i8, i8* %11
%41 = add i8 %40, 1
store i8 %41, i8* %11
br label %23
42: ; preds = %23
%43 = load i32, i32* %5
%44 = load i8, i8* %8
%45 = sext i8 %44 to i32
%46 = add nsw i32 %45, 1
%47 = trunc i32 %46 to i8
%48 = call i32 @CC_SPI_Transfer(i32 %43, i8* %17, i32 0, i8 signext %47)
%49 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
define void @TI_CC_SPIWriteBurstReg(i32 %0, i8 signext %1, i8* nocapture %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 = or i8 %1, 64
store i8 %9, i8* %8
%10 = icmp sgt i8 %3, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = zext i8 %3 to i64
br label %14
14: ; preds = %11, %4
%15 = trunc i32 %6 to i8
%16 = call i32 @CC_SPI_Transfer(i32 %0, i8* %8, i32 0, i8 signext %15)
ret void
}