#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 open_port();
int /*<<< orphan*/ printf(char *, ...);
int read_port(int *, unsigned char *);
int main(void) {
  int bytes;
  int i;
  int fd_ser;
  unsigned char puffer[300];
  fd_ser = open_port();
  while (1) {
    bytes = read_port(&fd_ser, puffer);
    if (bytes > 0) {
      for (i = 0; i < bytes; i++) {
        printf("%i\t", puffer[i]);
      }
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <open_port@plt>
mov    %eax,-0x10(%rbp)
lea    -0x140(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1030 <read_port@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11b2 <main+0x82>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a4 <main+0x74>
movslq -0xc(%rbp),%rax
movzbl -0x140(%rbp,%rax,1),%esi
ff
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1170 <main+0x40>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114c <main+0x1c>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x140,%rsp
xor    %eax,%eax
call   1060 <open_port@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe94(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <read_port@plt>
test   %eax,%eax
jle    1170 <main+0x30>
mov    %eax,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x10(%rsp,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [4 x i8] c"%i\09\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [300 x i8]
store i32 0, i32* %1
%6 = call i32 (...) @open_port()
store i32 %6, i32* %4
br label %7
7: ; preds = %0, %29
%8 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%9 = call i32 @read_port(i32* %4, i8* %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %7
store i32 0, i32* %3
br label %13
13: ; preds = %24, %12
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %13
27: ; preds = %13
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %7
br label %7
}

LLVM IR (-O2):
@.str = [4 x i8] c"%i\09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [300 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @open_port()
store i32 %5, i32* %1
br label %6
6: ; preds = %21, %0
%7 = call i32 @read_port(i32* %1, i8* %4)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %17, %11 ]
%13 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %11
19: ; preds = %11
%20 = call i32 @putchar(i32 10)
br label %21
21: ; preds = %19, %6
br label %6
}