#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*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int vc_init(char *, int, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd, i, idx = 0;
  int uart_fd;
  char buf[24];
  struct timeval tv;
  assert(argc > 1);
  uart_fd = vc_init(argv[1], -1, 0, 0);
  while (1) {
    i = read(uart_fd, buf + idx, 1);
    if (!idx)
      gettimeofday(&tv, NULL);
    if (buf[idx] == 0x0a) {
      idx = 0;
      buf[4] = 0;
      printf("%u.%u %s\n", tv.tv_sec, tv.tv_usec, buf + 1);
      fprintf(stderr, "%u.%u %s\n", tv.tv_sec, tv.tv_usec, buf + 1);
      fflush(stdout);
    } else
      idx++;
  }
  if (fd >= 0)
    close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0xffffffff,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <vc_init@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11e9 <main+0x79>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movslq -0x1c(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1256 <main+0xe6>
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x3c(%rbp)
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    -0x40(%rbp),%rcx
add    $0x1,%rcx
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
mov    -0x44(%rbp),%ecx
lea    -0x40(%rbp),%r8
add    $0x1,%r8
lea    0xdc2(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    125f <main+0xef>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b7 <main+0x47>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
setge  %al
mov    %eax,%edi
call   1070 <assert@plt>
mov    0x8(%rbx),%rdi
xor    %ebp,%ebp
mov    $0xffffffff,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <vc_init@plt>
mov    %eax,%r13d
lea    0x11(%rsp),%r14
lea    0xe4d(%rip),%r12
jmp    11c3 <main+0x53>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
movslq %ebp,%r15
lea    (%rsp,%r15,1),%rbx
add    $0x10,%rbx
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %r15d,%r15d
je     11f0 <main+0x80>
cmpb   $0xa,(%rbx)
jne    11c0 <main+0x50>
jmp    1201 <main+0x91>
nopw   0x0(%rax,%rax,1)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cmpb   $0xa,(%rbx)
jne    11c0 <main+0x50>
movb   $0x0,0x14(%rsp)
mov    0x8(%rsp),%ebx
mov    0xc(%rsp),%ebp
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1030 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14,%r8
call   1080 <fprintf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
xor    %ebp,%ebp
jmp    11c3 <main+0x53>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [10 x i8] c"%u.%u %s\0A\00"
@stderr = global i32 0
@stdout = global i32 0
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 [24 x i8]
%11 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @vc_init(i8* %18, i32 -1, i32 0, i32 0)
store i32 %19, i32* %9
br label %20
20: ; preds = %2, %60
%21 = load i32, i32* %9
%22 = getelementptr inbounds [24 x i8], [24 x i8]* %10, i64 0, i64 0
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = call i32 @read(i32 %21, i8* %25, i32 1)
store i32 %26, i32* %7
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %20
%30 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
br label %31
31: ; preds = %29, %20
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [24 x i8], [24 x i8]* %10, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %57
38: ; preds = %31
store i32 0, i32* %8
%39 = getelementptr inbounds [24 x i8], [24 x i8]* %10, i64 0, i64 4
store i8 0, i8* %39
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%43 = load i32, i32* %42
%44 = getelementptr inbounds [24 x i8], [24 x i8]* %10, i64 0, i64 0
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %43, i8* %45)
%47 = load i32, i32* @stderr
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds [24 x i8], [24 x i8]* %10, i64 0, i64 0
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %49, i32 %51, i8* %53)
%55 = load i32, i32* @stdout
%56 = call i32 @fflush(i32 %55)
br label %60
57: ; preds = %31
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %60
60: ; preds = %57, %38
br label %20
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [10 x i8] c"%u.%u %s\0A\00"
@stderr = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [24 x i8]
%4 = alloca %struct.timeval
%5 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp sgt i32 %0, 1
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @vc_init(i8* %11, i32 -1, i32 0, i32 0)
%13 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 4
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%16 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 1
br label %17
17: ; preds = %38, %2
%18 = phi i32 [ 0, %2 ], [ %39, %38 ]
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 %19
%21 = call i32 @read(i32 %12, i8* %20, i32 1)
%22 = icmp eq i32 %18, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %25
25: ; preds = %23, %17
%26 = load i8, i8* %20
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %36
28: ; preds = %25
store i8 0, i8* %13
%29 = load i32, i32* %14
%30 = load i32, i32* %15
%31 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30, i8* %16)
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30, i8* %16)
%34 = load i32, i32* @stdout
%35 = call i32 @fflush(i32 %34)
br label %38
36: ; preds = %25
%37 = add nsw i32 %18, 1
br label %38
38: ; preds = %36, %28
%39 = phi i32 [ 0, %28 ], [ %37, %36 ]
br label %17
}