#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 */
unsigned long long cpu_stats_get_intr();
int /*<<< orphan*/ printf(char *, unsigned long long, ...);
unsigned long *proc_interrupts_get_nintr_per_cpu(unsigned int *);
int /*<<< orphan*/ sleep(unsigned int);
unsigned long long get_intrdelta(unsigned int *ncpus0, unsigned int *ncpus1,
                                 unsigned long *(*vintr)[2], unsigned int count,
                                 unsigned int delay, signed char verbose) {
  unsigned long long nintr[2], dnintr;
  unsigned int i, tog = 0;
  dnintr = nintr[0] = cpu_stats_get_intr();
  if (verbose)
    printf("intr = %llu\n", dnintr);
  if (count <= 2)
    (*vintr)[0] = proc_interrupts_get_nintr_per_cpu(ncpus0);
  for (i = 1; i < count; i++) {
    sleep(delay);
    tog = !tog;
    nintr[tog] = cpu_stats_get_intr();
    dnintr = (nintr[tog] - nintr[!tog]) / delay;
    if (verbose)
      printf("intr = %llu --> %llu/s\n", nintr[tog], dnintr);
    if (count - 2 == i)
      (*vintr)[0] = proc_interrupts_get_nintr_per_cpu(ncpus0);
    else if (count - 1 == i)
      (*vintr)[1] = proc_interrupts_get_nintr_per_cpu(ncpus1);
  }
  return dnintr;
}


