#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ parse(char *);
int /*<<< orphan*/ print();
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  int i;
  int fd;
  char buf[4096];
  while (1) {
    fd = open("/proc/schedstat", O_RDONLY);
    if (fd < 0)
      return -1;
    i = read(fd, buf, sizeof(buf) - 1);
    close(fd);
    buf[i] = '\0';
    if (parse(buf))
      return -1;
    print();
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11a7 <main+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <main+0xaa>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0xfff,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
call   1070 <parse@plt>
cmp    $0x0,%rax
je     11f4 <main+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <main+0xaa>
mov    $0x0,%al
call   1040 <print@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1179 <main+0x19>
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    0x2e72(%rip),%r12
mov    (%r12),%esi
lea    0xe7f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11ef <main+0x8f>
mov    %eax,%ebp
mov    %rsp,%r15
lea    0xe6a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xfff,%edx
call   1050 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
call   1070 <parse@plt>
test   %rax,%rax
jne    11ef <main+0x8f>
xor    %eax,%eax
call   1040 <print@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11a0 <main+0x40>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/schedstat\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %2, %28
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 -1, i32* %3
br label %31
15: ; preds = %9
%16 = load i32, i32* %7
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 4095)
store i32 %18, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%25 = call i64 @parse(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %15
store i32 -1, i32* %3
br label %31
28: ; preds = %15
%29 = call i32 (...) @print()
%30 = call i32 @sleep(i32 1)
br label %9
31: ; preds = %27, %14
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/schedstat\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %2, %16
%9 = phi i32 [ %20, %16 ], [ %6, %2 ]
%10 = call i32 @read(i32 %9, i8* %4, i32 4095)
%11 = call i32 @close(i32 %9)
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i64 @parse(i8* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %8
%17 = call i32 (...) @print()
%18 = call i32 @sleep(i32 1)
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %16, %8, %2
ret i32 -1
}