#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 clock_t;

/* Variables and functions */
int clock();
int read(int, char *, int);
int get_schar(char *p, int fd) {
  char c;
  int notdone = 1;
  clock_t scnt, tcnt;
  scnt = clock();
  while (notdone) {
    if (read(fd, &c, 1) == 1) {
      *p = c;
      return (1);
    }
    tcnt = clock() - scnt;
    if (tcnt > 300000) {
      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   1030 <clock@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     119f <get_schar+0x7f>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1179 <get_schar+0x59>
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11a6 <get_schar+0x86>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x493e0,-0x24(%rbp)
jle    119a <get_schar+0x7a>
movl   $0x0,-0x1c(%rbp)
jmp    1140 <get_schar+0x20>
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   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%ebx
lea    0xf(%rsp),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     1177 <get_schar+0x57>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %ebx,%eax
cmp    $0x493e1,%eax
jl     1150 <get_schar+0x30>
jmp    1183 <get_schar+0x63>
mov    0xf(%rsp),%al
mov    %al,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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 i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %7
%10 = call i32 (...) @clock()
store i32 %10, i32* %8
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %29
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 %30
21: ; preds = %14
%22 = call i32 (...) @clock()
%23 = load i32, i32* %8
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 300000
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 0, i32* %7
br label %28
28: ; preds = %27, %21
br label %11
29: ; preds = %11
store i32 0, i32* %3
br label %30
30: ; preds = %29, %18
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @get_schar(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca i8
%4 = tail call i32 (...) @clock()
br label %5
5: ; preds = %2, %10
%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 %14
10: ; preds = %5
%11 = tail call i32 (...) @clock()
%12 = sub nsw i32 %11, %4
%13 = icmp sgt i32 %12, 300000
br i1 %13, label %14, label %5
14: ; preds = %10, %8
%15 = phi i32 [ 1, %8 ], [ 0, %10 ]
ret i32 %15
}