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


x86 assembly (clang, -O0):
<tftglGetTouchRawData8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
or     $0x84,%eax
or     $0x3,%eax
mov    %al,0x2efc(%rip)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    117c <tftglGetTouchRawData8+0x6c>
lea    0x2edb(%rip),%rdi
lea    0x2ed2(%rip),%rsi
mov    $0x2,%edx
call   1030 <bcm2835_spi_transfernb@plt>
movzbl 0x2ec2(%rip),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <tftglGetTouchRawData8+0x2d>
mov    -0x10(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tftglGetTouchRawData8>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
or     $0x87,%dil
mov    %dil,0x2f05(%rip)
xor    %ebp,%ebp
test   %esi,%esi
je     115e <tftglGetTouchRawData8+0x4e>
lea    0x2ef8(%rip),%r15
lea    0x2eef(%rip),%r12
mov    %r14d,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <bcm2835_spi_transfernb@plt>
movzbl 0x2ed3(%rip),%eax
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1140 <tftglGetTouchRawData8+0x30>
mov    %ebp,%eax
xor    %edx,%edx
div    %r14d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tftglGetTouchRawData8.out = internal global [2 x i8] zeroinitializer
@tftglGetTouchRawData8.buf = internal global [2 x i8] zeroinitializer
define i32 @tftglGetTouchRawData8(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 132, %7
%9 = or i32 %8, 3
%10 = trunc i32 %9 to i8
store i8 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @tftglGetTouchRawData8.buf, i64 0, i64 0)
store i32 0, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %21, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = call i32 @bcm2835_spi_transfernb(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @tftglGetTouchRawData8.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @tftglGetTouchRawData8.out, i64 0, i64 0), i32 2)
%17 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @tftglGetTouchRawData8.out, i64 0, i64 1)
%18 = zext i8 %17 to i32
%19 = load i32, i32* %6
%20 = add i32 %19, %18
store i32 %20, i32* %6
br label %21
21: ; preds = %15
%22 = load i32, i32* %5
%23 = add i32 %22, 1
store i32 %23, i32* %5
br label %11
24: ; preds = %11
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = udiv i32 %25, %26
ret i32 %27
}

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