#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 uint8_t;
struct timeval {
  scalar_t__ tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ delay(int);
int /*<<< orphan*/ delayMicroseconds(int);
int /*<<< orphan*/ digitalWrite(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pinMode(int, int);
int retrieveByte(int);
int /*<<< orphan*/ sensorLowHighWait(int);
int /*<<< orphan*/ setDefaultPriority();
int /*<<< orphan*/ setMaximumPriority();
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
int querySensor(int GPIO, uint8_t results[4]) {
  struct timeval now, then, took;
  uint8_t queryChecksum = 0x00, retrievedBytes[5];
  setMaximumPriority();
  gettimeofday(&then, NULL);
  pinMode(GPIO, 1);
  digitalWrite(GPIO, 0);
  delay(10);
  digitalWrite(GPIO, 1);
  delayMicroseconds(40);
  pinMode(GPIO, 0);
  if (!sensorLowHighWait(GPIO)) {
    return (!(1 == 1));
  }
  for (int byte = 0; byte < 5; ++byte) {
    retrievedBytes[byte] = retrieveByte(GPIO);
    if (byte < 4) {
      results[byte] = retrievedBytes[byte];
      queryChecksum += retrievedBytes[byte];
    }
  }
  queryChecksum &= 0xFF;
  gettimeofday(&now, NULL);
  timersub(&now, &then, &took);
  setDefaultPriority();
  if ((took.tv_sec != 0) || (took.tv_usec > 16000)) {
    return (!(1 == 1));
  }
  return queryChecksum == retrievedBytes[4];
}


x86 assembly (clang, -O0):
<querySensor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
mov    $0x0,%al
call   1090 <setMaximumPriority@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   10a0 <pinMode@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    $0xa,%edi
call   1080 <delay@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    $0x28,%edi
call   1070 <delayMicroseconds@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   10a0 <pinMode@plt>
mov    -0x8(%rbp),%edi
call   1060 <sensorLowHighWait@plt>
cmp    $0x0,%eax
jne    1229 <querySensor+0x89>
movl   $0x0,-0x4(%rbp)
jmp    12ef <querySensor+0x14f>
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jge    128a <querySensor+0xea>
mov    -0x8(%rbp),%edi
call   10b0 <retrieveByte@plt>
mov    %eax,%ecx
movslq -0x64(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
cmpl   $0x4,-0x64(%rbp)
jge    1277 <querySensor+0xd7>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    127c <querySensor+0xdc>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1230 <querySensor+0x90>
mov    -0x44(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x44(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   10c0 <timersub@plt>
mov    $0x0,%al
call   1040 <setDefaultPriority@plt>
cmpq   $0x0,-0x40(%rbp)
jne    12d2 <querySensor+0x132>
cmpl   $0x3e80,-0x38(%rbp)
jle    12de <querySensor+0x13e>
movl   $0x0,-0x4(%rbp)
jmp    12ef <querySensor+0x14f>
mov    -0x44(%rbp),%eax
cmp    -0x50(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<querySensor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <setMaximumPriority@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   10a0 <pinMode@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    $0xa,%edi
call   1080 <delay@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    $0x28,%edi
call   1070 <delayMicroseconds@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   10a0 <pinMode@plt>
mov    %ebp,%edi
call   1060 <sensorLowHighWait@plt>
test   %eax,%eax
je     12a8 <querySensor+0x108>
mov    %ebp,%edi
call   10b0 <retrieveByte@plt>
mov    %eax,0x4(%rsp)
mov    %eax,(%rbx)
mov    %ebp,%edi
call   10b0 <retrieveByte@plt>
mov    %eax,%r12d
mov    %eax,0x4(%rbx)
mov    %ebp,%edi
call   10b0 <retrieveByte@plt>
mov    %eax,%r13d
mov    %eax,0x8(%rbx)
mov    %ebp,%edi
call   10b0 <retrieveByte@plt>
mov    %eax,%r15d
mov    %eax,0xc(%rbx)
mov    %ebp,%edi
call   10b0 <retrieveByte@plt>
mov    %eax,%ebx
xor    %r14d,%r14d
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   10c0 <timersub@plt>
xor    %eax,%eax
call   1040 <setDefaultPriority@plt>
cmpq   $0x0,0x8(%rsp)
jne    12a8 <querySensor+0x108>
cmpl   $0x3e80,0x10(%rsp)
jg     12a8 <querySensor+0x108>
add    0x4(%rsp),%r12d
add    %r12d,%r13d
add    %r13d,%r15d
movzbl %r15b,%eax
xor    %r14d,%r14d
cmp    %ebx,%eax
sete   %r14b
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define i32 @querySensor(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca [5 x i32]
%11 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %9
%12 = call i32 (...) @setMaximumPriority()
%13 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%14 = load i32, i32* %4
%15 = call i32 @pinMode(i32 %14, i32 1)
%16 = load i32, i32* %4
%17 = call i32 @digitalWrite(i32 %16, i32 0)
%18 = call i32 @delay(i32 10)
%19 = load i32, i32* %4
%20 = call i32 @digitalWrite(i32 %19, i32 1)
%21 = call i32 @delayMicroseconds(i32 40)
%22 = load i32, i32* %4
%23 = call i32 @pinMode(i32 %22, i32 0)
%24 = load i32, i32* %4
%25 = call i32 @sensorLowHighWait(i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %2
store i32 0, i32* %3
br label %79
28: ; preds = %2
store i32 0, i32* %11
br label %29
29: ; preds = %56, %28
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 5
br i1 %31, label %32, label %59
32: ; preds = %29
%33 = load i32, i32* %4
%34 = call i32 @retrieveByte(i32 %33)
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %10, i64 0, i64 %36
store i32 %34, i32* %37
%38 = load i32, i32* %11
%39 = icmp slt i32 %38, 4
br i1 %39, label %40, label %55
40: ; preds = %32
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [5 x i32], [5 x i32]* %10, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32*, i32** %5
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [5 x i32], [5 x i32]* %10, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = load i32, i32* %9
%54 = add nsw i32 %53, %52
store i32 %54, i32* %9
br label %55
55: ; preds = %40, %32
br label %56
56: ; preds = %55
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %29
59: ; preds = %29
%60 = load i32, i32* %9
%61 = and i32 %60, 255
store i32 %61, i32* %9
%62 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%63 = call i32 @timersub(%struct.timeval* %6, %struct.timeval* %7, %struct.timeval* %8)
%64 = call i32 (...) @setDefaultPriority()
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%66 = load i64, i64* %65
%67 = icmp ne i64 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %59
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%70 = load i32, i32* %69
%71 = icmp sgt i32 %70, 16000
br i1 %71, label %72, label %73
72: ; preds = %68, %59
store i32 0, i32* %3
br label %79
73: ; preds = %68
%74 = load i32, i32* %9
%75 = getelementptr inbounds [5 x i32], [5 x i32]* %10, i64 0, i64 4
%76 = load i32, i32* %75
%77 = icmp eq i32 %74, %76
%78 = zext i1 %77 to i32
store i32 %78, i32* %3
br label %79
79: ; preds = %73, %72, %27
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define i32 @querySensor(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = tail call i32 (...) @setMaximumPriority()
%10 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%11 = tail call i32 @pinMode(i32 %0, i32 1)
%12 = tail call i32 @digitalWrite(i32 %0, i32 0)
%13 = tail call i32 @delay(i32 10)
%14 = tail call i32 @digitalWrite(i32 %0, i32 1)
%15 = tail call i32 @delayMicroseconds(i32 40)
%16 = tail call i32 @pinMode(i32 %0, i32 0)
%17 = tail call i32 @sensorLowHighWait(i32 %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %45, label %19
19: ; preds = %2
%20 = tail call i32 @retrieveByte(i32 %0)
store i32 %20, i32* %1
%21 = tail call i32 @retrieveByte(i32 %0)
%22 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %21, i32* %22
%23 = tail call i32 @retrieveByte(i32 %0)
%24 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %23, i32* %24
%25 = tail call i32 @retrieveByte(i32 %0)
%26 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %25, i32* %26
%27 = tail call i32 @retrieveByte(i32 %0)
%28 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%29 = call i32 @timersub(%struct.timeval* %3, %struct.timeval* %4, %struct.timeval* %5)
%30 = call i32 (...) @setDefaultPriority()
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%32 = load i64, i64* %31
%33 = icmp ne i64 %32, 0
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%35 = load i32, i32* %34
%36 = icmp sgt i32 %35, 16000
%37 = select i1 %33, i1 true, i1 %36
br i1 %37, label %45, label %38
38: ; preds = %19
%39 = add nsw i32 %21, %20
%40 = add nsw i32 %23, %39
%41 = add nsw i32 %25, %40
%42 = and i32 %41, 255
%43 = icmp eq i32 %42, %27
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %19, %2, %38
%46 = phi i32 [ %44, %38 ], [ 0, %2 ], [ 0, %19 ]
ret i32 %46
}