#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ TCIOFLUSH;
int avr_open(char *);
int get_rpm(int);
int get_speed(int);
int /*<<< orphan*/ log_time(int /*<<< orphan*/ *, scalar_t__);
int obd_open(char *);
int /*<<< orphan*/ obd_setup(int);
int /*<<< orphan*/ *open_timing_log();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_to_avr(int, int, int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/);
int main() {
  int fd = obd_open("/dev/ttyUSB2");
  int avr_fd = avr_open("/dev/ttyUSB1");
  FILE *timelog = open_timing_log();
  int RPM = 0;
  int speed = 0;
  time_t start, end;
  obd_setup(fd);
  printf("Beginning read cycle...\n");
  while (true) {
    start = time(0);
    RPM = get_rpm(fd);
    end = time(0);
    log_time(timelog, end - start);
    speed = get_speed(fd);
    if ((RPM != -1) && (speed != -1)) {
      send_to_avr(avr_fd, speed, RPM);
      printf("RPM: %d\nSpeed: %d\n", RPM, speed);
    }
    tcflush(fd, TCIOFLUSH);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe3a(%rip),%rdi
call   1050 <obd_open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe38(%rip),%rdi
call   10d0 <avr_open@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <open_timing_log@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <obd_setup@plt>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   10a0 <get_rpm@plt>
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   10b0 <log_time@plt>
mov    -0x8(%rbp),%edi
call   1060 <get_speed@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     127f <main+0xcf>
cmpl   $0xffffffff,-0x20(%rbp)
je     127f <main+0xcf>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <send_to_avr@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   1080 <tcflush@plt>
jmp    120c <main+0x5c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe2e(%rip),%rdi
call   1060 <obd_open@plt>
mov    %eax,%r13d
lea    0xe2c(%rip),%rdi
call   10e0 <avr_open@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1080 <open_timing_log@plt>
mov    %rax,%r12
mov    %r13d,%edi
call   1050 <obd_setup@plt>
lea    0xe2b(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dd2(%rip),%r15
jmp    121b <main+0x5b>
mov    (%r15),%esi
mov    %r13d,%edi
call   1090 <tcflush@plt>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %rax,%rbx
mov    %r13d,%edi
call   10b0 <get_rpm@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   10d0 <time@plt>
sub    %rbx,%rax
mov    %r12,%rdi
mov    %rax,%rsi
call   10c0 <log_time@plt>
mov    %r13d,%edi
call   1070 <get_speed@plt>
cmp    $0xffffffff,%ebp
je     1210 <main+0x50>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1210 <main+0x50>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <send_to_avr@plt>
lea    0xdaf(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    1210 <main+0x50>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB2\00"
@.str.1 = [13 x i8] c"/dev/ttyUSB1\00"
@.str.2 = [25 x i8] c"Beginning read cycle...\0A\00"
@.str.3 = [19 x i8] c"RPM: %d\0ASpeed: %d\0A\00"
@TCIOFLUSH = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i32 @obd_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %2
%10 = call i32 @avr_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %3
%11 = call i32* (...) @open_timing_log()
store i32* %11, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
%12 = load i32, i32* %2
%13 = call i32 @obd_setup(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %0, %40
%16 = call i64 @time(i32 0)
store i64 %16, i64* %7
%17 = load i32, i32* %2
%18 = call i32 @get_rpm(i32 %17)
store i32 %18, i32* %5
%19 = call i64 @time(i32 0)
store i64 %19, i64* %8
%20 = load i32*, i32** %4
%21 = load i64, i64* %8
%22 = load i64, i64* %7
%23 = sub nsw i64 %21, %22
%24 = call i32 @log_time(i32* %20, i64 %23)
%25 = load i32, i32* %2
%26 = call i32 @get_speed(i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %40
29: ; preds = %15
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i32, i32* %3
%34 = load i32, i32* %6
%35 = load i32, i32* %5
%36 = call i32 @send_to_avr(i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %38)
br label %40
40: ; preds = %32, %29, %15
%41 = load i32, i32* %2
%42 = load i32, i32* @TCIOFLUSH
%43 = call i32 @tcflush(i32 %41, i32 %42)
br label %15
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB2\00"
@.str.1 = [13 x i8] c"/dev/ttyUSB1\00"
@.str.3 = [19 x i8] c"RPM: %d\0ASpeed: %d\0A\00"
@TCIOFLUSH = global i32 0
@str = [24 x i8] c"Beginning read cycle...\00"
define i32 @main() {
%1 = tail call i32 @obd_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @avr_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* (...) @open_timing_log()
%4 = tail call i32 @obd_setup(i32 %1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %19, %0
%7 = tail call i64 @time(i32 0)
%8 = tail call i32 @get_rpm(i32 %1)
%9 = tail call i64 @time(i32 0)
%10 = sub nsw i64 %9, %7
%11 = tail call i32 @log_time(i32* %3, i64 %10)
%12 = tail call i32 @get_speed(i32 %1)
%13 = icmp ne i32 %8, -1
%14 = icmp ne i32 %12, -1
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %19
16: ; preds = %6
%17 = tail call i32 @send_to_avr(i32 %2, i32 %12, i32 %8)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 %12)
br label %19
19: ; preds = %16, %6
%20 = load i32, i32* @TCIOFLUSH
%21 = tail call i32 @tcflush(i32 %1, i32 %20)
br label %6
}