#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*/ clearString(char *);
int /*<<< orphan*/ close(int);
int openSerial();
int /*<<< orphan*/ printf(char *, int);
int read(int, unsigned char *, int);
int /*<<< orphan*/ sendCommand(int, char *);
int /*<<< orphan*/ usleep(int);
void init() {
  unsigned char inBuff[128];
  int fd = openSerial();
  int receivedBytes;
  while ((receivedBytes = read(fd, inBuff, 128))) {
    if (receivedBytes && 0)
      printf("Emptied buffer of %d bytes\n", receivedBytes);
  }
  clearString((char *)inBuff);
  usleep(100000);
  sendCommand(fd, ":1:");
  close(fd);
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    $0x0,%al
call   1080 <openSerial@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x80,%edx
call   1070 <read@plt>
mov    %eax,-0x88(%rbp)
cmp    $0x0,%eax
je     11de <init+0x6e>
cmpl   $0x0,-0x88(%rbp)
je     11d9 <init+0x69>
xor    %eax,%eax
test   $0x1,%al
jne    11c7 <init+0x57>
jmp    11d9 <init+0x69>
mov    -0x88(%rbp),%esi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
jmp    1188 <init+0x18>
lea    -0x80(%rbp),%rdi
call   1050 <clearString@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    -0x84(%rbp),%edi
lea    0xe1e(%rip),%rsi
call   1030 <sendCommand@plt>
mov    -0x84(%rbp),%edi
call   1060 <close@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %eax,%eax
call   1070 <openSerial@plt>
mov    %eax,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    1180 <init+0x20>
mov    %rsp,%rdi
call   1040 <clearString@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
lea    0xe54(%rip),%rsi
mov    %ebx,%edi
call   1030 <sendCommand@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Emptied buffer of %d bytes\0A\00"
@.str.1 = [4 x i8] c":1:\00"
define void @init() {
%1 = alloca [128 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @openSerial()
store i32 %4, i32* %2
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* %2
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 128)
store i32 %8, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
br i1 false, label %14, label %17
14: ; preds = %13
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %13, %10
br label %5
18: ; preds = %5
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%20 = call i32 @clearString(i8* %19)
%21 = call i32 @usleep(i32 100000)
%22 = load i32, i32* %2
%23 = call i32 @sendCommand(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = call i32 @close(i32 %24)
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c":1:\00"
define void @init() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @openSerial()
br label %4
4: ; preds = %4, %0
%5 = call i32 @read(i32 %3, i8* %2, i32 128)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %4
7: ; preds = %4
%8 = call i32 @clearString(i8* %2)
%9 = call i32 @usleep(i32 100000)
%10 = call i32 @sendCommand(i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @close(i32 %3)
ret void
}