#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 */
unsigned long getdvalue();
int getonebyte();
unsigned long htime();
int dowaitquiet(void) {
  unsigned long timeout, timequiet, quiet, now;
  int c, quit;
  timeout = htime() + getdvalue();
  quiet = getdvalue();
  timequiet = htime() + quiet;
  quit = 1;
  while (quit == 1) {
    now = htime();
    c = getonebyte();
    if (c != -1)
      timequiet = now + quiet;
    if (now >= timequiet)
      quit = 0;
    if (now >= timeout)
      quit = 255;
  }
  return (quit);
}


x86 assembly (clang, -O0):
<dowaitquiet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <htime@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <getdvalue@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getdvalue@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <htime@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    11dd <dowaitquiet+0xad>
mov    $0x0,%al
call   1040 <htime@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getonebyte@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     11ae <dowaitquiet+0x7e>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11c3 <dowaitquiet+0x93>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11d8 <dowaitquiet+0xa8>
movl   $0xff,-0x28(%rbp)
jmp    1179 <dowaitquiet+0x49>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dowaitquiet>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1040 <htime@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getdvalue@plt>
mov    %rax,%r14
add    %rbx,%r14
xor    %eax,%eax
call   1050 <getdvalue@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1040 <htime@plt>
mov    %rax,%rbx
add    %r15,%rbx
mov    $0xff,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <htime@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <getonebyte@plt>
lea    (%r12,%r15,1),%rcx
cmp    $0xffffffff,%eax
cmovne %rcx,%rbx
xor    %eax,%eax
cmp    %rbx,%r12
setb   %al
cmp    %r14,%r12
cmovae %ebp,%eax
cmp    $0x1,%eax
je     1170 <dowaitquiet+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dowaitquiet() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = call i64 (...) @htime()
%8 = call i64 (...) @getdvalue()
%9 = add i64 %7, %8
store i64 %9, i64* %1
%10 = call i64 (...) @getdvalue()
store i64 %10, i64* %3
%11 = call i64 (...) @htime()
%12 = load i64, i64* %3
%13 = add i64 %11, %12
store i64 %13, i64* %2
store i32 1, i32* %6
br label %14
14: ; preds = %36, %0
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = call i64 (...) @htime()
store i64 %18, i64* %4
%19 = call i32 (...) @getonebyte()
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i64, i64* %4
%24 = load i64, i64* %3
%25 = add i64 %23, %24
store i64 %25, i64* %2
br label %26
26: ; preds = %22, %17
%27 = load i64, i64* %4
%28 = load i64, i64* %2
%29 = icmp uge i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %6
br label %31
31: ; preds = %30, %26
%32 = load i64, i64* %4
%33 = load i64, i64* %1
%34 = icmp uge i64 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 255, i32* %6
br label %36
36: ; preds = %35, %31
br label %14
37: ; preds = %14
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
define i32 @dowaitquiet() {
%1 = tail call i64 (...) @htime()
%2 = tail call i64 (...) @getdvalue()
%3 = add i64 %2, %1
%4 = tail call i64 (...) @getdvalue()
%5 = tail call i64 (...) @htime()
%6 = add i64 %5, %4
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ %6, %0 ], [ %13, %7 ]
%9 = tail call i64 (...) @htime()
%10 = tail call i32 (...) @getonebyte()
%11 = icmp eq i32 %10, -1
%12 = add i64 %9, %4
%13 = select i1 %11, i64 %8, i64 %12
%14 = icmp ult i64 %9, %13
%15 = zext i1 %14 to i32
%16 = icmp ult i64 %9, %3
%17 = select i1 %16, i32 %15, i32 255
%18 = icmp eq i32 %17, 1
br i1 %18, label %7, label %19
19: ; preds = %7
ret i32 %17
}