#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 timeval {
  long tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main(void) {
  long int start;
  long long int duration;
  long long int max_duration = 0;
  struct timeval previous;
  struct timeval now;
  gettimeofday(&now, NULL);
  start = now.tv_sec;
  do {
    previous = now;
    gettimeofday(&now, NULL);
    duration = now.tv_sec - previous.tv_sec;
    duration *= 1000000;
    duration += now.tv_usec - previous.tv_usec;
    if (duration > max_duration)
      max_duration = duration;
  } while ((now.tv_sec - start) < 10);
  fprintf(stdout, "Max preemption = %lld us\n", max_duration);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x40(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
imul   $0xf4240,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    11a7 <main+0x87>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11ac <main+0x8c>
mov    -0x40(%rbp),%rax
sub    -0x10(%rbp),%rax
cmp    $0xa,%rax
jl     114c <main+0x2c>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe2e(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%r15
mov    0x10(%rsp),%r12
mov    %r15,%r13
nopl   0x0(%rax)
mov    %rbx,%rbp
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    %rax,%rdx
sub    %r13,%rdx
imul   $0xf4240,%rdx,%rdx
mov    %rcx,%rbx
sub    %r12,%rbx
add    %rdx,%rbx
cmp    %rbp,%rbx
cmovle %rbp,%rbx
mov    %rax,%r13
sub    %r15,%rax
mov    %rcx,%r12
cmp    $0xa,%rax
jl     1150 <main+0x30>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@stdout = global i32 0
@.str = [26 x i8] c"Max preemption = %lld us\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
store i32 0, i32* %1
store i64 0, i64* %4
%7 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%9 = load i64, i64* %8
store i64 %9, i64* %2
br label %10
10: ; preds = %34, %0
%11 = bitcast %struct.timeval* %5 to i8*
%12 = bitcast %struct.timeval* %6 to i8*
%13 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = sub nsw i64 %15, %17
store i64 %18, i64* %3
%19 = load i64, i64* %3
%20 = mul nsw i64 %19, 1000000
store i64 %20, i64* %3
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%24 = load i64, i64* %23
%25 = sub nsw i64 %22, %24
%26 = load i64, i64* %3
%27 = add nsw i64 %26, %25
store i64 %27, i64* %3
%28 = load i64, i64* %3
%29 = load i64, i64* %4
%30 = icmp sgt i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %10
%32 = load i64, i64* %3
store i64 %32, i64* %4
br label %33
33: ; preds = %31, %10
br label %34
34: ; preds = %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%36 = load i64, i64* %35
%37 = load i64, i64* %2
%38 = sub nsw i64 %36, %37
%39 = icmp slt i64 %38, 10
br i1 %39, label %10, label %40
40: ; preds = %34
%41 = load i32, i32* @stdout
%42 = load i64, i64* %4
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %42)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@stdout = global i32 0
@.str = [26 x i8] c"Max preemption = %lld us\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ %7, %0 ], [ %16, %8 ]
%10 = phi i64 [ %5, %0 ], [ %13, %8 ]
%11 = phi i64 [ 0, %0 ], [ %20, %8 ]
%12 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%13 = load i64, i64* %4
%14 = sub nsw i64 %13, %10
%15 = mul nsw i64 %14, 1000000
%16 = load i64, i64* %6
%17 = sub nsw i64 %16, %9
%18 = add nsw i64 %15, %17
%19 = icmp sgt i64 %18, %11
%20 = select i1 %19, i64 %18, i64 %11
%21 = sub nsw i64 %13, %5
%22 = icmp slt i64 %21, 10
br i1 %22, label %8, label %23
23: ; preds = %8
%24 = load i32, i32* @stdout
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %20)
ret i32 0
}