#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*/ bcm2835_spi_transfernb(unsigned char *, unsigned char *,
                                          int);
unsigned int tftglGetTouchRawData16(unsigned int target, unsigned int c) {
  static unsigned char out[3];
  static unsigned char buf[3];
  unsigned int i, ret;
  buf[0] = (0x80 | 0x00 | 0x00 | target | 0x3);
  ret = 0;
  for (i = 0; i < c; i++) {
    bcm2835_spi_transfernb(buf, out, 3);
    ret += (out[1] << 8 | out[2]) >> 3;
  }
  return (ret / c);
}


x86 assembly (clang, -O0):
<tftglGetTouchRawData16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
or     $0x80,%eax
or     $0x3,%eax
mov    %al,0x2efd(%rip)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    118b <tftglGetTouchRawData16+0x7b>
lea    0x2edc(%rip),%rdi
lea    0x2ed2(%rip),%rsi
mov    $0x3,%edx
call   1030 <bcm2835_spi_transfernb@plt>
movzbl 0x2ec2(%rip),%eax
shl    $0x8,%eax
movzbl 0x2eb9(%rip),%ecx
or     %ecx,%eax
sar    $0x3,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <tftglGetTouchRawData16+0x2d>
mov    -0x10(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tftglGetTouchRawData16>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
or     $0x83,%dil
mov    %dil,0x2f06(%rip)
xor    %ebp,%ebp
test   %esi,%esi
je     1166 <tftglGetTouchRawData16+0x56>
lea    0x2ef9(%rip),%r15
lea    0x2eef(%rip),%r12
mov    %r14d,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <bcm2835_spi_transfernb@plt>
movzwl 0x2ed3(%rip),%eax
shl    $0x10,%eax
bswap  %eax
shr    $0x3,%eax
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1140 <tftglGetTouchRawData16+0x30>
mov    %ebp,%eax
xor    %edx,%edx
div    %r14d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tftglGetTouchRawData16.out = internal global [3 x i8] zeroinitializer
@tftglGetTouchRawData16.buf = internal global [3 x i8] zeroinitializer
define i32 @tftglGetTouchRawData16(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = or i32 128, %7
%9 = or i32 %8, 3
%10 = trunc i32 %9 to i8
store i8 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.buf, i64 0, i64 0)
store i32 0, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = call i32 @bcm2835_spi_transfernb(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.out, i64 0, i64 0), i32 3)
%17 = load i8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.out, i64 0, i64 1)
%18 = zext i8 %17 to i32
%19 = shl i32 %18, 8
%20 = load i8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.out, i64 0, i64 2)
%21 = zext i8 %20 to i32
%22 = or i32 %19, %21
%23 = ashr i32 %22, 3
%24 = load i32, i32* %6
%25 = add i32 %24, %23
store i32 %25, i32* %6
br label %26
26: ; preds = %15
%27 = load i32, i32* %5
%28 = add i32 %27, 1
store i32 %28, i32* %5
br label %11
29: ; preds = %11
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = udiv i32 %30, %31
ret i32 %32
}

LLVM IR (-O2):
@tftglGetTouchRawData16.out = internal global [3 x i8] zeroinitializer
@tftglGetTouchRawData16.buf = internal global [3 x i8] zeroinitializer
define i32 @tftglGetTouchRawData16(i32 %0, i32 %1) {
%3 = trunc i32 %0 to i8
%4 = or i8 %3, -125
store i8 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.buf, i64 0, i64 0)
%5 = icmp eq i32 %1, 0
br i1 %5, label %20, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %17, %6 ], [ 0, %2 ]
%8 = phi i32 [ %18, %6 ], [ 0, %2 ]
%9 = tail call i32 @bcm2835_spi_transfernb(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.out, i64 0, i64 0), i32 3)
%10 = load i8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.out, i64 0, i64 1)
%11 = zext i8 %10 to i32
%12 = shl nuw nsw i32 %11, 8
%13 = load i8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @tftglGetTouchRawData16.out, i64 0, i64 2)
%14 = zext i8 %13 to i32
%15 = or i32 %12, %14
%16 = lshr i32 %15, 3
%17 = add i32 %16, %7
%18 = add nuw i32 %8, 1
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %6
20: ; preds = %6, %2
%21 = phi i32 [ 0, %2 ], [ %17, %6 ]
%22 = udiv i32 %21, %1
ret i32 %22
}