#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 */
typedef scalar_t__ uint8_t;
struct termios {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ B57600;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, scalar_t__ *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  int fd, n, i, j;
  uint8_t data[11];
  struct termios toptions;
  fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
  if (fd < 0) {
    printf("Error opening /deC/ttyUSB0\n");
  } else {
    printf("File open !\n");
  }
  printf("get current serial port settings\n");
  tcgetattr(fd, &toptions);
  printf("Setting speed\n");
  cfsetispeed(&toptions, B57600);
  cfsetospeed(&toptions, B57600);
  cfmakeraw(&toptions);
  printf("commit the serial port settings\n");
  tcsetattr(fd, TCSANOW, &toptions);
  printf("Ready to read...\n");
  j = 0;
  while (1) {
    n = read(fd, data, 11);
    if (n == -1) {
      printf("Err!\n");
    }
    for (i = 0; i < n; i++) {
      j++;
      printf("%u ", (unsigned)data[i]);
      if (j == 11) {
        j = 0;
        printf("\n");
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e1f(%rip),%rax
or     (%rax),%esi
lea    0xe4e(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d7 <main+0x57>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e5 <main+0x65>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x88(%rbp),%rsi
call   1070 <tcgetattr@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdi
call   10a0 <cfsetispeed@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdi
call   1030 <cfsetospeed@plt>
lea    -0x88(%rbp),%rdi
call   1060 <cfmakeraw@plt>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
call   1080 <tcsetattr@plt>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0xb,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12ad <main+0x12d>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1314 <main+0x194>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rax
mov    %eax,%esi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xb,-0x20(%rbp)
jne    1301 <main+0x181>
movl   $0x0,-0x20(%rbp)
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1306 <main+0x186>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b4 <main+0x134>
jmp    1281 <main+0x101>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e33(%rip),%rax
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe39(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
lea    0xeaa(%rip),%rax
lea    0xe32(%rip),%rdi
cmovs  %rax,%rdi
call   1040 <puts@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%r14
mov    %r13d,%edi
mov    %r14,%rsi
call   1090 <tcgetattr@plt>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dc1(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   10c0 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <cfsetospeed@plt>
mov    %r14,%rdi
call   1080 <cfmakeraw@plt>
lea    0xe12(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
mov    %r14,%rdx
call   10a0 <tcsetattr@plt>
lea    0xe12(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%r14
lea    0xda2(%rip),%r12
xor    %ebp,%ebp
nopl   (%rax)
lea    0xe06(%rip),%rbx
jmp    1288 <main+0xe8>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0xb,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1280 <main+0xe0>
test   %eax,%eax
jle    1288 <main+0xe8>
mov    %eax,%ebx
xor    %r15d,%r15d
jmp    12b9 <main+0x119>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%rbx
je     1270 <main+0xd0>
add    $0x1,%ebp
mov    0x10(%rsp,%r15,8),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0xb,%ebp
jne    12b0 <main+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    12b0 <main+0x110>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [28 x i8] c"Error opening /deC/ttyUSB0\0A\00"
@.str.2 = [13 x i8] c"File open !\0A\00"
@.str.3 = [34 x i8] c"get current serial port settings\0A\00"
@.str.4 = [15 x i8] c"Setting speed\0A\00"
@B57600 = global i32 0
@.str.5 = [33 x i8] c"commit the serial port settings\0A\00"
@TCSANOW = global i32 0
@.str.6 = [18 x i8] c"Ready to read...\0A\00"
@.str.7 = [6 x i8] c"Err!\0A\00"
@.str.8 = [4 x i8] c"%u \00"
@.str.9 = [2 x i8] c"\0A\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 i32
%9 = alloca i32
%10 = alloca [11 x i64]
%11 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_NOCTTY
%14 = or i32 %12, %13
%15 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* %6
%25 = call i32 @tcgetattr(i32 %24, %struct.termios* %11)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* @B57600
%28 = call i32 @cfsetispeed(%struct.termios* %11, i32 %27)
%29 = load i32, i32* @B57600
%30 = call i32 @cfsetospeed(%struct.termios* %11, i32 %29)
%31 = call i32 @cfmakeraw(%struct.termios* %11)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = load i32, i32* @TCSANOW
%35 = call i32 @tcsetattr(i32 %33, i32 %34, %struct.termios* %11)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %9
br label %37
37: ; preds = %22, %67
%38 = load i32, i32* %6
%39 = getelementptr inbounds [11 x i64], [11 x i64]* %10, i64 0, i64 0
%40 = call i32 @read(i32 %38, i64* %39, i32 11)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
store i32 0, i32* %8
br label %46
46: ; preds = %64, %45
%47 = load i32, i32* %8
%48 = load i32, i32* %7
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %67
50: ; preds = %46
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [11 x i64], [11 x i64]* %10, i64 0, i64 %54
%56 = load i64, i64* %55
%57 = trunc i64 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %9
%60 = icmp eq i32 %59, 11
br i1 %60, label %61, label %63
61: ; preds = %50
store i32 0, i32* %9
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %63
63: ; preds = %61, %50
br label %64
64: ; preds = %63
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %46
67: ; preds = %46
br label %37
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B57600 = global i32 0
@TCSANOW = global i32 0
@.str.8 = [4 x i8] c"%u \00"
@str = [12 x i8] c"File open !\00"
@str.10 = [33 x i8] c"get current serial port settings\00"
@str.11 = [14 x i8] c"Setting speed\00"
@str.12 = [32 x i8] c"commit the serial port settings\00"
@str.13 = [17 x i8] c"Ready to read...\00"
@str.14 = [5 x i8] c"Err!\00"
@str.15 = [27 x i8] c"Error opening /deC/ttyUSB0\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [11 x i64]
%4 = alloca %struct.termios
%5 = bitcast [11 x i64]* %3 to i8*
%6 = bitcast %struct.termios* %4 to i8*
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str.15, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0)
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
%15 = call i32 @tcgetattr(i32 %10, %struct.termios* %4)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0))
%17 = load i32, i32* @B57600
%18 = call i32 @cfsetispeed(%struct.termios* %4, i32 %17)
%19 = load i32, i32* @B57600
%20 = call i32 @cfsetospeed(%struct.termios* %4, i32 %19)
%21 = call i32 @cfmakeraw(%struct.termios* %4)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.12, i64 0, i64 0))
%23 = load i32, i32* @TCSANOW
%24 = call i32 @tcsetattr(i32 %10, i32 %23, %struct.termios* %4)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
%26 = getelementptr inbounds [11 x i64], [11 x i64]* %3, i64 0, i64 0
br label %27
27: ; preds = %50, %2
%28 = phi i32 [ 0, %2 ], [ %51, %50 ]
br label %29
29: ; preds = %34, %27
%30 = call i32 @read(i32 %10, i64* %26, i32 11)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.14, i64 0, i64 0))
br label %34
34: ; preds = %32, %35
br label %29
35: ; preds = %29
%36 = icmp sgt i32 %30, 0
br i1 %36, label %37, label %34
37: ; preds = %35
%38 = zext i32 %30 to i64
br label %39
39: ; preds = %37, %50
%40 = phi i64 [ 0, %37 ], [ %52, %50 ]
%41 = phi i32 [ %28, %37 ], [ %51, %50 ]
%42 = add nsw i32 %41, 1
%43 = getelementptr inbounds [11 x i64], [11 x i64]* %3, i64 0, i64 %40
%44 = load i64, i64* %43
%45 = trunc i64 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = icmp eq i32 %42, 11
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 @putchar(i32 10)
br label %50
50: ; preds = %39, %48
%51 = phi i32 [ 0, %48 ], [ %42, %39 ]
%52 = add nuw nsw i64 %40, 1
%53 = icmp eq i64 %52, %38
br i1 %53, label %27, label %39
}