#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 int ushort;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ msg_send(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
ushort ANT_SendBurstTransfer(unsigned char chan, unsigned char *data,
                             ushort numpkts) {
  unsigned char buf[9];
  int j;
  int seq = 0;
  for (j = 0; j < numpkts; j++) {
    buf[0] = chan | (seq << 5) | (j == numpkts - 1 ? 0x80 : 0);
    memcpy(buf + 1, data + j * 8, 8);
    usleep(20 * 1000);
    msg_send(0x50, buf, 9);
    seq++;
    if (seq > 3)
      seq = 1;
  }
  return numpkts;
}


x86 assembly (clang, -O0):
<ANT_SendBurstTransfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f0 <ANT_SendBurstTransfer+0xc0>
movzbl -0x1(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
xor    %ecx,%ecx
mov    $0x80,%edx
cmp    %edi,%esi
cmove  %edx,%ecx
or     %ecx,%eax
mov    %al,-0x1d(%rbp)
lea    -0x1d(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    $0x4e20,%edi
call   1050 <usleep@plt>
lea    -0x1d(%rbp),%rsi
mov    $0x50,%edi
mov    $0x9,%edx
call   1040 <msg_send@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jle    11dd <ANT_SendBurstTransfer+0xad>
movl   $0x1,-0x28(%rbp)
jmp    11e2 <ANT_SendBurstTransfer+0xb2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <ANT_SendBurstTransfer+0x23>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ANT_SendBurstTransfer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,(%rsp)
test   %edx,%edx
jle    11d7 <ANT_SendBurstTransfer+0xa7>
mov    %rsi,%r13
movzbl %dil,%ebp
mov    (%rsp),%rax
lea    -0x1(%rax),%ebx
mov    %eax,%r14d
shl    $0x3,%rbx
shl    $0x3,%r14
xor    %r15d,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r12d,%eax
shl    $0x5,%eax
or     %ebp,%eax
xor    %ecx,%ecx
cmp    %r15,%rbx
sete   %cl
shl    $0x7,%ecx
or     %eax,%ecx
mov    %cl,0xf(%rsp)
lea    (%r15,%r13,1),%rsi
lea    0x10(%rsp),%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    $0x4e20,%edi
call   1050 <usleep@plt>
mov    $0x50,%edi
lea    0xf(%rsp),%rsi
mov    $0x9,%edx
call   1040 <msg_send@plt>
cmp    $0x3,%r12d
lea    0x1(%r12),%eax
mov    $0x1,%ecx
cmovge %ecx,%eax
add    $0x8,%r15
mov    %eax,%r12d
cmp    %r15,%r14
jne    1170 <ANT_SendBurstTransfer+0x40>
mov    (%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ANT_SendBurstTransfer(i8 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [9 x i8]
%8 = alloca i32
%9 = alloca i32
store i8 %0, i8* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %9
store i32 0, i32* %8
br label %10
10: ; preds = %46, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %49
14: ; preds = %10
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = load i32, i32* %9
%18 = shl i32 %17, 5
%19 = or i32 %16, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = icmp eq i32 %20, %22
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 128, i32 0
%26 = or i32 %19, %25
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
store i8 %27, i8* %28
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8*, i8** %5
%32 = load i32, i32* %8
%33 = mul nsw i32 %32, 8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = call i32 @memcpy(i8* %30, i8* %35, i32 8)
%37 = call i32 @usleep(i32 20000)
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%39 = call i32 @msg_send(i32 80, i8* %38, i32 9)
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp sgt i32 %42, 3
br i1 %43, label %44, label %45
44: ; preds = %14
store i32 1, i32* %9
br label %45
45: ; preds = %44, %14
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %10
49: ; preds = %10
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
define i32 @ANT_SendBurstTransfer(i8 zeroext %0, i8* %1, i32 returned %2) {
%4 = alloca [9 x i8]
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %32
7: ; preds = %3
%8 = zext i8 %0 to i32
%9 = add nsw i32 %2, -1
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 1
%11 = zext i32 %9 to i64
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %7, %13
%14 = phi i64 [ 0, %7 ], [ %30, %13 ]
%15 = phi i32 [ 0, %7 ], [ %29, %13 ]
%16 = shl i32 %15, 5
%17 = or i32 %16, %8
%18 = icmp eq i64 %14, %11
%19 = select i1 %18, i32 128, i32 0
%20 = or i32 %17, %19
%21 = trunc i32 %20 to i8
store i8 %21, i8* %5
%22 = shl nsw i64 %14, 3
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = call i32 @memcpy(i8* %10, i8* %23, i32 8)
%25 = call i32 @usleep(i32 20000)
%26 = call i32 @msg_send(i32 80, i8* %5, i32 9)
%27 = add nsw i32 %15, 1
%28 = icmp sgt i32 %15, 2
%29 = select i1 %28, i32 1, i32 %27
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %13
32: ; preds = %13, %3
ret i32 %2
}