#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 */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ do_stat(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int interval = 0;
  int fd;
  if (argc > 1)
    interval = atoi(argv[1]);
  fd = open("/proc/sys/lnet/stats", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Can't open stat: %s\n", strerror(errno));
    return (1);
  }
  do_stat(fd);
  if (interval == 0)
    return (0);
  for (;;) {
    sleep(interval);
    do_stat(fd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1197 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11f1 <main+0x91>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe35(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <main+0xc9>
mov    -0x18(%rbp),%edi
call   1070 <do_stat@plt>
cmpl   $0x0,-0x14(%rbp)
jne    120f <main+0xaf>
movl   $0x0,-0x4(%rbp)
jmp    1229 <main+0xc9>
jmp    1214 <main+0xb4>
mov    -0x14(%rbp),%edi
call   1080 <sleep@plt>
mov    -0x18(%rbp),%edi
call   1070 <do_stat@plt>
jmp    1214 <main+0xb4>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x2,%edi
jl     1175 <main+0x15>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     11b0 <main+0x50>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <do_stat@plt>
test   %ebx,%ebx
je     11df <main+0x7f>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1080 <sleep@plt>
mov    %ebp,%edi
call   1070 <do_stat@plt>
jmp    11a0 <main+0x40>
mov    0x2e21(%rip),%rax
mov    (%rax),%ebx
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe47(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%eax
jmp    11e1 <main+0x81>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/proc/sys/lnet/stats\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open stat: %s\0A\00"
@errno = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
br label %15
15: ; preds = %10, %2
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
br label %37
25: ; preds = %15
%26 = load i32, i32* %7
%27 = call i32 @do_stat(i32 %26)
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %3
br label %37
31: ; preds = %25
br label %32
32: ; preds = %32, %31
%33 = load i32, i32* %6
%34 = call i32 @sleep(i32 %33)
%35 = load i32, i32* %7
%36 = call i32 @do_stat(i32 %35)
br label %32
37: ; preds = %30, %20
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [21 x i8] c"/proc/sys/lnet/stats\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open stat: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 0, %2 ]
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %24
18: ; preds = %8
%19 = tail call i32 @do_stat(i32 %11)
%20 = icmp eq i32 %9, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %21
%22 = tail call i32 @sleep(i32 %9)
%23 = tail call i32 @do_stat(i32 %11)
br label %21
24: ; preds = %18, %13
%25 = phi i32 [ 1, %13 ], [ 0, %18 ]
ret i32 %25
}