#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 timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ usleep(int);
int readcall(char *filename) {
  struct timespec tim;
  tim.tv_sec = 0;
  tim.tv_nsec = 1;
  char buffer[BUFSIZ];
  int filedesc = open(filename, O_RDONLY);
  if (filedesc < 0)
    return 1;
  while (read(filedesc, buffer, sizeof(buffer)) > 0)
    usleep(1);
  return 0;
}


x86 assembly (clang, -O0):
<readcall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11ad <readcall+0x7d>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    11eb <readcall+0xbb>
jmp    11b2 <readcall+0x82>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rax
mov    -0x34(%rbp),%edi
mov    %eax,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
jle    11dd <readcall+0xad>
mov    $0x1,%edi
call   1050 <usleep@plt>
jmp    11b2 <readcall+0x82>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcall>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e96(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     119e <readcall+0x6e>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <read@plt>
xor    %r12d,%r12d
test   %rax,%rax
jle    11a4 <readcall+0x74>
nop
mov    $0x1,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <read@plt>
test   %rax,%rax
jg     1180 <readcall+0x50>
jmp    11a4 <readcall+0x74>
mov    $0x1,%r12d
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@BUFSIZ = global i32 0
@O_RDONLY = global i32 0
define i32 @readcall(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.timespec
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 1, i32* %10
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %5
%14 = alloca i8, i64 %12
store i64 %12, i64* %6
%15 = load i8*, i8** %3
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %1
store i32 1, i32* %2
store i32 1, i32* %8
br label %30
21: ; preds = %1
br label %22
22: ; preds = %27, %21
%23 = load i32, i32* %7
%24 = trunc i64 %12 to i32
%25 = call i64 @read(i32 %23, i8* %14, i32 %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @usleep(i32 1)
br label %22
29: ; preds = %22
store i32 0, i32* %2
store i32 1, i32* %8
br label %30
30: ; preds = %29, %20
%31 = load i8*, i8** %5
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@O_RDONLY = global i32 0
define i32 @readcall(i8* nocapture %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = call i64 @read(i32 %6, i8* %4, i32 %2)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8, %11
%12 = tail call i32 @usleep(i32 1)
%13 = call i64 @read(i32 %6, i8* %4, i32 %2)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %11, label %15
15: ; preds = %11, %8, %1
%16 = phi i32 [ 1, %1 ], [ 0, %8 ], [ 0, %11 ]
ret i32 %16
}