x86 assembly (clang, -O0):
<get_intrdelta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %r9b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %al,-0x21(%rbp)
movl   $0x0,-0x50(%rbp)
mov    $0x0,%al
call   1040 <cpu_stats_get_intr@plt>
mov    %rax,-0x40(%rbp)
mov    %rax,-0x48(%rbp)
cmpb   $0x0,-0x21(%rbp)
je     1193 <get_intrdelta+0x53>
mov    -0x48(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x1c(%rbp)
ja     11b0 <get_intrdelta+0x70>
mov    -0x8(%rbp),%rdi
call   1050 <proc_interrupts_get_nintr_per_cpu@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    12a0 <get_intrdelta+0x160>
mov    -0x20(%rbp),%edi
call   1060 <sleep@plt>
cmpl   $0x0,-0x50(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x50(%rbp)
mov    $0x0,%al
call   1040 <cpu_stats_get_intr@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%eax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x50(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rax
cmpl   $0x0,-0x50(%rbp)
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
sub    -0x40(%rbp,%rcx,8),%rax
mov    -0x20(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x48(%rbp)
cmpb   $0x0,-0x21(%rbp)
je     123e <get_intrdelta+0xfe>
mov    -0x50(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rsi
mov    -0x48(%rbp),%rdx
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
cmp    -0x4c(%rbp),%eax
jne    1265 <get_intrdelta+0x125>
mov    -0x8(%rbp),%rdi
call   1050 <proc_interrupts_get_nintr_per_cpu@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    128d <get_intrdelta+0x14d>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cmp    -0x4c(%rbp),%eax
jne    1288 <get_intrdelta+0x148>
mov    -0x10(%rbp),%rdi
call   1050 <proc_interrupts_get_nintr_per_cpu@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    128d <get_intrdelta+0x14d>
jmp    1292 <get_intrdelta+0x152>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11b7 <get_intrdelta+0x77>
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_intrdelta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,%ebx
mov    %r8d,0xc(%rsp)
mov    %ecx,%ebp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdi,0x18(%rsp)
xor    %eax,%eax
call   1040 <cpu_stats_get_intr@plt>
mov    %rax,%r12
mov    %rax,0x30(%rsp)
mov    %ebx,%r13d
test   %bl,%bl
je     118e <get_intrdelta+0x4e>
lea    0xe7c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebp
ja     11ae <get_intrdelta+0x6e>
mov    0x18(%rsp),%rdi
call   1050 <proc_interrupts_get_nintr_per_cpu@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
cmp    $0x2,%ebp
jne    125f <get_intrdelta+0x11f>
mov    0xc(%rsp),%r14d
add    $0xffffffff,%ebp
mov    0x10(%rsp),%rax
add    $0x8,%rax
mov    %rax,0x20(%rsp)
xor    %r15d,%r15d
jmp    11e1 <get_intrdelta+0xa1>
nopl   0x0(%rax)
call   1050 <proc_interrupts_get_nintr_per_cpu@plt>
mov    %rax,(%rbx)
xor    $0x1,%r15d
add    $0xffffffff,%ebp
je     125f <get_intrdelta+0x11f>
mov    0xc(%rsp),%edi
call   1060 <sleep@plt>
xor    %ebx,%ebx
test   %r15d,%r15d
sete   %bl
xor    %eax,%eax
call   1040 <cpu_stats_get_intr@plt>
mov    %rax,%rsi
mov    %rax,0x30(%rsp,%rbx,8)
mov    %r15d,%ecx
sub    0x30(%rsp,%rcx,8),%rax
mov    %rax,%rcx
shr    $0x20,%rcx
je     1250 <get_intrdelta+0x110>
xor    %edx,%edx
div    %r14
mov    %rax,%r12
test   %r13b,%r13b
je     1230 <get_intrdelta+0xf0>
lea    0xde7(%rip),%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rbx
cmp    $0x2,%ebp
je     11d0 <get_intrdelta+0x90>
mov    0x28(%rsp),%rdi
mov    0x20(%rsp),%rbx
cmp    $0x1,%ebp
je     11d0 <get_intrdelta+0x90>
jmp    11d8 <get_intrdelta+0x98>
xor    %edx,%edx
div    %r14d
mov    %eax,%r12d
test   %r13b,%r13b
jne    121f <get_intrdelta+0xdf>
jmp    1230 <get_intrdelta+0xf0>
mov    %r12,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"intr = %llu\0A\00"
@.str.1 = [24 x i8] c"intr = %llu --> %llu/s\0A\00"
define i64 @get_intrdelta(i32* %0, i32* %1, [2 x i64*]* %2, i32 %3, i32 %4, i8 signext %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [2 x i64*]*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca [2 x i64]
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store [2 x i64*]* %2, [2 x i64*]** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8 %5, i8* %12
store i32 0, i32* %16
%17 = call i64 (...) @cpu_stats_get_intr()
%18 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 0
store i64 %17, i64* %18
store i64 %17, i64* %14
%19 = load i8, i8* %12
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %6
%22 = load i64, i64* %14
%23 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %22)
br label %24
24: ; preds = %21, %6
%25 = load i32, i32* %10
%26 = icmp ule i32 %25, 2
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32*, i32** %7
%29 = call i64* @proc_interrupts_get_nintr_per_cpu(i32* %28)
%30 = load [2 x i64*]*, [2 x i64*]** %9
%31 = getelementptr inbounds [2 x i64*], [2 x i64*]* %30, i64 0, i64 0
store i64* %29, i64** %31
br label %32
32: ; preds = %27, %24
store i32 1, i32* %15
br label %33
33: ; preds = %94, %32
%34 = load i32, i32* %15
%35 = load i32, i32* %10
%36 = icmp ult i32 %34, %35
br i1 %36, label %37, label %97
37: ; preds = %33
%38 = load i32, i32* %11
%39 = call i32 @sleep(i32 %38)
%40 = load i32, i32* %16
%41 = icmp ne i32 %40, 0
%42 = xor i1 %41, true
%43 = zext i1 %42 to i32
store i32 %43, i32* %16
%44 = call i64 (...) @cpu_stats_get_intr()
%45 = load i32, i32* %16
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 %46
store i64 %44, i64* %47
%48 = load i32, i32* %16
%49 = zext i32 %48 to i64
%50 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 %49
%51 = load i64, i64* %50
%52 = load i32, i32* %16
%53 = icmp ne i32 %52, 0
%54 = xor i1 %53, true
%55 = zext i1 %54 to i32
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 %56
%58 = load i64, i64* %57
%59 = sub i64 %51, %58
%60 = load i32, i32* %11
%61 = zext i32 %60 to i64
%62 = udiv i64 %59, %61
store i64 %62, i64* %14
%63 = load i8, i8* %12
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %37
%66 = load i32, i32* %16
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 %67
%69 = load i64, i64* %68
%70 = load i64, i64* %14
%71 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %69, i64 %70)
br label %72
72: ; preds = %65, %37
%73 = load i32, i32* %10
%74 = sub i32 %73, 2
%75 = load i32, i32* %15
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %82
77: ; preds = %72
%78 = load i32*, i32** %7
%79 = call i64* @proc_interrupts_get_nintr_per_cpu(i32* %78)
%80 = load [2 x i64*]*, [2 x i64*]** %9
%81 = getelementptr inbounds [2 x i64*], [2 x i64*]* %80, i64 0, i64 0
store i64* %79, i64** %81
br label %93
82: ; preds = %72
%83 = load i32, i32* %10
%84 = sub i32 %83, 1
%85 = load i32, i32* %15
%86 = icmp eq i32 %84, %85
br i1 %86, label %87, label %92
87: ; preds = %82
%88 = load i32*, i32** %8
%89 = call i64* @proc_interrupts_get_nintr_per_cpu(i32* %88)
%90 = load [2 x i64*]*, [2 x i64*]** %9
%91 = getelementptr inbounds [2 x i64*], [2 x i64*]* %90, i64 0, i64 1
store i64* %89, i64** %91
br label %92
92: ; preds = %87, %82
br label %93
93: ; preds = %92, %77
br label %94
94: ; preds = %93
%95 = load i32, i32* %15
%96 = add i32 %95, 1
store i32 %96, i32* %15
br label %33
97: ; preds = %33
%98 = load i64, i64* %14
ret i64 %98
}

LLVM IR (-O2):
@.str = [13 x i8] c"intr = %llu\0A\00"
@.str.1 = [24 x i8] c"intr = %llu --> %llu/s\0A\00"
define i64 @get_intrdelta(i32* %0, i32* %1, [2 x i64*]* nocapture writeonly %2, i32 %3, i32 %4, i8 signext %5) {
%7 = alloca [2 x i64]
%8 = bitcast [2 x i64]* %7 to i8*
%9 = tail call i64 (...) @cpu_stats_get_intr()
%10 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 0
store i64 %9, i64* %10
%11 = icmp eq i8 %5, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %14
14: ; preds = %12, %6
%15 = icmp ult i32 %3, 3
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = tail call i64* @proc_interrupts_get_nintr_per_cpu(i32* %0)
%18 = getelementptr inbounds [2 x i64*], [2 x i64*]* %2, i64 0, i64 0
store i64* %17, i64** %18
%19 = icmp eq i32 %3, 2
br i1 %19, label %20, label %53
20: ; preds = %14, %16
%21 = zext i32 %4 to i64
%22 = add i32 %3, -2
%23 = add i32 %3, -1
%24 = getelementptr inbounds [2 x i64*], [2 x i64*]* %2, i64 0, i64 1
%25 = getelementptr inbounds [2 x i64*], [2 x i64*]* %2, i64 0, i64 0
br label %26
26: ; preds = %20, %50
%27 = phi i32 [ 0, %20 ], [ %31, %50 ]
%28 = phi i32 [ 1, %20 ], [ %51, %50 ]
%29 = tail call i32 @sleep(i32 %4)
%30 = icmp eq i32 %27, 0
%31 = xor i32 %27, 1
%32 = tail call i64 (...) @cpu_stats_get_intr()
%33 = zext i1 %30 to i64
%34 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 %33
store i64 %32, i64* %34
%35 = zext i32 %27 to i64
%36 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = sub i64 %32, %37
%39 = udiv i64 %38, %21
br i1 %11, label %42, label %40
40: ; preds = %26
%41 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %32, i64 %39)
br label %42
42: ; preds = %40, %26
%43 = icmp eq i32 %22, %28
br i1 %43, label %46, label %44
44: ; preds = %42
%45 = icmp eq i32 %23, %28
br i1 %45, label %46, label %50
46: ; preds = %44, %42
%47 = phi i32* [ %0, %42 ], [ %1, %44 ]
%48 = phi i64** [ %25, %42 ], [ %24, %44 ]
%49 = tail call i64* @proc_interrupts_get_nintr_per_cpu(i32* %47)
store i64* %49, i64** %48
br label %50
50: ; preds = %46, %44
%51 = add nuw i32 %28, 1
%52 = icmp eq i32 %51, %3
br i1 %52, label %53, label %26
53: ; preds = %50, %16
%54 = phi i64 [ %9, %16 ], [ %39, %50 ]
ret i64 %54
}