#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
unsigned int get_processor_number_online();
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ logging_null(char *, ...);
char *strchr(char *, char);
unsigned long strtoul(char *, char **, int);
unsigned long *xnmalloc(unsigned int, int);
unsigned long *proc_interrupts_get_nintr_per_cpu(unsigned int *ncpus) {
  FILE *fp;
  char *p, *end, *line = NULL;
  size_t len = 0;
  ssize_t chread;
  signed char header = 1;
  unsigned int cpu;
  if ((fp = fopen("/proc"
                  "/interrupts",
                  "r")) == NULL)
    return NULL;
  *ncpus = get_processor_number_online();
  unsigned long value, *vintr = xnmalloc(*ncpus, sizeof(unsigned long));
  while ((chread = getline(&line, &len, fp)) != -1) {
    if (header) {
      header = 0;
      continue;
    }
    p = strchr(line, ':');
    if (NULL == p)
      continue;
    logging_null("%s", line);
    for (cpu = 0; cpu < *ncpus; cpu++) {
      if (*p == '\0' || *p == '\n')
        continue;
      value = strtoul(p + 1, &end, 10);
      logging_null(" --> cpu%d = %lu\n", cpu, value);
      vintr[cpu] += value;
      p = end + 1;
    }
    logging_null("\n");
  }
  free(line);
  return vintr;
}


