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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int, long long);
int /*<<< orphan*/ stdin;
int main() {
  long long ints[1001];
  int i;
  struct timespec z;
  char *buffer;
  buffer = malloc(1024 * 1024);
  if (buffer == NULL)
    return -1;
  for (i = 0; i < 1001; i++)
    ints[i] = 0;
  if (clock_gettime(CLOCK_REALTIME, &z))
    return -2;
  i = z.tv_nsec;
  while (fread(buffer, 1, 1024 * 32, stdin)) {
    if (clock_gettime(CLOCK_REALTIME, &z))
      return -2;
    i = z.tv_nsec - i;
    while (i < 0)
      i += 1000000000;
    while (i >= 1000000000)
      i -= 1000000000;
    i /= 1000000;
    ints[i]++;
    i = z.tv_nsec;
  }
  for (i = 0; i < 1001; i++)
    if (ints[i])
      printf("%u %llu\n", i + 1, ints[i]);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x1f60(%rbp)
cmpq   $0x0,-0x1f60(%rbp)
jne    118d <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1379 <main+0x229>
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x3e9,-0x1f54(%rbp)
jge    11ce <main+0x7e>
movslq -0x1f54(%rbp),%rax
movq   $0x0,-0x1f50(%rbp,%rax,8)
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1197 <main+0x47>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    -0x1f58(%rbp),%rsi
call   1050 <clock_gettime@plt>
cmp    $0x0,%rax
je     11f9 <main+0xa9>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1379 <main+0x229>
mov    -0x1f58(%rbp),%eax
mov    %eax,-0x1f54(%rbp)
mov    -0x1f60(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x8000,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     12f9 <main+0x1a9>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    -0x1f58(%rbp),%rsi
call   1050 <clock_gettime@plt>
cmp    $0x0,%rax
je     1259 <main+0x109>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1379 <main+0x229>
mov    -0x1f58(%rbp),%eax
sub    -0x1f54(%rbp),%eax
mov    %eax,-0x1f54(%rbp)
cmpl   $0x0,-0x1f54(%rbp)
jge    128e <main+0x13e>
mov    -0x1f54(%rbp),%eax
add    $0x3b9aca00,%eax
mov    %eax,-0x1f54(%rbp)
jmp    126b <main+0x11b>
jmp    1293 <main+0x143>
cmpl   $0x3b9aca00,-0x1f54(%rbp)
ca 9a 3b
jl     12b9 <main+0x169>
mov    -0x1f54(%rbp),%eax
sub    $0x3b9aca00,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1293 <main+0x143>
mov    -0x1f54(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1f54(%rbp)
movslq -0x1f54(%rbp),%rax
mov    -0x1f50(%rbp,%rax,8),%rcx
ff
add    $0x1,%rcx
mov    %rcx,-0x1f50(%rbp,%rax,8)
ff
mov    -0x1f58(%rbp),%eax
mov    %eax,-0x1f54(%rbp)
jmp    1205 <main+0xb5>
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x3e9,-0x1f54(%rbp)
jge    1366 <main+0x216>
movslq -0x1f54(%rbp),%rax
cmpq   $0x0,-0x1f50(%rbp,%rax,8)
je     134d <main+0x1fd>
mov    -0x1f54(%rbp),%esi
add    $0x1,%esi
movslq -0x1f54(%rbp),%rax
mov    -0x1f50(%rbp,%rax,8),%rdx
ff
lea    0xcb8(%rip),%rdi
call   1060 <printf@plt>
jmp    1352 <main+0x202>
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1303 <main+0x1b3>
mov    -0x1f60(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1f60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
mov    $0x100000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12c5 <main+0x165>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x1f48,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x2e39(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
jne    1311 <main+0x1b1>
mov    0x8(%rsp),%r12d
mov    0x2e22(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
call   1040 <fread@plt>
test   %rax,%rax
je     12cc <main+0x16c>
lea    0x8(%rsp),%rbx
jmp    1259 <main+0xf9>
nopw   0x0(%rax,%rax,1)
add    %edx,%r12d
sub    %r12d,%eax
add    $0x3b9ac9ff,%eax
mov    %eax,%edx
shr    $0x9,%edx
imul   $0x44b83,%rdx,%rdx
shr    $0x27,%rdx
imul   $0x3b9aca00,%edx,%edx
mov    %eax,%esi
sub    %edx,%esi
sub    %eax,%esi
add    %ecx,%esi
movslq %esi,%rax
imul   $0x431bde83,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
addq   $0x1,0x10(%rsp,%rax,8)
mov    0x2dab(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
call   1040 <fread@plt>
mov    %r13d,%r12d
test   %rax,%rax
je     12cc <main+0x16c>
mov    (%r15),%edi
mov    %rbx,%rsi
call   1050 <clock_gettime@plt>
test   %rax,%rax
jne    1311 <main+0x1b1>
mov    0x8(%rsp),%r13d
mov    %r13d,%eax
sub    %r12d,%eax
test   %eax,%eax
mov    $0x0,%ecx
cmovle %ecx,%eax
add    %r12d,%eax
xor    %ecx,%ecx
sub    %r13d,%eax
setne  %cl
sub    %ecx,%eax
shr    $0x9,%eax
imul   $0x44b83,%rax,%rax
shr    $0x27,%rax
add    %ecx,%eax
imul   $0x3b9aca00,%eax,%eax
add    %r13d,%eax
mov    %eax,%ecx
sub    %r12d,%ecx
mov    %ecx,%edx
cmp    $0x3b9ac9ff,%ecx
jl     11f0 <main+0x90>
mov    $0x3b9ac9ff,%edx
jmp    11f0 <main+0x90>
mov    $0xffffffff,%ebp
jmp    1311 <main+0x1b1>
xor    %esi,%esi
lea    0xd2b(%rip),%rbp
jmp    12ec <main+0x18c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rsi
cmp    $0x3e9,%rbx
je     1307 <main+0x1a7>
mov    0x10(%rsp,%rsi,8),%rdx
lea    0x1(%rsi),%rbx
test   %rdx,%rdx
je     12e0 <main+0x180>
add    $0x1,%esi
mov    %rbp,%rdi
call   1060 <printf@plt>
jmp    12e0 <main+0x180>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"%u %llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1001 x i64]
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @malloc(i32 1048576)
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %92
10: ; preds = %0
store i32 0, i32* %3
br label %11
11: ; preds = %18, %10
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1001
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1001 x i64], [1001 x i64]* %2, i64 0, i64 %16
store i64 0, i64* %17
br label %18
18: ; preds = %14
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %11
21: ; preds = %11
%22 = load i32, i32* @CLOCK_REALTIME
%23 = call i64 @clock_gettime(i32 %22, %struct.timespec* %4)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 -2, i32* %1
br label %92
26: ; preds = %21
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%28 = load i32, i32* %27
store i32 %28, i32* %3
br label %29
29: ; preds = %57, %26
%30 = load i8*, i8** %5
%31 = load i32, i32* @stdin
%32 = call i64 @fread(i8* %30, i32 1, i32 32768, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %67
34: ; preds = %29
%35 = load i32, i32* @CLOCK_REALTIME
%36 = call i64 @clock_gettime(i32 %35, %struct.timespec* %4)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 -2, i32* %1
br label %92
39: ; preds = %34
%40 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load i32, i32* %3
%43 = sub nsw i32 %41, %42
store i32 %43, i32* %3
br label %44
44: ; preds = %47, %39
%45 = load i32, i32* %3
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1000000000
store i32 %49, i32* %3
br label %44
50: ; preds = %44
br label %51
51: ; preds = %54, %50
%52 = load i32, i32* %3
%53 = icmp sge i32 %52, 1000000000
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %3
%56 = sub nsw i32 %55, 1000000000
store i32 %56, i32* %3
br label %51
57: ; preds = %51
%58 = load i32, i32* %3
%59 = sdiv i32 %58, 1000000
store i32 %59, i32* %3
%60 = load i32, i32* %3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1001 x i64], [1001 x i64]* %2, i64 0, i64 %61
%63 = load i64, i64* %62
%64 = add nsw i64 %63, 1
store i64 %64, i64* %62
%65 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%66 = load i32, i32* %65
store i32 %66, i32* %3
br label %29
67: ; preds = %29
store i32 0, i32* %3
br label %68
68: ; preds = %86, %67
%69 = load i32, i32* %3
%70 = icmp slt i32 %69, 1001
br i1 %70, label %71, label %89
71: ; preds = %68
%72 = load i32, i32* %3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [1001 x i64], [1001 x i64]* %2, i64 0, i64 %73
%75 = load i64, i64* %74
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %85
77: ; preds = %71
%78 = load i32, i32* %3
%79 = add nsw i32 %78, 1
%80 = load i32, i32* %3
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [1001 x i64], [1001 x i64]* %2, i64 0, i64 %81
%83 = load i64, i64* %82
%84 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %79, i64 %83)
br label %85
85: ; preds = %77, %71
br label %86
86: ; preds = %85
%87 = load i32, i32* %3
%88 = add nsw i32 %87, 1
store i32 %88, i32* %3
br label %68
89: ; preds = %68
%90 = load i8*, i8** %5
%91 = call i32 @free(i8* %90)
store i32 0, i32* %1
br label %92
92: ; preds = %89, %38, %25, %9
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"%u %llu\0A\00"
define i32 @main() {
%1 = alloca [1001 x i64]
%2 = bitcast [1001 x i64]* %1 to i8*
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%6 = icmp eq i8* %5, null
br i1 %6, label %66, label %7
7: ; preds = %0
%8 = load i32, i32* @CLOCK_REALTIME
%9 = call i64 @clock_gettime(i32 %8, %struct.timespec* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %66
11: ; preds = %7
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @stdin
%15 = call i64 @fread(i8* %5, i32 1, i32 32768, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %52, label %17
17: ; preds = %11, %22
%18 = phi i32 [ %23, %22 ], [ %13, %11 ]
%19 = load i32, i32* @CLOCK_REALTIME
%20 = call i64 @clock_gettime(i32 %19, %struct.timespec* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %66
22: ; preds = %17
%23 = load i32, i32* %12
%24 = sub i32 %23, %18
%25 = call i32 @llvm.smax.i32(i32 %24, i32 0)
%26 = add i32 %18, %25
%27 = sub i32 %26, %23
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i32
%30 = sub i32 %27, %29
%31 = udiv i32 %30, 1000000000
%32 = add nuw nsw i32 %31, %29
%33 = mul i32 %32, 1000000000
%34 = add i32 %23, %33
%35 = sub i32 %34, %18
%36 = add i32 %23, 999999999
%37 = add i32 %36, %33
%38 = call i32 @llvm.smin.i32(i32 %35, i32 999999999)
%39 = add i32 %18, %38
%40 = sub i32 %37, %39
%41 = urem i32 %40, 1000000000
%42 = sub i32 %41, %40
%43 = add i32 %42, %35
%44 = sdiv i32 %43, 1000000
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [1001 x i64], [1001 x i64]* %1, i64 0, i64 %45
%47 = load i64, i64* %46
%48 = add nsw i64 %47, 1
store i64 %48, i64* %46
%49 = load i32, i32* @stdin
%50 = call i64 @fread(i8* %5, i32 1, i32 32768, i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %17
52: ; preds = %22, %11
br label %53
53: ; preds = %52, %62
%54 = phi i64 [ %58, %62 ], [ 0, %52 ]
%55 = getelementptr inbounds [1001 x i64], [1001 x i64]* %1, i64 0, i64 %54
%56 = load i64, i64* %55
%57 = icmp eq i64 %56, 0
%58 = add nuw nsw i64 %54, 1
br i1 %57, label %62, label %59
59: ; preds = %53
%60 = trunc i64 %58 to i32
%61 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %60, i64 %56)
br label %62
62: ; preds = %53, %59
%63 = icmp eq i64 %58, 1001
br i1 %63, label %64, label %53
64: ; preds = %62
%65 = call i32 @free(i8* %5)
br label %66
66: ; preds = %17, %7, %0, %64
%67 = phi i32 [ 0, %64 ], [ -1, %0 ], [ -2, %7 ], [ -2, %17 ]
ret i32 %67
}