#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_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ read_line(int);
int serialport_init(char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_line(int, char *);
int main(int argc, char *argv[]) {
  int fd = serialport_init("/dev/ttyACM0", 9600);
  read_line(fd);
  int count = 0;
  while (1) {
    count++;
    usleep(50 * 1000);
    if (count > 20)
      write_line(fd, "ping\r");
    read_line(fd);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x2580,%esi
call   1030 <serialport_init@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <read_line@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    $0xc350,%edi
call   1060 <usleep@plt>
cmpl   $0x14,-0x18(%rbp)
jle    11a5 <main+0x65>
mov    -0x14(%rbp),%edi
lea    0xe6d(%rip),%rsi
call   1050 <write_line@plt>
mov    -0x14(%rbp),%edi
call   1040 <read_line@plt>
jmp    1179 <main+0x39>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
mov    $0x2580,%esi
call   1030 <serialport_init@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
lea    0xead(%rip),%r14
jmp    1173 <main+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %ebx,%edi
call   1040 <read_line@plt>
mov    $0xc350,%edi
call   1060 <usleep@plt>
cmp    $0x14,%ebp
jb     1170 <main+0x30>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <write_line@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.1 = [6 x i8] c"ping\0D\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @serialport_init(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 9600)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = call i32 @read_line(i32 %9)
store i32 0, i32* %7
br label %11
11: ; preds = %2, %20
%12 = load i32, i32* %7
%13 = add nsw i32 %12, 1
store i32 %13, i32* %7
%14 = call i32 @usleep(i32 50000)
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, 20
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %6
%19 = call i32 @write_line(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %11
%21 = load i32, i32* %6
%22 = call i32 @read_line(i32 %21)
br label %11
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.1 = [6 x i8] c"ping\0D\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @serialport_init(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 9600)
br label %4
4: ; preds = %12, %2
%5 = phi i32 [ 0, %2 ], [ %7, %12 ]
%6 = tail call i32 @read_line(i32 %3)
%7 = add nuw nsw i32 %5, 1
%8 = tail call i32 @usleep(i32 50000)
%9 = icmp ugt i32 %5, 19
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @write_line(i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
br label %4
}