#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 */
typedef int /*<<< orphan*/ tcflag_t;
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct timespec {
  int tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
struct termios {
  int /*<<< orphan*/ c_lflag;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
#define EINTR 128
int /*<<< orphan*/ FD_SET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ ISIG;
scalar_t__ STDIN_FILENO;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSAFLUSH;
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ free(struct timeval *);
struct timeval *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
size_t read(scalar_t__, char *, int);
int select(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
size_t strlen(char *);
int /*<<< orphan*/ tcflush(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(scalar_t__, struct termios *);
int /*<<< orphan*/ tcsetattr(scalar_t__, int /*<<< orphan*/, struct termios *);
char *prompt(const char *msg, const struct timespec *timeout) {
  char buffer[512];
  char *result = NULL;
  ssize_t len;
  struct termios term;
  struct timeval *timeout_val = NULL;
  tcflag_t lflag;
  fd_set readfds;
  if (msg != NULL) {
    (void)fputs(msg, stderr);
    fflush(stderr);
  }
  (void)tcgetattr(STDIN_FILENO, &term);
  lflag = term.c_lflag;
  term.c_lflag |= ICANON;
  term.c_lflag &= ~ISIG;
  (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
  (void)tcflush(STDIN_FILENO, TCIFLUSH);
  FD_ZERO(&readfds);
  FD_SET(STDIN_FILENO, &readfds);
before_select:
  if (timeout != NULL) {
    timeout_val = malloc(sizeof *timeout_val);
    if (timeout_val == NULL)
      return NULL;
    timeout_val->tv_sec = timeout->tv_sec;
    timeout_val->tv_usec = timeout->tv_nsec / 1000;
  }
  errno = 0;
  if (select(STDIN_FILENO + 1, &readfds, NULL, NULL, timeout_val) != 1) {
    switch (errno) {
    case 0:
      fprintf(stderr, "timeout!\n");
      goto out;
    case EINTR:
      goto before_select;
    default:
      perror("vlock: select() on stdin failed");
      goto out;
    }
  }
  if ((len = read(STDIN_FILENO, buffer, sizeof buffer - 1)) < 0)
    goto out;
  buffer[len] = '\0';
  for (len = strlen(buffer); len > 0; --len)
    if (buffer[len - 1] != '\r' && buffer[len - 1] != '\n')
      break;
  buffer[len] = '\0';
  result = strdup(buffer);
  memset(buffer, 0, sizeof buffer);
out:
  free(timeout_val);
  term.c_lflag = lflag;
  (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
  return result;
}


x86 assembly (clang, -O0):
<prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x228(%rbp)
movq   $0x0,-0x240(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1254 <prompt+0x54>
mov    -0x10(%rbp),%rdi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%rdi
lea    -0x238(%rbp),%rsi
call   10e0 <tcgetattr@plt>
mov    -0x238(%rbp),%eax
mov    %eax,-0x244(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
or     -0x238(%rbp),%eax
mov    %eax,-0x238(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x238(%rbp),%eax
mov    %eax,-0x238(%rbp)
mov    0x2d0e(%rip),%rax
mov    (%rax),%rdi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
lea    -0x238(%rbp),%rdx
call   10f0 <tcsetattr@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
lea    -0x248(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%rdi
lea    -0x248(%rbp),%rsi
call   1120 <FD_SET@plt>
cmpq   $0x0,-0x18(%rbp)
je     135d <prompt+0x15d>
mov    $0x8,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x240(%rbp)
cmpq   $0x0,-0x240(%rbp)
jne    1333 <prompt+0x133>
movq   $0x0,-0x8(%rbp)
jmp    152e <prompt+0x32e>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x240(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x240(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2c5c(%rip),%rax
movl   $0x0,(%rax)
mov    0x2c47(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
mov    -0x240(%rbp),%r8
lea    -0x248(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   10b0 <select@plt>
cmp    $0x1,%eax
je     13fd <prompt+0x1fd>
mov    0x2c1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24c(%rbp)
test   %eax,%eax
je     13cd <prompt+0x1cd>
jmp    13b7 <prompt+0x1b7>
mov    -0x24c(%rbp),%eax
sub    $0x80,%eax
je     13e7 <prompt+0x1e7>
jmp    13ec <prompt+0x1ec>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
lea    0xc23(%rip),%rsi
call   1090 <fprintf@plt>
jmp    14ec <prompt+0x2ec>
jmp    12fc <prompt+0xfc>
lea    0xc17(%rip),%rdi
call   1100 <perror@plt>
jmp    14ec <prompt+0x2ec>
mov    0x2bb4(%rip),%rax
mov    (%rax),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x1ff,%edx
call   1080 <read@plt>
mov    %rax,-0x230(%rbp)
cmp    $0x0,%rax
jae    142e <prompt+0x22e>
jmp    14ec <prompt+0x2ec>
mov    -0x230(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jbe    14b7 <prompt+0x2b7>
mov    -0x230(%rbp),%rax
sub    $0x1,%rax
movsbl -0x220(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
je     149b <prompt+0x29b>
mov    -0x230(%rbp),%rax
sub    $0x1,%rax
movsbl -0x220(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     149b <prompt+0x29b>
jmp    14b7 <prompt+0x2b7>
jmp    14a0 <prompt+0x2a0>
mov    -0x230(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x230(%rbp)
jmp    1450 <prompt+0x250>
mov    -0x230(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
call   1110 <strdup@plt>
mov    %rax,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    -0x240(%rbp),%rdi
call   1030 <free@plt>
mov    -0x244(%rbp),%eax
mov    %eax,-0x238(%rbp)
mov    0x2aad(%rip),%rax
mov    (%rax),%rdi
mov    0x2ad3(%rip),%rax
mov    (%rax),%esi
lea    -0x238(%rbp),%rdx
call   10f0 <tcsetattr@plt>
mov    -0x228(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
test   %rdi,%rdi
je     122e <prompt+0x2e>
mov    0x2da8(%rip),%rbx
mov    (%rbx),%esi
call   1060 <fputs@plt>
mov    (%rbx),%edi
call   10d0 <fflush@plt>
mov    0x2d83(%rip),%r13
mov    0x0(%r13),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10e0 <tcgetattr@plt>
mov    (%rsp),%ecx
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %ecx,0x8(%rsp)
or     %ecx,%eax
mov    0x2d83(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x0(%r13),%rdi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   10f0 <tcsetattr@plt>
mov    0x0(%r13),%rdi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
lea    0xc(%rsp),%r12
mov    %r12,%rdi
call   10a0 <FD_ZERO@plt>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   1120 <FD_SET@plt>
xor    %r15d,%r15d
mov    0x2d10(%rip),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %r14,%r14
je     12fb <prompt+0xfb>
mov    $0x8,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     13f7 <prompt+0x1f7>
mov    %rax,%rbx
mov    0x4(%r14),%eax
mov    %eax,0x4(%rbx)
movslq (%r14),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rbx)
movl   $0x0,0x0(%rbp)
mov    0x0(%r13),%rdi
add    $0x1,%rdi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10b0 <select@plt>
cmp    $0x1,%eax
je     1358 <prompt+0x158>
mov    0x0(%rbp),%eax
cmp    $0x80,%eax
je     12c0 <prompt+0xc0>
test   %eax,%eax
jne    140c <prompt+0x20c>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xcc0(%rip),%rsi
call   1090 <fprintf@plt>
xor    %r15d,%r15d
mov    0x8(%rsp),%ebp
mov    0x2c95(%rip),%r12
jmp    13dc <prompt+0x1dc>
mov    0x0(%r13),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
mov    $0x1ff,%edx
call   1080 <read@plt>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     13ab <prompt+0x1ab>
mov    0x8(%rsp),%ebp
mov    0x2c5d(%rip),%r12
jmp    1396 <prompt+0x196>
nopl   (%rax)
add    $0xffffffffffffffff,%rax
je     13a7 <prompt+0x1a7>
movzbl 0xf(%rsp,%rax,1),%ecx
cmp    $0xd,%cl
je     1390 <prompt+0x190>
cmp    $0xa,%cl
je     1390 <prompt+0x190>
jmp    13b8 <prompt+0x1b8>
xor    %eax,%eax
jmp    13b8 <prompt+0x1b8>
xor    %eax,%eax
mov    0x8(%rsp),%ebp
mov    0x2c30(%rip),%r12
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1110 <strdup@plt>
mov    %rax,%r15
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,(%rsp)
mov    0x0(%r13),%rdi
mov    (%r12),%esi
mov    %rsp,%rdx
call   10f0 <tcsetattr@plt>
mov    %r15,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbf7(%rip),%rdi
call   1100 <perror@plt>
jmp    1345 <prompt+0x145>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.termios = type { i32 }
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@STDIN_FILENO = global i64 0
@ICANON = global i32 0
@ISIG = global i32 0
@TCSAFLUSH = global i32 0
@TCIFLUSH = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"timeout!\0A\00"
@.str.1 = [32 x i8] c"vlock: select() on stdin failed\00"
define i8* @prompt(i8* %0, %struct.timespec* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.timespec*
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.termios
%10 = alloca %struct.timeval*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store %struct.timespec* %1, %struct.timespec** %5
store i8* null, i8** %7
store %struct.timeval* null, %struct.timeval** %10
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i32, i32* @stderr
%18 = call i32 @fputs(i8* %16, i32 %17)
%19 = load i32, i32* @stderr
%20 = call i32 @fflush(i32 %19)
br label %21
21: ; preds = %15, %2
%22 = load i64, i64* @STDIN_FILENO
%23 = call i32 @tcgetattr(i64 %22, %struct.termios* %9)
%24 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%25 = load i32, i32* %24
store i32 %25, i32* %11
%26 = load i32, i32* @ICANON
%27 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%28 = load i32, i32* %27
%29 = or i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @ISIG
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = load i64, i64* @STDIN_FILENO
%36 = load i32, i32* @TCSAFLUSH
%37 = call i32 @tcsetattr(i64 %35, i32 %36, %struct.termios* %9)
%38 = load i64, i64* @STDIN_FILENO
%39 = load i32, i32* @TCIFLUSH
%40 = call i32 @tcflush(i64 %38, i32 %39)
%41 = call i32 @FD_ZERO(i32* %12)
%42 = load i64, i64* @STDIN_FILENO
%43 = call i32 @FD_SET(i64 %42, i32* %12)
br label %44
44: ; preds = %75, %21
%45 = load %struct.timespec*, %struct.timespec** %5
%46 = icmp ne %struct.timespec* %45, null
br i1 %46, label %47, label %64
47: ; preds = %44
%48 = call %struct.timeval* @malloc(i32 8)
store %struct.timeval* %48, %struct.timeval** %10
%49 = load %struct.timeval*, %struct.timeval** %10
%50 = icmp eq %struct.timeval* %49, null
br i1 %50, label %51, label %52
51: ; preds = %47
store i8* null, i8** %3
br label %127
52: ; preds = %47
%53 = load %struct.timespec*, %struct.timespec** %5
%54 = getelementptr inbounds %struct.timespec, %struct.timespec* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = load %struct.timeval*, %struct.timeval** %10
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %56, i32 0, i32 1
store i32 %55, i32* %57
%58 = load %struct.timespec*, %struct.timespec** %5
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = sdiv i32 %60, 1000
%62 = load %struct.timeval*, %struct.timeval** %10
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %62, i32 0, i32 0
store i32 %61, i32* %63
br label %64
64: ; preds = %52, %44
store i32 0, i32* @errno
%65 = load i64, i64* @STDIN_FILENO
%66 = add nsw i64 %65, 1
%67 = load %struct.timeval*, %struct.timeval** %10
%68 = call i32 @select(i64 %66, i32* %12, i32* null, i32* null, %struct.timeval* %67)
%69 = icmp ne i32 %68, 1
br i1 %69, label %70, label %78
70: ; preds = %64
%71 = load i32, i32* @errno
switch i32 %71, label %76 [
i32 0, label %72
i32 128, label %75
]
72: ; preds = %70
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %118
75: ; preds = %70
br label %44
76: ; preds = %70
%77 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %118
78: ; preds = %64
%79 = load i64, i64* @STDIN_FILENO
%80 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%81 = call i64 @read(i64 %79, i8* %80, i32 511)
store i64 %81, i64* %8
%82 = icmp ult i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %78
br label %118
84: ; preds = %78
%85 = load i64, i64* %8
%86 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %85
store i8 0, i8* %86
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%88 = call i64 @strlen(i8* %87)
store i64 %88, i64* %8
br label %89
89: ; preds = %108, %84
%90 = load i64, i64* %8
%91 = icmp ugt i64 %90, 0
br i1 %91, label %92, label %111
92: ; preds = %89
%93 = load i64, i64* %8
%94 = sub i64 %93, 1
%95 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp ne i32 %97, 13
br i1 %98, label %99, label %107
99: ; preds = %92
%100 = load i64, i64* %8
%101 = sub i64 %100, 1
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %101
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = icmp ne i32 %104, 10
br i1 %105, label %106, label %107
106: ; preds = %99
br label %111
107: ; preds = %99, %92
br label %108
108: ; preds = %107
%109 = load i64, i64* %8
%110 = add i64 %109, -1
store i64 %110, i64* %8
br label %89
111: ; preds = %106, %89
%112 = load i64, i64* %8
%113 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %112
store i8 0, i8* %113
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%115 = call i8* @strdup(i8* %114)
store i8* %115, i8** %7
%116 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%117 = call i32 @memset(i8* %116, i32 0, i32 512)
br label %118
118: ; preds = %111, %83, %76, %72
%119 = load %struct.timeval*, %struct.timeval** %10
%120 = call i32 @free(%struct.timeval* %119)
%121 = load i32, i32* %11
%122 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
store i32 %121, i32* %122
%123 = load i64, i64* @STDIN_FILENO
%124 = load i32, i32* @TCSAFLUSH
%125 = call i32 @tcsetattr(i64 %123, i32 %124, %struct.termios* %9)
%126 = load i8*, i8** %7
store i8* %126, i8** %3
br label %127
127: ; preds = %118, %51
%128 = load i8*, i8** %3
ret i8* %128
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.termios = type { i32 }
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@STDIN_FILENO = global i64 0
@ICANON = global i32 0
@ISIG = global i32 0
@TCSAFLUSH = global i32 0
@TCIFLUSH = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"timeout!\0A\00"
@.str.1 = [32 x i8] c"vlock: select() on stdin failed\00"
define noalias i8* @prompt(i8* %0, %struct.timespec* %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.termios
%5 = alloca i32
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.termios* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i8* %0, null
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fputs(i8* %0, i32 %11)
%13 = load i32, i32* @stderr
%14 = tail call i32 @fflush(i32 %13)
br label %15
15: ; preds = %10, %2
%16 = load i64, i64* @STDIN_FILENO
%17 = call i32 @tcgetattr(i64 %16, %struct.termios* %4)
%18 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @ICANON
%21 = or i32 %20, %19
%22 = load i32, i32* @ISIG
%23 = xor i32 %22, -1
%24 = and i32 %21, %23
store i32 %24, i32* %18
%25 = load i64, i64* @STDIN_FILENO
%26 = load i32, i32* @TCSAFLUSH
%27 = call i32 @tcsetattr(i64 %25, i32 %26, %struct.termios* %4)
%28 = load i64, i64* @STDIN_FILENO
%29 = load i32, i32* @TCIFLUSH
%30 = call i32 @tcflush(i64 %28, i32 %29)
%31 = call i32 @FD_ZERO(i32* %5)
%32 = load i64, i64* @STDIN_FILENO
%33 = call i32 @FD_SET(i64 %32, i32* %5)
%34 = icmp eq %struct.timespec* %1, null
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
br label %37
37: ; preds = %54, %15
%38 = phi %struct.timeval* [ null, %15 ], [ %49, %54 ]
br i1 %34, label %48, label %39
39: ; preds = %37
%40 = call %struct.timeval* @malloc(i32 8)
%41 = icmp eq %struct.timeval* %40, null
br i1 %41, label %85, label %42
42: ; preds = %39
%43 = load i32, i32* %35
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i64 0, i32 1
store i32 %43, i32* %44
%45 = load i32, i32* %36
%46 = sdiv i32 %45, 1000
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i64 0, i32 0
store i32 %46, i32* %47
br label %48
48: ; preds = %42, %37
%49 = phi %struct.timeval* [ %40, %42 ], [ %38, %37 ]
store i32 0, i32* @errno
%50 = load i64, i64* @STDIN_FILENO
%51 = add nsw i64 %50, 1
%52 = call i32 @select(i64 %51, i32* %5, i32* null, i32* null, %struct.timeval* %49)
%53 = icmp eq i32 %52, 1
br i1 %53, label %61, label %54
54: ; preds = %48
%55 = load i32, i32* @errno
switch i32 %55, label %59 [
i32 0, label %56
i32 128, label %37
]
56: ; preds = %54
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %79
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %79
61: ; preds = %48
%62 = load i64, i64* @STDIN_FILENO
%63 = call i64 @read(i64 %62, i8* %6, i32 511)
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %63
store i8 0, i8* %64
%65 = call i64 @strlen(i8* %6)
%66 = icmp eq i64 %65, 0
br i1 %66, label %74, label %67
67: ; preds = %61, %72
%68 = phi i64 [ %69, %72 ], [ %65, %61 ]
%69 = add i64 %68, -1
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %69
%71 = load i8, i8* %70
switch i8 %71, label %74 [
i8 13, label %72
i8 10, label %72
]
72: ; preds = %67, %67
%73 = icmp eq i64 %69, 0
br i1 %73, label %74, label %67
74: ; preds = %72, %67, %61
%75 = phi i64 [ 0, %61 ], [ %68, %67 ], [ 0, %72 ]
%76 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %75
store i8 0, i8* %76
%77 = call i8* @strdup(i8* %6)
%78 = call i32 @memset(i8* %6, i32 0, i32 512)
br label %79
79: ; preds = %74, %59, %56
%80 = phi i8* [ null, %59 ], [ null, %56 ], [ %77, %74 ]
%81 = call i32 @free(%struct.timeval* %49)
store i32 %19, i32* %18
%82 = load i64, i64* @STDIN_FILENO
%83 = load i32, i32* @TCSAFLUSH
%84 = call i32 @tcsetattr(i64 %82, i32 %83, %struct.termios* %4)
br label %85
85: ; preds = %39, %79
%86 = phi i8* [ %80, %79 ], [ null, %39 ]
ret i8* %86
}