#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*/ EXIT_FAILURE;
int avr_open(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send_to_avr(int, int, int);
int main() {
  printf("Starting AVR testing program\n");
  int avr_fd = avr_open("/dev/ttyUSB1");
  int speed = 0, RPM = 0;
  if (avr_fd <= 0) {
    perror("Unable to connect to the AVR");
    exit(EXIT_FAILURE);
  }
  while ("forever") {
    if (speed != 110)
      ++speed;
    else
      speed = 0;
    if (RPM != 65500)
      RPM += 100;
    else
      RPM = 0;
    send_to_avr(avr_fd, speed, RPM);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
call   1050 <avr_open@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     11ac <main+0x5c>
lea    0xe92(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11b1 <main+0x61>
cmpl   $0x6e,-0xc(%rbp)
je     11c9 <main+0x79>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d0 <main+0x80>
movl   $0x0,-0xc(%rbp)
cmpl   $0xffdc,-0x10(%rbp)
je     11eb <main+0x9b>
mov    -0x10(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x10(%rbp)
jmp    11f2 <main+0xa2>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <send_to_avr@plt>
jmp    11b1 <main+0x61>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
lea    0xe96(%rip),%rdi
call   1050 <avr_open@plt>
test   %eax,%eax
jle    11a8 <main+0x58>
mov    %eax,%r14d
xor    %r15d,%r15d
xor    %ecx,%ecx
xor    %eax,%eax
nopl   (%rax)
lea    0x1(%rcx),%ebp
cmp    $0x6e,%ecx
cmove  %r15d,%ebp
lea    0x64(%rax),%ebx
cmp    $0xffdc,%eax
cmove  %r15d,%ebx
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <send_to_avr@plt>
mov    %ebp,%ecx
mov    %ebx,%eax
jmp    1180 <main+0x30>
lea    0xe5e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Starting AVR testing program\0A\00"
@.str.1 = [13 x i8] c"/dev/ttyUSB1\00"
@.str.2 = [29 x i8] c"Unable to connect to the AVR\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [8 x i8] c"forever\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @avr_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 %6, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %13, %28
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 110
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %21
20: ; preds = %14
store i32 0, i32* %3
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 65500
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 100
store i32 %26, i32* %4
br label %28
27: ; preds = %21
store i32 0, i32* %4
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @send_to_avr(i32 %29, i32 %30, i32 %31)
br label %14
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"/dev/ttyUSB1\00"
@.str.2 = [29 x i8] c"Unable to connect to the AVR\00"
@EXIT_FAILURE = global i32 0
@str = [29 x i8] c"Starting AVR testing program\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 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 = icmp slt i32 %2, 1
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0, %8
%9 = phi i32 [ %13, %8 ], [ 0, %0 ]
%10 = phi i32 [ %16, %8 ], [ 0, %0 ]
%11 = icmp eq i32 %9, 110
%12 = add nsw i32 %9, 1
%13 = select i1 %11, i32 0, i32 %12
%14 = icmp eq i32 %10, 65500
%15 = add nsw i32 %10, 100
%16 = select i1 %14, i32 0, i32 %15
%17 = tail call i32 @send_to_avr(i32 %2, i32 %13, i32 %16)
br label %8
}