#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 OpenDev(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int set_Parity(int, int, int, char);
int /*<<< orphan*/ set_speed(int, int);
int main(int argc, char **argv) {
  int fd;
  int nread;
  char buff[1024];
  char *dev = "/dev/ttyACM0";
  fd = OpenDev(dev);
  if (fd > 0)
    set_speed(fd, 9600);
  else {
    printf("Can't Open Serial Port!\n");
    exit(0);
  }
  if (set_Parity(fd, 8, 1, 'N') == (!(1 == 1))) {
    printf("Set Parity Error\n");
    exit(1);
  }
  while (1) {
    while ((nread = read(fd, buff, 1024)) > 0) {
      printf("\nLen %d\n", nread);
      buff[nread + 1] = '\0';
      printf("\n%s", buff);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
call   1070 <OpenDev@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b2 <main+0x52>
mov    -0x14(%rbp),%edi
mov    $0x2580,%esi
call   1060 <set_speed@plt>
jmp    11c7 <main+0x67>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   1050 <set_Parity@plt>
cmp    $0x0,%eax
jne    11ff <main+0x9f>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1204 <main+0xa4>
jmp    1209 <main+0xa9>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1264 <main+0x104>
mov    -0x18(%rbp),%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1209 <main+0xa9>
jmp    1204 <main+0xa4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xe7a(%rip),%rdi
call   1080 <OpenDev@plt>
test   %eax,%eax
jle    1238 <main+0xc8>
mov    %eax,%r12d
mov    %eax,%edi
mov    $0x2580,%esi
call   1070 <set_speed@plt>
mov    %r12d,%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   1060 <set_Parity@plt>
test   %eax,%eax
je     124b <main+0xdb>
mov    %rsp,%rbx
lea    0xe42(%rip),%r14
lea    0xe44(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11e0 <main+0x70>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
movb   $0x0,0x1(%rax,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1200 <main+0x90>
jmp    11e0 <main+0x70>
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xde0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.1 = [25 x i8] c"Can't Open Serial Port!\0A\00"
@.str.2 = [18 x i8] c"Set Parity Error\0A\00"
@.str.3 = [9 x i8] c"\0ALen %d\0A\00"
@.str.4 = [4 x i8] c"\0A%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %9
%11 = call i32 @OpenDev(i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* %6
%16 = call i32 @set_speed(i32 %15, i32 9600)
br label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %14
%21 = load i32, i32* %6
%22 = call i32 @set_Parity(i32 %21, i32 8, i32 1, i8 signext 78)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
br label %28
28: ; preds = %27, %43
br label %29
29: ; preds = %34, %28
%30 = load i32, i32* %6
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 1024)
store i32 %32, i32* %7
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %29
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %29
43: ; preds = %29
br label %28
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.3 = [9 x i8] c"\0ALen %d\0A\00"
@.str.4 = [4 x i8] c"\0A%s\00"
@str = [24 x i8] c"Can't Open Serial Port!\00"
@str.5 = [17 x i8] c"Set Parity Error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @OpenDev(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @set_speed(i32 %5, i32 9600)
%9 = tail call i32 @set_Parity(i32 %5, i32 8, i32 1, i8 signext 78)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %17
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %7, %20
%18 = call i32 @read(i32 %5, i8* %4, i32 1024)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %21, %17
br label %17
21: ; preds = %17, %21
%22 = phi i32 [ %28, %21 ], [ %18, %17 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i32 %22, 1
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%28 = call i32 @read(i32 %5, i8* %4, i32 1024)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %21, label %20
}