#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int xserial_port_open();
int xserial_port_dump() {
  int cnt, serline;
  serline = xserial_port_open();
  while (1) {
    unsigned char c;
    cnt = read(serline, &c, 1);
    if (cnt < 0) {
      perror("error reading from serial port");
      exit(2);
    }
    if (cnt == 1) {
      if (c == 0x7e)
        printf("\n");
      printf("%02x ", c);
    }
  }
}


x86 assembly (clang, -O0):
<xserial_port_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <xserial_port_open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1196 <xserial_port_dump+0x46>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x4(%rbp)
jne    11cd <xserial_port_dump+0x7d>
movzbl -0x9(%rbp),%eax
cmp    $0x7e,%eax
jne    11bb <xserial_port_dump+0x6b>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x9(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1162 <xserial_port_dump+0x12>

x86 assembly (clang, -O2):
<xserial_port_dump>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <xserial_port_open@plt>
mov    %eax,%ebx
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jns    119b <xserial_port_dump+0x3b>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe7d(%rip),%r14
lea    0x7(%rsp),%r15
jmp    11cf <xserial_port_dump+0x6f>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1185 <xserial_port_dump+0x25>
cmp    $0x1,%eax
jne    11bc <xserial_port_dump+0x5c>
movzbl 0x7(%rsp),%ebp
cmp    $0x7e,%ebp
jne    11b0 <xserial_port_dump+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11b0 <xserial_port_dump+0x50>

LLVM IR (-O0):
@.str = [31 x i8] c"error reading from serial port\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"%02x \00"
define i32 @xserial_port_dump() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = call i32 (...) @xserial_port_open()
store i32 %4, i32* %2
br label %5
5: ; preds = %0, %26
%6 = load i32, i32* %2
%7 = call i32 @read(i32 %6, i8* %3, i32 1)
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 2)
unreachable
13: ; preds = %5
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 126
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %13
br label %5
}

LLVM IR (-O2):
@.str = [31 x i8] c"error reading from serial port\00"
@.str.2 = [6 x i8] c"%02x \00"
define i32 @xserial_port_dump() {
%1 = alloca i8
%2 = tail call i32 (...) @xserial_port_open()
%3 = call i32 @read(i32 %2, i8* %1, i32 1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %19, %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %0, %19
%9 = phi i32 [ %20, %19 ], [ %3, %0 ]
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i8, i8* %1
%13 = icmp eq i8 %12, 126
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %14, %11
%17 = zext i8 %12 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %8
%20 = call i32 @read(i32 %2, i8* %1, i32 1)
%21 = icmp slt i32 %20, 0
br i1 %21, label %5, label %8
}