#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ configure_serial_port(char const *);
unsigned long decode_attributes(unsigned char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ print_attributes(unsigned long);
int print_display_number(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int read_packet(int, unsigned char *);
int main(int argc, char **argv) {
  int fd;
  int n;
  unsigned char buf[15];
  unsigned long attributes;
  const char *port;
  if (argc > 1)
    port = argv[1];
  else
    port = "/dev/ttyS0";
  if (configure_serial_port(port))
    printf("Couldn't configure serial port \"%s\"\n", port);
  fd = open(port, O_RDONLY);
  if (fd < 0) {
    perror(port);
    exit(0);
  }
  while (1) {
    n = read_packet(fd, buf);
    if (n)
      continue;
    struct timeval t;
    gettimeofday(&t, NULL);
    printf("%u.%06u ", t.tv_sec, t.tv_usec);
    n = print_display_number(buf);
    if (n != 0)
      continue;
    printf(" ");
    attributes = decode_attributes(buf);
    print_attributes(attributes);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11d1 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    11dc <main+0x3c>
lea    0xe28(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <configure_serial_port@plt>
cmp    $0x0,%rax
je     1201 <main+0x61>
mov    -0x38(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1230 <main+0x90>
mov    -0x38(%rbp),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    1235 <main+0x95>
mov    -0x14(%rbp),%edi
lea    -0x27(%rbp),%rsi
call   1070 <read_packet@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1253 <main+0xb3>
jmp    1235 <main+0x95>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x27(%rbp),%rdi
call   1030 <print_display_number@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     128f <main+0xef>
jmp    1235 <main+0x95>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x27(%rbp),%rdi
call   1050 <decode_attributes@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <print_attributes@plt>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1235 <main+0x95>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     11c6 <main+0x16>
mov    0x8(%rsi),%r14
jmp    11cd <main+0x1d>
lea    0xe33(%rip),%r14
mov    %r14,%rdi
call   1090 <configure_serial_port@plt>
test   %rax,%rax
je     11eb <main+0x3b>
lea    0xe2a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     127b <main+0xcb>
mov    %eax,%ebx
lea    0x9(%rsp),%r14
mov    %rsp,%r15
lea    0xe1f(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
call   1080 <read_packet@plt>
test   %eax,%eax
jne    1220 <main+0x70>
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <print_display_number@plt>
test   %eax,%eax
jne    1220 <main+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1060 <decode_attributes@plt>
mov    %rax,%rdi
call   10c0 <print_attributes@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0x70>
mov    %r14,%rdi
call   10b0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [37 x i8] c"Couldn't configure serial port \22%s\22\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"%u.%06u \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [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 [15 x i8]
%9 = alloca i64
%10 = alloca i8*
%11 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %10
br label %19
18: ; preds = %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %10
br label %19
19: ; preds = %18, %14
%20 = load i8*, i8** %10
%21 = call i64 @configure_serial_port(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %10
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %19
%27 = load i8*, i8** %10
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i8*, i8** %10
%34 = call i32 @perror(i8* %33)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %26
br label %37
37: ; preds = %36, %43, %55, %56
%38 = load i32, i32* %6
%39 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%40 = call i32 @read_packet(i32 %38, i8* %39)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
br label %37
44: ; preds = %37
%45 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %49)
%51 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%52 = call i32 @print_display_number(i8* %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %44
br label %37
56: ; preds = %44
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%58 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%59 = call i64 @decode_attributes(i8* %58)
store i64 %59, i64* %9
%60 = load i64, i64* %9
%61 = call i32 @print_attributes(i64 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %37
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [37 x i8] c"Couldn't configure serial port \22%s\22\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"%u.%06u \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [15 x i8]
%4 = alloca %struct.timeval
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
br label %10
10: ; preds = %2, %7
%11 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = tail call i64 @configure_serial_port(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %11, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = bitcast %struct.timeval* %4 to i8*
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
br label %27
24: ; preds = %16
%25 = tail call i32 @perror(i8* %11)
%26 = tail call i32 @exit(i32 0)
unreachable
27: ; preds = %30, %20
%28 = call i32 @read_packet(i32 %18, i8* %5)
%29 = icmp eq i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %27, %43
br label %27
31: ; preds = %27
%32 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%33 = load i32, i32* %22
%34 = load i32, i32* %23
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34)
%36 = call i32 @print_display_number(i8* %5)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = call i32 @putchar(i32 32)
%40 = call i64 @decode_attributes(i8* %5)
%41 = call i32 @print_attributes(i64 %40)
%42 = call i32 @putchar(i32 10)
br label %43
43: ; preds = %31, %38
br label %30
}