#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_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int atoi(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, int *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
main(int argc, char **argv) {
  fd_set selectset;
  struct timeval timeout;
  int ret;
  int var = 0;
  int count = 0;
  int tmout = 160;
  int maxcount = 0;
  while (argc--) {
    if (strcmp("-t", *argv) == 0) {
      tmout = atoi(*++argv);
    } else if (strcmp("-c", *argv) == 0) {
      maxcount = atoi(*++argv);
    } else {
      *argv++;
    }
  }
  for (int i = 0;; i++) {
    FD_ZERO(&selectset);
    FD_SET(0, &selectset);
    timeout.tv_sec = 0;
    timeout.tv_usec = tmout * 1000;
    ret = select(1, &selectset, NULL, NULL, &timeout);
    if (ret == 0) {
      if (count) {
        count = 0;
        printf("\n");
        fflush(stdout);
      }
    } else if (ret == -1) {
      printf("error\n");
    } else {
      count++;
      int size = read(0, &var, 1);
      if (var == -1) {
        return 0;
      }
      printf("%02x", var);
      if (maxcount > 0 && count == maxcount) {
        count = 0;
        printf("\n");
        fflush(stdout);
      }
    }
  }
}


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,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0xa0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1256 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2c(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1203 <main+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x38(%rbp)
jmp    1251 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf2(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1240 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x3c(%rbp)
jmp    124c <main+0xcc>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1251 <main+0xd1>
jmp    11b2 <main+0x32>
movl   $0x0,-0x40(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   10a0 <FD_SET@plt>
movq   $0x0,-0x20(%rbp)
imul   $0x3e8,-0x38(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1070 <select@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12db <main+0x15b>
cmpl   $0x0,-0x34(%rbp)
je     12d6 <main+0x156>
movl   $0x0,-0x34(%rbp)
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    137a <main+0x1fa>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12f8 <main+0x178>
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1375 <main+0x1f5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
xor    %edi,%edi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1326 <main+0x1a6>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x30(%rbp),%esi
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x3c(%rbp)
jle    1370 <main+0x1f0>
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jne    1370 <main+0x1f0>
movl   $0x0,-0x34(%rbp)
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1375 <main+0x1f5>
jmp    137a <main+0x1fa>
jmp    137f <main+0x1ff>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    125d <main+0xdd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,(%rsp)
test   %edi,%edi
je     1228 <main+0x88>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0xa0,%r15d
xor    %r14d,%r14d
lea    0xe32(%rip),%r12
lea    0xe2e(%rip),%r13
jmp    11f4 <main+0x54>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
call   10b0 <atoi@plt>
mov    %eax,%r15d
test   %ebp,%ebp
je     1231 <main+0x91>
add    $0xffffffff,%ebp
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e0 <main+0x40>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1070 <strcmp@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    11f0 <main+0x50>
mov    (%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
jmp    11f0 <main+0x50>
mov    $0xa0,%r15d
xor    %r14d,%r14d
imul   $0x3e8,%r15d,%r13d
lea    0x4(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0xdc2(%rip),%r15
xor    %r12d,%r12d
jmp    1258 <main+0xb8>
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1080 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
movq   $0x0,0x10(%rsp)
mov    %r13d,0x8(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
call   1090 <select@plt>
cmp    $0xffffffff,%eax
je     1250 <main+0xb0>
test   %eax,%eax
jne    12a2 <main+0x102>
test   %r12d,%r12d
mov    $0x0,%r12d
je     1258 <main+0xb8>
jmp    12d5 <main+0x135>
xor    %edi,%edi
mov    %rsp,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    (%rsp),%esi
cmp    $0xffffffff,%esi
je     12f5 <main+0x155>
add    $0x1,%r12d
lea    0xd42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jle    1258 <main+0xb8>
cmp    %r14d,%r12d
jne    1258 <main+0xb8>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
xor    %r12d,%r12d
jmp    1258 <main+0xb8>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [2 x i8] c"\0A\00"
@stdout = global i32 0
@.str.3 = [7 x i8] c"error\0A\00"
@.str.4 = [5 x i8] c"%02x\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
store i32 160, i32* %11
store i32 0, i32* %12
br label %15
15: ; preds = %44, %2
%16 = load i32, i32* %4
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = icmp ne i32 %16, 0
br i1 %18, label %19, label %45
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i32 1
store i8** %26, i8*** %5
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %11
br label %44
29: ; preds = %19
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i32 1
store i8** %36, i8*** %5
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %12
br label %43
39: ; preds = %29
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i32 1
store i8** %41, i8*** %5
%42 = load i8*, i8** %40
br label %43
43: ; preds = %39, %34
br label %44
44: ; preds = %43, %24
br label %15
45: ; preds = %15
store i32 0, i32* %13
br label %46
46: ; preds = %92, %45
%47 = call i32 @FD_ZERO(i32* %6)
%48 = call i32 @FD_SET(i32 0, i32* %6)
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 0, i64* %49
%50 = load i32, i32* %11
%51 = mul nsw i32 %50, 1000
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 %51, i32* %52
%53 = call i32 @select(i32 1, i32* %6, i32* null, i32* null, %struct.timeval* %7)
store i32 %53, i32* %8
%54 = load i32, i32* %8
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %46
%57 = load i32, i32* %10
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %56
store i32 0, i32* %10
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* @stdout
%62 = call i32 @fflush(i32 %61)
br label %63
63: ; preds = %59, %56
br label %91
64: ; preds = %46
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %90
69: ; preds = %64
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
%72 = call i32 @read(i32 0, i32* %9, i32 1)
store i32 %72, i32* %14
%73 = load i32, i32* %9
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %76
75: ; preds = %69
ret i32 0
76: ; preds = %69
%77 = load i32, i32* %9
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %12
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %89
81: ; preds = %76
%82 = load i32, i32* %10
%83 = load i32, i32* %12
%84 = icmp eq i32 %82, %83
br i1 %84, label %85, label %89
85: ; preds = %81
store i32 0, i32* %10
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%87 = load i32, i32* @stdout
%88 = call i32 @fflush(i32 %87)
br label %89
89: ; preds = %85, %81, %76
br label %90
90: ; preds = %89, %67
br label %91
91: ; preds = %90, %63
br label %92
92: ; preds = %91
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
store i32 %94, i32* %13
br label %46
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c"-c\00"
@stdout = global i32 0
@.str.4 = [5 x i8] c"%02x\00"
@str = [6 x i8] c"error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = icmp eq i32 %0, 0
br i1 %9, label %10, label %17
10: ; preds = %38, %2
%11 = phi i32 [ 160, %2 ], [ %40, %38 ]
%12 = phi i32 [ 0, %2 ], [ %41, %38 ]
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%14 = mul nsw i32 %11, 1000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%16 = icmp sgt i32 %12, 0
br label %55
17: ; preds = %2, %38
%18 = phi i32 [ %22, %38 ], [ %0, %2 ]
%19 = phi i32 [ %41, %38 ], [ 0, %2 ]
%20 = phi i32 [ %40, %38 ], [ 160, %2 ]
%21 = phi i8** [ %39, %38 ], [ %1, %2 ]
%22 = add nsw i32 %18, -1
%23 = load i8*, i8** %21
%24 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = getelementptr inbounds i8*, i8** %21, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
br label %38
30: ; preds = %17
%31 = load i8*, i8** %21
%32 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = icmp eq i64 %32, 0
%34 = getelementptr inbounds i8*, i8** %21, i64 1
br i1 %33, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %34
%37 = tail call i32 @atoi(i8* %36)
br label %38
38: ; preds = %30, %35, %26
%39 = phi i8** [ %27, %26 ], [ %34, %35 ], [ %34, %30 ]
%40 = phi i32 [ %29, %26 ], [ %20, %35 ], [ %20, %30 ]
%41 = phi i32 [ %19, %26 ], [ %37, %35 ], [ %19, %30 ]
%42 = icmp eq i32 %22, 0
br i1 %42, label %10, label %17
43: ; preds = %55, %57
%44 = call i32 @FD_ZERO(i32* %3)
%45 = call i32 @FD_SET(i32 0, i32* %3)
store i64 0, i64* %13
store i32 %14, i32* %15
%46 = call i32 @select(i32 1, i32* %3, i32* null, i32* null, %struct.timeval* %4)
switch i32 %46, label %59 [
i32 0, label %47
i32 -1, label %57
]
47: ; preds = %43
%48 = icmp eq i32 %56, 0
br i1 %48, label %53, label %49
49: ; preds = %47
%50 = call i32 @putchar(i32 10)
%51 = load i32, i32* @stdout
%52 = call i32 @fflush(i32 %51)
br label %53
53: ; preds = %49, %47, %64, %68
%54 = phi i32 [ 0, %68 ], [ %60, %64 ], [ 0, %47 ], [ 0, %49 ]
br label %55
55: ; preds = %53, %10
%56 = phi i32 [ 0, %10 ], [ %54, %53 ]
br label %43
57: ; preds = %43
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %43
59: ; preds = %43
%60 = add nsw i32 %56, 1
%61 = call i32 @read(i32 0, i32* %5, i32 1)
%62 = load i32, i32* %5
%63 = icmp eq i32 %62, -1
br i1 %63, label %72, label %64
64: ; preds = %59
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%66 = icmp eq i32 %60, %12
%67 = select i1 %16, i1 %66, i1 false
br i1 %67, label %68, label %53
68: ; preds = %64
%69 = call i32 @putchar(i32 10)
%70 = load i32, i32* @stdout
%71 = call i32 @fflush(i32 %70)
br label %53
72: ; preds = %59
ret i32 0
}