#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_init(char *, int);
int ser_readln(int, char *);
int /*<<< orphan*/ sleep(int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  int charactersAmount;
  char readBuffer[1000];
  int fd;
  printf("Start initialization process\n");
  fd = ser_init("/dev/ttyACM0", 9600);
  sleep(2);
  if (fd == -1) {
    exit(77);
  }
  printf("Arduino initialized\n");
  charactersAmount = ser_readln(fd, readBuffer);
  if (strlen(readBuffer) != charactersAmount) {
    printf("Read string is not 0-terminated.\n");
    exit(1);
  }
  if (charactersAmount != strlen("Test program for testing libarduserial")) {
    printf("Not the correct amount of characters was read [%i]\n",
           charactersAmount);
    printf("\"%s\" read", readBuffer);
    exit(1);
  }
  if (strncmp("Test program for testing libarduserial", readBuffer,
              charactersAmount) != 0) {
    printf("Failed to read the correct string from the arduino.\n");
    printf("\"%s\" was read\n", readBuffer);
    exit(1);
  }
  printf("String read from the arduino was correct.\n");
  printf("\"%s\" was read\n", readBuffer);
  printf("Test: PASS\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe80(%rip),%rdi
mov    $0x2580,%esi
call   1040 <ser_init@plt>
mov    %eax,-0x404(%rbp)
mov    $0x2,%edi
call   1090 <sleep@plt>
cmpl   $0xffffffff,-0x404(%rbp)
jne    11cf <main+0x5f>
mov    $0x4d,%edi
call   1080 <exit@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x404(%rbp),%edi
lea    -0x400(%rbp),%rsi
call   1070 <ser_readln@plt>
mov    %eax,-0x14(%rbp)
lea    -0x400(%rbp),%rdi
call   1050 <strlen@plt>
cmp    -0x14(%rbp),%eax
je     121f <main+0xaf>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x408(%rbp)
lea    0xe33(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x408(%rbp),%eax
cmp    %ecx,%eax
je     1274 <main+0x104>
mov    -0x14(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x400(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xddd(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12c1 <main+0x151>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xef0(%rip),%rdi
call   1050 <puts@plt>
lea    0xe63(%rip),%rdi
mov    $0x2580,%esi
call   1040 <ser_init@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   10a0 <sleep@plt>
cmp    $0xffffffff,%ebx
jne    11c2 <main+0x42>
mov    $0x4d,%edi
call   1090 <exit@plt>
lea    0xed5(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1080 <ser_readln@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <strlen@plt>
cmp    %ebx,%eax
jne    123f <main+0xbf>
lea    0xe1d(%rip),%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebx
jne    1255 <main+0xd5>
lea    0xe0d(%rip),%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    126e <main+0xee>
lea    0xe9c(%rip),%rdi
call   1050 <puts@plt>
lea    0xe50(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xea9(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xed5(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdd8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdfc(%rip),%rdi
jmp    1281 <main+0x101>
lea    0xe72(%rip),%rdi
call   1050 <puts@plt>
lea    0xdf1(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Start initialization process\0A\00"
@.str.1 = [13 x i8] c"/dev/ttyACM0\00"
@.str.2 = [21 x i8] c"Arduino initialized\0A\00"
@.str.3 = [34 x i8] c"Read string is not 0-terminated.\0A\00"
@.str.4 = [39 x i8] c"Test program for testing libarduserial\00"
@.str.5 = [52 x i8] c"Not the correct amount of characters was read [%i]\0A\00"
@.str.6 = [10 x i8] c"\22%s\22 read\00"
@.str.7 = [53 x i8] c"Failed to read the correct string from the arduino.\0A\00"
@.str.8 = [15 x i8] c"\22%s\22 was read\0A\00"
@.str.9 = [43 x i8] c"String read from the arduino was correct.\0A\00"
@.str.10 = [12 x i8] c"Test: PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1000 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @ser_init(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 9600)
store i32 %10, i32* %8
%11 = call i32 @sleep(i32 2)
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @exit(i32 77)
unreachable
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* %8
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%20 = call i32 @ser_readln(i32 %18, i8* %19)
store i32 %20, i32* %6
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = load i32, i32* %6
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = load i32, i32* %6
%30 = call i32 @strlen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i32, i32* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%40 = load i32, i32* %6
%41 = call i64 @strncmp(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0))
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"/dev/ttyACM0\00"
@.str.4 = [39 x i8] c"Test program for testing libarduserial\00"
@.str.5 = [52 x i8] c"Not the correct amount of characters was read [%i]\0A\00"
@.str.6 = [10 x i8] c"\22%s\22 read\00"
@.str.8 = [15 x i8] c"\22%s\22 was read\0A\00"
@str = [29 x i8] c"Start initialization process\00"
@str.11 = [20 x i8] c"Arduino initialized\00"
@str.12 = [42 x i8] c"String read from the arduino was correct.\00"
@str.13 = [11 x i8] c"Test: PASS\00"
@str.14 = [52 x i8] c"Failed to read the correct string from the arduino.\00"
@str.15 = [33 x i8] c"Read string is not 0-terminated.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @ser_init(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 9600)
%7 = tail call i32 @sleep(i32 2)
%8 = icmp eq i32 %6, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @exit(i32 77)
unreachable
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
%13 = call i32 @ser_readln(i32 %6, i8* %4)
%14 = call i32 @strlen(i8* %4)
%15 = icmp eq i32 %14, %13
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.15, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = call i32 @strlen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32 %13, %20
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = call i64 @strncmp(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 %13)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.14, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.12, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.13, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
}