#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 */
scalar_t__ RS232_OpenComport(int, int, char *);
int RS232_PollComport(int, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int main() {
  int i, n, cport_nr = 16, bdrate = 115200;
  unsigned char buf[4096];
  char mode[] = {'8', 'N', '1', 0};
  if (RS232_OpenComport(cport_nr, bdrate, mode)) {
    printf("Can not open comport\n");
    return (0);
  }
  while (1) {
    n = RS232_PollComport(cport_nr, buf, 4095);
    if (n > 0) {
      buf[n] = 0;
      for (i = 0; i < n; i++) {
        if (buf[i] < 32) {
          buf[i] = '.';
        }
      }
      printf("received %i bytes: %s\n", n, (char *)buf);
    }
    usleep(100000);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x10,-0x10(%rbp)
movl   $0x1c200,-0x14(%rbp)
mov    0xe9a(%rip),%eax
mov    %eax,-0x1024(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x1024(%rbp),%rdx
call   1050 <RS232_OpenComport@plt>
cmp    $0x0,%rax
je     11a1 <main+0x61>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret
jmp    11a6 <main+0x66>
mov    -0x10(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0xfff,%edx
call   1030 <RS232_PollComport@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1232 <main+0xf2>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121a <main+0xda>
movslq -0x8(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jge    1207 <main+0xc7>
movslq -0x8(%rbp),%rax
movb   $0x2e,-0x1020(%rbp,%rax,1)
2e
jmp    120c <main+0xcc>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11da <main+0x9a>
mov    -0xc(%rbp),%esi
lea    -0x1020(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
jmp    11a6 <main+0x66>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1018,%rsp
movl   $0x314e38,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    $0x10,%edi
mov    $0x1c200,%esi
call   1060 <RS232_OpenComport@plt>
test   %rax,%rax
je     1194 <main+0x44>
lea    0xea5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r14
ret
lea    0x10(%rsp),%rbx
lea    0xe70(%rip),%r14
jmp    11c9 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
mov    $0xfff,%edx
call   1030 <RS232_PollComport@plt>
test   %eax,%eax
jle    11bf <main+0x6f>
mov    %eax,%ecx
movb   $0x0,0x10(%rsp,%rcx,1)
cmp    $0x10,%eax
jae    1200 <main+0xb0>
xor    %edx,%edx
jmp    13fd <main+0x2ad>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%edx
and    $0xfffffff0,%edx
xor    %esi,%esi
movdqa 0xdf1(%rip),%xmm4
pcmpeqd %xmm5,%xmm5
jmp    122d <main+0xdd>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x10,%rsi
cmp    %rsi,%rdx
je     13e0 <main+0x290>
movq   0x10(%rsp,%rsi,1),%xmm1
movq   0x18(%rsp,%rsi,1),%xmm0
movdqa %xmm1,%xmm2
pmaxub %xmm4,%xmm2
pcmpeqb %xmm1,%xmm2
movd   %xmm2,%edi
not    %dil
test   $0x1,%dil
je     1257 <main+0x107>
movb   $0x2e,0x10(%rsp,%rsi,1)
movdqa %xmm2,%xmm1
pxor   %xmm5,%xmm1
movdqa %xmm1,%xmm3
pslld  $0x8,%xmm3
movd   %xmm3,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     127a <main+0x12a>
movb   $0x2e,0x11(%rsp,%rsi,1)
pshuflw $0x55,%xmm2,%xmm3
pxor   %xmm5,%xmm3
pextrw $0x2,%xmm3,%edi
test   $0x1,%dil
je     1293 <main+0x143>
movb   $0x2e,0x12(%rsp,%rsi,1)
movdqa %xmm1,%xmm3
psllq  $0x18,%xmm3
pextrw $0x3,%xmm3,%edi
test   $0x1,%dil
je     12ac <main+0x15c>
movb   $0x2e,0x13(%rsp,%rsi,1)
pshufd $0x55,%xmm2,%xmm2
pxor   %xmm5,%xmm2
pextrw $0x4,%xmm2,%edi
test   $0x1,%dil
je     12c5 <main+0x175>
movb   $0x2e,0x14(%rsp,%rsi,1)
movdqa %xmm1,%xmm2
pslldq $0x5,%xmm2
pextrw $0x5,%xmm2,%edi
test   $0x1,%dil
je     12de <main+0x18e>
movb   $0x2e,0x15(%rsp,%rsi,1)
pextrw $0x3,%xmm1,%edi
test   $0x1,%dil
je     12ee <main+0x19e>
movb   $0x2e,0x16(%rsp,%rsi,1)
pslldq $0x7,%xmm1
pextrw $0x7,%xmm1,%edi
test   $0x1,%dil
je     1303 <main+0x1b3>
movb   $0x2e,0x17(%rsp,%rsi,1)
movdqa %xmm0,%xmm1
pmaxub %xmm4,%xmm1
pcmpeqb %xmm0,%xmm1
movd   %xmm1,%edi
not    %dil
test   $0x1,%dil
je     1321 <main+0x1d1>
movb   $0x2e,0x18(%rsp,%rsi,1)
movdqa %xmm1,%xmm0
pxor   %xmm5,%xmm0
movdqa %xmm0,%xmm2
pslld  $0x8,%xmm2
movd   %xmm2,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     1344 <main+0x1f4>
movb   $0x2e,0x19(%rsp,%rsi,1)
pshuflw $0x55,%xmm1,%xmm2
pxor   %xmm5,%xmm2
pextrw $0x2,%xmm2,%edi
test   $0x1,%dil
je     135d <main+0x20d>
movb   $0x2e,0x1a(%rsp,%rsi,1)
movdqa %xmm0,%xmm2
psllq  $0x18,%xmm2
pextrw $0x3,%xmm2,%edi
test   $0x1,%dil
je     1376 <main+0x226>
movb   $0x2e,0x1b(%rsp,%rsi,1)
pshufd $0x55,%xmm1,%xmm1
pxor   %xmm5,%xmm1
pextrw $0x4,%xmm1,%edi
test   $0x1,%dil
je     138f <main+0x23f>
movb   $0x2e,0x1c(%rsp,%rsi,1)
movdqa %xmm0,%xmm1
pslldq $0x5,%xmm1
pextrw $0x5,%xmm1,%edi
test   $0x1,%dil
je     13a8 <main+0x258>
movb   $0x2e,0x1d(%rsp,%rsi,1)
pextrw $0x3,%xmm0,%edi
test   $0x1,%dil
je     13b8 <main+0x268>
movb   $0x2e,0x1e(%rsp,%rsi,1)
pslldq $0x7,%xmm0
pextrw $0x7,%xmm0,%edi
test   $0x1,%dil
je     1220 <main+0xd0>
movb   $0x2e,0x1f(%rsp,%rsi,1)
jmp    1220 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
cmp    %rcx,%rdx
jne    13fd <main+0x2ad>
jmp    11b0 <main+0x60>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %rdx,%rcx
je     11b0 <main+0x60>
cmpb   $0x1f,0x10(%rsp,%rdx,1)
ja     13f0 <main+0x2a0>
movb   $0x2e,0x10(%rsp,%rdx,1)
jmp    13f0 <main+0x2a0>

LLVM IR (-O0):
@__const.main.mode = [4 x i8] c"8N1\00"
@.str = [22 x i8] c"Can not open comport\0A\00"
@.str.1 = [23 x i8] c"received %i bytes: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca [4 x i8]
store i32 0, i32* %1
store i32 16, i32* %4
store i32 115200, i32* %5
%8 = bitcast [4 x i8]* %7 to i8*
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%12 = call i64 @RS232_OpenComport(i32 %9, i32 %10, i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
ret i32 0
16: ; preds = %0
br label %17
17: ; preds = %16, %50
%18 = load i32, i32* %4
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%20 = call i32 @RS232_PollComport(i32 %18, i8* %19, i32 4095)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %50
23: ; preds = %17
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %25
store i8 0, i8* %26
store i32 0, i32* %2
br label %27
27: ; preds = %43, %23
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = icmp slt i32 %36, 32
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %40
store i8 46, i8* %41
br label %42
42: ; preds = %38, %31
br label %43
43: ; preds = %42
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %27
46: ; preds = %27
%47 = load i32, i32* %3
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %47, i8* %48)
br label %50
50: ; preds = %46, %17
%51 = call i32 @usleep(i32 100000)
br label %17
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"received %i bytes: %s\0A\00"
@str = [21 x i8] c"Can not open comport\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
store i32 3231288, i32* %2
%5 = call i64 @RS232_OpenComport(i32 16, i32 115200, i8* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
ret i32 0
9: ; preds = %0, %124
%10 = call i32 @RS232_PollComport(i32 16, i8* %3, i32 4095)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %124
12: ; preds = %9
%13 = zext i32 %10 to i64
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %13
store i8 0, i8* %14
%15 = icmp ult i32 %10, 16
br i1 %15, label %111, label %16
16: ; preds = %12
%17 = and i64 %13, 4294967280
br label %18
18: ; preds = %106, %16
%19 = phi i64 [ 0, %16 ], [ %107, %106 ]
%20 = or i64 %19, 8
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %19
%22 = bitcast i8* %21 to <8 x i8>*
%23 = load <8 x i8>, <8 x i8>* %22
%24 = getelementptr inbounds i8, i8* %21, i64 8
%25 = bitcast i8* %24 to <8 x i8>*
%26 = load <8 x i8>, <8 x i8>* %25
%27 = icmp ult <8 x i8> %23, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%28 = icmp ult <8 x i8> %26, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%29 = extractelement <8 x i1> %27, i64 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %19
store i8 46, i8* %31
br label %32
32: ; preds = %30, %18
%33 = extractelement <8 x i1> %27, i64 1
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = or i64 %19, 1
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %35
store i8 46, i8* %36
br label %37
37: ; preds = %34, %32
%38 = extractelement <8 x i1> %27, i64 2
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = or i64 %19, 2
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %40
store i8 46, i8* %41
br label %42
42: ; preds = %39, %37
%43 = extractelement <8 x i1> %27, i64 3
br i1 %43, label %44, label %47
44: ; preds = %42
%45 = or i64 %19, 3
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %45
store i8 46, i8* %46
br label %47
47: ; preds = %44, %42
%48 = extractelement <8 x i1> %27, i64 4
br i1 %48, label %49, label %52
49: ; preds = %47
%50 = or i64 %19, 4
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %50
store i8 46, i8* %51
br label %52
52: ; preds = %49, %47
%53 = extractelement <8 x i1> %27, i64 5
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = or i64 %19, 5
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %55
store i8 46, i8* %56
br label %57
57: ; preds = %54, %52
%58 = extractelement <8 x i1> %27, i64 6
br i1 %58, label %59, label %62
59: ; preds = %57
%60 = or i64 %19, 6
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %60
store i8 46, i8* %61
br label %62
62: ; preds = %59, %57
%63 = extractelement <8 x i1> %27, i64 7
br i1 %63, label %64, label %67
64: ; preds = %62
%65 = or i64 %19, 7
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %65
store i8 46, i8* %66
br label %67
67: ; preds = %64, %62
%68 = extractelement <8 x i1> %28, i64 0
br i1 %68, label %69, label %71
69: ; preds = %67
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %20
store i8 46, i8* %70
br label %71
71: ; preds = %69, %67
%72 = extractelement <8 x i1> %28, i64 1
br i1 %72, label %73, label %76
73: ; preds = %71
%74 = or i64 %19, 9
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %74
store i8 46, i8* %75
br label %76
76: ; preds = %73, %71
%77 = extractelement <8 x i1> %28, i64 2
br i1 %77, label %78, label %81
78: ; preds = %76
%79 = or i64 %19, 10
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %79
store i8 46, i8* %80
br label %81
81: ; preds = %78, %76
%82 = extractelement <8 x i1> %28, i64 3
br i1 %82, label %83, label %86
83: ; preds = %81
%84 = or i64 %19, 11
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %84
store i8 46, i8* %85
br label %86
86: ; preds = %83, %81
%87 = extractelement <8 x i1> %28, i64 4
br i1 %87, label %88, label %91
88: ; preds = %86
%89 = or i64 %19, 12
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %89
store i8 46, i8* %90
br label %91
91: ; preds = %88, %86
%92 = extractelement <8 x i1> %28, i64 5
br i1 %92, label %93, label %96
93: ; preds = %91
%94 = or i64 %19, 13
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %94
store i8 46, i8* %95
br label %96
96: ; preds = %93, %91
%97 = extractelement <8 x i1> %28, i64 6
br i1 %97, label %98, label %101
98: ; preds = %96
%99 = or i64 %19, 14
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %99
store i8 46, i8* %100
br label %101
101: ; preds = %98, %96
%102 = extractelement <8 x i1> %28, i64 7
br i1 %102, label %103, label %106
103: ; preds = %101
%104 = or i64 %19, 15
%105 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %104
store i8 46, i8* %105
br label %106
106: ; preds = %103, %101
%107 = add nuw i64 %19, 16
%108 = icmp eq i64 %107, %17
br i1 %108, label %109, label %18
109: ; preds = %106
%110 = icmp eq i64 %17, %13
br i1 %110, label %122, label %111
111: ; preds = %12, %109
%112 = phi i64 [ 0, %12 ], [ %17, %109 ]
br label %113
113: ; preds = %111, %119
%114 = phi i64 [ %120, %119 ], [ %112, %111 ]
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %114
%116 = load i8, i8* %115
%117 = icmp ult i8 %116, 32
br i1 %117, label %118, label %119
118: ; preds = %113
store i8 46, i8* %115
br label %119
119: ; preds = %113, %118
%120 = add nuw nsw i64 %114, 1
%121 = icmp eq i64 %120, %13
br i1 %121, label %122, label %113
122: ; preds = %119, %109
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %3)
br label %124
124: ; preds = %122, %9
%125 = call i32 @usleep(i32 100000)
br label %9
}