#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 */
scalar_t__ pi_tty_init();
unsigned int read_gp2y();
int pi_gp2y10_read(int sensor, int sample, float *density) {
  if (pi_tty_init() < 0) {
    return -5;
  }
  float pm25;
  unsigned int data;
  int i, nr_samples;
  pm25 = 0;
  nr_samples = 0;
  for (i = 0; i < sample; i++) {
    data = read_gp2y();
    if (data >= 0)
      nr_samples++;
    else
      data = 0;
    pm25 += data;
  }
  *density = ((pm25 / nr_samples) * 5 * 100 / 1024);
  return 0;
}


x86 assembly (clang, -O0):
<pi_gp2y10_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <pi_tty_init@plt>
cmp    $0x0,%rax
jge    114f <pi_gp2y10_read+0x2f>
movl   $0xfffffffb,-0x4(%rbp)
jmp    11fb <pi_gp2y10_read+0xdb>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ba <pi_gp2y10_read+0x9a>
mov    $0x0,%al
call   1040 <read_gp2y@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jb     1193 <pi_gp2y10_read+0x73>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119a <pi_gp2y10_read+0x7a>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cvtsi2ss %rax,%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <pi_gp2y10_read+0x45>
movss  -0x1c(%rbp),%xmm0
cvtsi2ssl -0x28(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xe38(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe28(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe18(%rip),%xmm1
divss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_gp2y10_read>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
xor    %eax,%eax
call   1030 <pi_tty_init@plt>
test   %rax,%rax
js     119b <pi_gp2y10_read+0x7b>
test   %ebx,%ebx
jle    11a2 <pi_gp2y10_read+0x82>
xorps  %xmm1,%xmm1
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm1,0xc(%rsp)
xor    %eax,%eax
call   1040 <read_gp2y@plt>
movss  0xc(%rsp),%xmm1
mov    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm1
add    $0xffffffff,%ebp
jne    1150 <pi_gp2y10_read+0x30>
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
divss  %xmm0,%xmm1
mulss  0xe7b(%rip),%xmm1
mulss  0xe77(%rip),%xmm1
mulss  0xe73(%rip),%xmm1
jmp    11aa <pi_gp2y10_read+0x8a>
mov    $0xfffffffb,%eax
jmp    11b1 <pi_gp2y10_read+0x91>
movss  0xe56(%rip),%xmm1
movss  %xmm1,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pi_gp2y10_read(i32 %0, i32 %1, float* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float*
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store float* %2, float** %7
%12 = call i64 (...) @pi_tty_init()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -5, i32* %4
br label %45
15: ; preds = %3
store float 0.000000e+00, float* %8
store i32 0, i32* %11
store i32 0, i32* %10
br label %16
16: ; preds = %33, %15
%17 = load i32, i32* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = call i32 (...) @read_gp2y()
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp uge i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %11
%26 = add nsw i32 %25, 1
store i32 %26, i32* %11
br label %28
27: ; preds = %20
store i32 0, i32* %9
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %9
%30 = uitofp i32 %29 to float
%31 = load float, float* %8
%32 = fadd float %31, %30
store float %32, float* %8
br label %33
33: ; preds = %28
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %16
36: ; preds = %16
%37 = load float, float* %8
%38 = load i32, i32* %11
%39 = sitofp i32 %38 to float
%40 = fdiv float %37, %39
%41 = fmul float %40, 5.000000e+00
%42 = fmul float %41, 1.000000e+02
%43 = fdiv float %42, 1.024000e+03
%44 = load float*, float** %7
store float %43, float* %44
store i32 0, i32* %4
br label %45
45: ; preds = %36, %14
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
define i32 @pi_gp2y10_read(i32 %0, i32 %1, float* nocapture writeonly %2) {
%4 = tail call i64 (...) @pi_tty_init()
%5 = icmp slt i64 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %22
8: ; preds = %6, %8
%9 = phi i32 [ %12, %8 ], [ 0, %6 ]
%10 = phi float [ %14, %8 ], [ 0.000000e+00, %6 ]
%11 = tail call i32 (...) @read_gp2y()
%12 = add nuw nsw i32 %9, 1
%13 = uitofp i32 %11 to float
%14 = fadd float %10, %13
%15 = icmp eq i32 %12, %1
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = sitofp i32 %1 to float
%18 = fdiv float %14, %17
%19 = fmul float %18, 5.000000e+00
%20 = fmul float %19, 1.000000e+02
%21 = fmul float %20, 0x3F50000000000000
br label %22
22: ; preds = %16, %6
%23 = phi float [ %21, %16 ], [ 0x7FF8000000000000, %6 ]
store float %23, float* %2
br label %24
24: ; preds = %3, %22
%25 = phi i32 [ 0, %22 ], [ -5, %3 ]
ret i32 %25
}