#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(int);
int /*<<< orphan*/ printf(char *, ...);
int ser_autodetect(int);
int ser_flush(int);
int ser_println(int, char *);
int ser_readln(int, char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int main() {
  int tty;
  int reads;
  int retval;
  char buf[1000];
  char *message = "Test";
  tty = ser_autodetect(9600);
  if (tty == -1)
    exit(77);
  sleep(2);
  retval = ser_flush(tty);
  printf("Return value of ser_flush: %i\n", retval);
  printf("Serial I/O flushed\n");
  printf("Print \"%s\" to Arduino\n", message);
  retval = ser_println(tty, message);
  if (retval != 1) {
    printf("Print \"%s\" to arduino failed. Aborting test.", message);
    exit(1);
  }
  printf("\"%s\" printed succesfully to the arduino.\n", message);
  reads = ser_readln(tty, buf);
  if (strcmp(buf, "Test program for testing libarduserial") == 0) {
    printf("Test failed, flush did not work correctly./n");
    exit(1);
  }
  printf("Test pass\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x408(%rbp)
mov    $0x2580,%edi
call   1070 <ser_autodetect@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c1 <main+0x41>
mov    $0x4d,%edi
call   1090 <exit@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
mov    -0x8(%rbp),%edi
call   1030 <ser_flush@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x408(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x408(%rbp),%rsi
call   1040 <ser_println@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     1245 <main+0xc5>
mov    -0x408(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x408(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x400(%rbp),%rsi
call   1080 <ser_readln@plt>
mov    %eax,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12a1 <main+0x121>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    $0x2580,%edi
call   1080 <ser_autodetect@plt>
cmp    $0xffffffff,%eax
je     1252 <main+0xc2>
mov    %eax,%ebx
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    %ebx,%edi
call   1030 <ser_flush@plt>
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xf0f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe41(%rip),%rdi
lea    0xe16(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <ser_println@plt>
cmp    $0x1,%eax
jne    125c <main+0xcc>
lea    0xe5e(%rip),%rdi
lea    0xdef(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <ser_readln@plt>
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     127b <main+0xeb>
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x4d,%edi
call   10a0 <exit@plt>
lea    0xdd8(%rip),%rdi
lea    0xd96(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"Test\00"
@.str.1 = [31 x i8] c"Return value of ser_flush: %i\0A\00"
@.str.2 = [20 x i8] c"Serial I/O flushed\0A\00"
@.str.3 = [23 x i8] c"Print \22%s\22 to Arduino\0A\00"
@.str.4 = [45 x i8] c"Print \22%s\22 to arduino failed. Aborting test.\00"
@.str.5 = [42 x i8] c"\22%s\22 printed succesfully to the arduino.\0A\00"
@.str.6 = [39 x i8] c"Test program for testing libarduserial\00"
@.str.7 = [45 x i8] c"Test failed, flush did not work correctly./n\00"
@.str.8 = [11 x i8] c"Test pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = call i32 @ser_autodetect(i32 9600)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @exit(i32 77)
unreachable
12: ; preds = %0
%13 = call i32 @sleep(i32 2)
%14 = load i32, i32* %2
%15 = call i32 @ser_flush(i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %2
%22 = load i8*, i8** %6
%23 = call i32 @ser_println(i32 %21, i8* %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %30
26: ; preds = %12
%27 = load i8*, i8** %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %12
%31 = load i8*, i8** %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %2
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%35 = call i32 @ser_readln(i32 %33, i8* %34)
store i32 %35, i32* %3
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"Test\00"
@.str.1 = [31 x i8] c"Return value of ser_flush: %i\0A\00"
@.str.3 = [23 x i8] c"Print \22%s\22 to Arduino\0A\00"
@.str.4 = [45 x i8] c"Print \22%s\22 to arduino failed. Aborting test.\00"
@.str.5 = [42 x i8] c"\22%s\22 printed succesfully to the arduino.\0A\00"
@.str.6 = [39 x i8] c"Test program for testing libarduserial\00"
@.str.7 = [45 x i8] c"Test failed, flush did not work correctly./n\00"
@str = [19 x i8] c"Serial I/O flushed\00"
@str.9 = [10 x i8] c"Test pass\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @ser_autodetect(i32 9600)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @exit(i32 77)
unreachable
7: ; preds = %0
%8 = tail call i32 @sleep(i32 2)
%9 = tail call i32 @ser_flush(i32 %3)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @ser_println(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %7
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @ser_readln(i32 %3, i8* %2)
%21 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0))
ret i32 0
}