#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 */
double getwholetime();
int read(int, char *, int);
int /*<<< orphan*/ usleep(int);
int get_schar(char *p, int fd) {
  char c;
  int notdone = 1;
  double scnt, tcnt;
  scnt = getwholetime();
  while (notdone) {
    if (read(fd, &c, 1) == 1) {
      *p = c;
      return (1);
    } else {
      usleep(100);
    }
    tcnt = getwholetime() - scnt;
    if (tcnt > 0.1) {
      notdone = 0;
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<get_schar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <getwholetime@plt>
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c9 <get_schar+0x99>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    118b <get_schar+0x5b>
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11d0 <get_schar+0xa0>
mov    $0x64,%edi
call   1050 <usleep@plt>
mov    $0x0,%al
call   1040 <getwholetime@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe4d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c4 <get_schar+0x94>
movl   $0x0,-0x1c(%rbp)
jmp    1152 <get_schar+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_schar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <getwholetime@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xf(%rsp),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     1197 <get_schar+0x67>
mov    $0x64,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
call   1040 <getwholetime@plt>
subsd  0x10(%rsp),%xmm0
ucomisd 0xe6d(%rip),%xmm0
jbe    1160 <get_schar+0x30>
jmp    11a3 <get_schar+0x73>
mov    0xf(%rsp),%al
mov    %al,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_schar(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %7
%10 = call double (...) @getwholetime()
store double %10, double* %8
br label %11
11: ; preds = %30, %2
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load i32, i32* %5
%16 = call i32 @read(i32 %15, i8* %6, i32 1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8, i8* %6
%20 = load i8*, i8** %4
store i8 %19, i8* %20
store i32 1, i32* %3
br label %32
21: ; preds = %14
%22 = call i32 @usleep(i32 100)
br label %23
23: ; preds = %21
%24 = call double (...) @getwholetime()
%25 = load double, double* %8
%26 = fsub double %24, %25
store double %26, double* %9
%27 = load double, double* %9
%28 = fcmp ogt double %27, 1.000000e-01
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %7
br label %30
30: ; preds = %29, %23
br label %11
31: ; preds = %11
store i32 0, i32* %3
br label %32
32: ; preds = %31, %18
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @get_schar(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca i8
%4 = tail call double (...) @getwholetime()
br label %5
5: ; preds = %10, %2
%6 = call i32 @read(i32 %1, i8* %3, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = load i8, i8* %3
store i8 %9, i8* %0
br label %15
10: ; preds = %5
%11 = tail call i32 @usleep(i32 100)
%12 = tail call double (...) @getwholetime()
%13 = fsub double %12, %4
%14 = fcmp ogt double %13, 1.000000e-01
br i1 %14, label %15, label %5
15: ; preds = %10, %8
%16 = phi i32 [ 1, %8 ], [ 0, %10 ]
ret i32 %16
}