x86 assembly (clang, -O0):
<proc_interrupts_get_nintr_per_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movb   $0x1,-0x3d(%rbp)
lea    0xe59(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ce <proc_interrupts_get_nintr_per_cpu+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    1311 <proc_interrupts_get_nintr_per_cpu+0x191>
mov    $0x0,%al
call   1030 <get_processor_number_online@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   10a0 <xnmalloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     1300 <proc_interrupts_get_nintr_per_cpu+0x180>
cmpb   $0x0,-0x3d(%rbp)
je     1221 <proc_interrupts_get_nintr_per_cpu+0xa1>
movb   $0x0,-0x3d(%rbp)
jmp    11f1 <proc_interrupts_get_nintr_per_cpu+0x71>
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1244 <proc_interrupts_get_nintr_per_cpu+0xc4>
jmp    11f1 <proc_interrupts_get_nintr_per_cpu+0x71>
mov    -0x30(%rbp),%rsi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1060 <logging_null@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jae    12ed <proc_interrupts_get_nintr_per_cpu+0x16d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     128c <proc_interrupts_get_nintr_per_cpu+0x10c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1291 <proc_interrupts_get_nintr_per_cpu+0x111>
jmp    12df <proc_interrupts_get_nintr_per_cpu+0x15f>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%esi
mov    -0x50(%rbp),%rdx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1060 <logging_null@plt>
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rax
mov    -0x44(%rbp),%ecx
add    (%rax,%rcx,8),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    125d <proc_interrupts_get_nintr_per_cpu+0xdd>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1060 <logging_null@plt>
jmp    11f1 <proc_interrupts_get_nintr_per_cpu+0x71>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_interrupts_get_nintr_per_cpu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe56(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12ef <proc_interrupts_get_nintr_per_cpu+0x16f>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <get_processor_number_online@plt>
mov    %eax,(%rbx)
mov    %eax,%edi
mov    $0x8,%esi
call   10a0 <xnmalloc@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12e3 <proc_interrupts_get_nintr_per_cpu+0x163>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12e3 <proc_interrupts_get_nintr_per_cpu+0x163>
lea    0xdff(%rip),%r12
mov    %r14,0x18(%rsp)
jmp    124e <proc_interrupts_get_nintr_per_cpu+0xce>
xchg   %ax,%ax
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1060 <logging_null@plt>
mov    0x18(%rsp),%r14
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12e3 <proc_interrupts_get_nintr_per_cpu+0x163>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1233 <proc_interrupts_get_nintr_per_cpu+0xb3>
mov    %rax,%r13
lea    0xda4(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <logging_null@plt>
mov    (%rbx),%eax
test   %eax,%eax
je     1220 <proc_interrupts_get_nintr_per_cpu+0xa0>
xor    %r14d,%r14d
jmp    129b <proc_interrupts_get_nintr_per_cpu+0x11b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
mov    %eax,%ecx
cmp    %rcx,%r14
jae    1220 <proc_interrupts_get_nintr_per_cpu+0xa0>
movzbl 0x0(%r13),%ecx
test   %cl,%cl
je     1290 <proc_interrupts_get_nintr_per_cpu+0x110>
cmp    $0xa,%cl
je     1290 <proc_interrupts_get_nintr_per_cpu+0x110>
add    $0x1,%r13
mov    %r13,%rdi
lea    0x20(%rsp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <logging_null@plt>
add    %rbp,(%r15,%r14,8)
mov    0x20(%rsp),%r13
add    $0x1,%r13
mov    (%rbx),%eax
jmp    1290 <proc_interrupts_get_nintr_per_cpu+0x110>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
jmp    12f2 <proc_interrupts_get_nintr_per_cpu+0x172>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/interrupts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [18 x i8] c" --> cpu%d = %lu\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i64* @proc_interrupts_get_nintr_per_cpu(i32* %0) {
%2 = alloca i64*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64*
store i32* %0, i32** %3
store i8* null, i8** %7
store i64 0, i64* %8
store i8 1, i8* %10
%14 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
store i64* null, i64** %2
br label %81
17: ; preds = %1
%18 = call i32 (...) @get_processor_number_online()
%19 = load i32*, i32** %3
store i32 %18, i32* %19
%20 = load i32*, i32** %3
%21 = load i32, i32* %20
%22 = call i64* @xnmalloc(i32 %21, i32 8)
store i64* %22, i64** %13
br label %23
23: ; preds = %75, %36, %30, %17
%24 = load i32*, i32** %4
%25 = call i32 @getline(i8** %7, i64* %8, i32* %24)
store i32 %25, i32* %9
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %77
27: ; preds = %23
%28 = load i8, i8* %10
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
store i8 0, i8* %10
br label %23
31: ; preds = %27
%32 = load i8*, i8** %7
%33 = call i8* @strchr(i8* %32, i8 signext 58)
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = icmp eq i8* null, %34
br i1 %35, label %36, label %37
36: ; preds = %31
br label %23
37: ; preds = %31
%38 = load i8*, i8** %7
%39 = call i32 (i8*, ...) @logging_null(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %38)
store i32 0, i32* %11
br label %40
40: ; preds = %72, %37
%41 = load i32, i32* %11
%42 = load i32*, i32** %3
%43 = load i32, i32* %42
%44 = icmp ult i32 %41, %43
br i1 %44, label %45, label %75
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %56
55: ; preds = %50, %45
br label %72
56: ; preds = %50
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i64 @strtoul(i8* %58, i8** %6, i32 10)
store i64 %59, i64* %12
%60 = load i32, i32* %11
%61 = load i64, i64* %12
%62 = call i32 (i8*, ...) @logging_null(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %60, i64 %61)
%63 = load i64, i64* %12
%64 = load i64*, i64** %13
%65 = load i32, i32* %11
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds i64, i64* %64, i64 %66
%68 = load i64, i64* %67
%69 = add i64 %68, %63
store i64 %69, i64* %67
%70 = load i8*, i8** %6
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8* %71, i8** %5
br label %72
72: ; preds = %56, %55
%73 = load i32, i32* %11
%74 = add i32 %73, 1
store i32 %74, i32* %11
br label %40
75: ; preds = %40
%76 = call i32 (i8*, ...) @logging_null(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %23
77: ; preds = %23
%78 = load i8*, i8** %7
%79 = call i32 @free(i8* %78)
%80 = load i64*, i64** %13
store i64* %80, i64** %2
br label %81
81: ; preds = %77, %16
%82 = load i64*, i64** %2
ret i64* %82
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/interrupts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [18 x i8] c" --> cpu%d = %lu\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i64* @proc_interrupts_get_nintr_per_cpu(i32* nocapture %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %2 to i8*
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %56, label %10
10: ; preds = %1
%11 = tail call i32 (...) @get_processor_number_online()
store i32 %11, i32* %0
%12 = tail call i64* @xnmalloc(i32 %11, i32 8)
%13 = call i32 @getline(i8** %3, i64* %4, i32* %8)
%14 = icmp eq i32 %13, -1
br i1 %14, label %53, label %15
15: ; preds = %10
%16 = call i32 @getline(i8** %3, i64* %4, i32* %8)
%17 = icmp eq i32 %16, -1
br i1 %17, label %53, label %18
18: ; preds = %15, %22
%19 = load i8*, i8** %3
%20 = call i8* @strchr(i8* dereferenceable(1) %19, i8 signext 58)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18, %51
%23 = call i32 @getline(i8** %3, i64* %4, i32* %8)
%24 = icmp eq i32 %23, -1
br i1 %24, label %53, label %18
25: ; preds = %18
%26 = call i32 (i8*, ...) @logging_null(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%27 = load i32, i32* %0
%28 = icmp eq i32 %27, 0
br i1 %28, label %51, label %29
29: ; preds = %25, %45
%30 = phi i32 [ %46, %45 ], [ %27, %25 ]
%31 = phi i64 [ %48, %45 ], [ 0, %25 ]
%32 = phi i8* [ %47, %45 ], [ %20, %25 ]
%33 = load i8, i8* %32
switch i8 %33, label %34 [
i8 0, label %45
i8 10, label %45
]
34: ; preds = %29
%35 = getelementptr inbounds i8, i8* %32, i64 1
%36 = call i64 @strtoul(i8* %35, i8** %2, i32 10)
%37 = trunc i64 %31 to i32
%38 = call i32 (i8*, ...) @logging_null(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %37, i64 %36)
%39 = getelementptr inbounds i64, i64* %12, i64 %31
%40 = load i64, i64* %39
%41 = add i64 %40, %36
store i64 %41, i64* %39
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i32, i32* %0
br label %45
45: ; preds = %29, %29, %34
%46 = phi i32 [ %30, %29 ], [ %44, %34 ], [ %30, %29 ]
%47 = phi i8* [ %32, %29 ], [ %43, %34 ], [ %32, %29 ]
%48 = add nuw nsw i64 %31, 1
%49 = zext i32 %46 to i64
%50 = icmp ult i64 %48, %49
br i1 %50, label %29, label %51
51: ; preds = %45, %25
%52 = call i32 (i8*, ...) @logging_null(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %22
53: ; preds = %22, %15, %10
%54 = load i8*, i8** %3
%55 = call i32 @free(i8* %54)
br label %56
56: ; preds = %1, %53
%57 = phi i64* [ %12, %53 ], [ null, %1 ]
ret i64* %57
}