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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ realloc(char *, int);
int get_irqcpu_nr(int max_nr_irqcpu, int cpu_nr) {
  FILE *fp;
  static char *line;
  unsigned int irq = 0;
  if ((fp = fopen("/proc/interrupts", "r")) == NULL)
    return 0;
  do {
    char *_p_;
    _p_ = line;
    if (128 + 11 * cpu_nr) {
      if ((line = (char *)realloc(line, (128 + 11 * cpu_nr))) == NULL) {
        perror("realloc");
        exit(4);
      }
      if (!_p_)
        memset(line, 0, (128 + 11 * cpu_nr));
    }
  } while (0);
  while ((fgets(line, 128 + 11 * cpu_nr, fp) != NULL) &&
         (irq < max_nr_irqcpu)) {
    if (isdigit(line[2]))
      irq++;
  }
  fclose(fp);
  return irq;
}


x86 assembly (clang, -O0):
<get_irqcpu_nr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe64(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c2 <get_irqcpu_nr+0x42>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <get_irqcpu_nr+0x152>
jmp    11c7 <get_irqcpu_nr+0x47>
mov    0x2e9a(%rip),%rax
mov    %rax,-0x28(%rbp)
imul   $0xb,-0xc(%rbp),%eax
add    $0x80,%eax
cmp    $0x0,%eax
je     1249 <get_irqcpu_nr+0xc9>
mov    0x2e7d(%rip),%rdi
imul   $0xb,-0xc(%rbp),%esi
add    $0x80,%esi
call   1070 <realloc@plt>
mov    %rax,0x2e67(%rip)
cmp    $0x0,%rax
jne    1221 <get_irqcpu_nr+0xa1>
lea    0xe01(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1244 <get_irqcpu_nr+0xc4>
mov    0x2e35(%rip),%rdi
imul   $0xb,-0xc(%rbp),%edx
add    $0x80,%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    1249 <get_irqcpu_nr+0xc9>
jmp    124e <get_irqcpu_nr+0xce>
jmp    1253 <get_irqcpu_nr+0xd3>
mov    0x2e0e(%rip),%rdi
imul   $0xb,-0xc(%rbp),%esi
add    $0x80,%esi
mov    -0x18(%rbp),%rdx
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     128b <get_irqcpu_nr+0x10b>
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
setb   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    129b <get_irqcpu_nr+0x11b>
jmp    12c3 <get_irqcpu_nr+0x143>
mov    0x2dc6(%rip),%rax
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12be <get_irqcpu_nr+0x13e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1253 <get_irqcpu_nr+0xd3>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_irqcpu_nr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xe6d(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     124c <get_irqcpu_nr+0xcc>
mov    %rax,%r15
mov    0x2eb6(%rip),%rbx
lea    0x0(%rbp,%rbp,4),%eax
lea    0x0(%rbp,%rax,2),%ebp
sub    $0xffffff80,%ebp
je     11f4 <get_irqcpu_nr+0x74>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <realloc@plt>
mov    %rax,0x2e98(%rip)
test   %rax,%rax
je     125b <get_irqcpu_nr+0xdb>
test   %rbx,%rbx
mov    %rax,%rbx
jne    11f4 <get_irqcpu_nr+0x74>
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
mov    0x2e74(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1242 <get_irqcpu_nr+0xc2>
test   %r14d,%r14d
je     1242 <get_irqcpu_nr+0xc2>
xor    %ebx,%ebx
nop
mov    0x2e51(%rip),%rax
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
mov    0x2e3a(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1242 <get_irqcpu_nr+0xc2>
cmp    %r14d,%ebx
jb     1210 <get_irqcpu_nr+0x90>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    124e <get_irqcpu_nr+0xce>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@get_irqcpu_nr.line = internal global i8* null
@.str = [17 x i8] c"/proc/interrupts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"realloc\00"
define i32 @get_irqcpu_nr(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = 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* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %70
12: ; preds = %2
br label %13
13: ; preds = %12
%14 = load i8*, i8** @get_irqcpu_nr.line
store i8* %14, i8** %8
%15 = load i32, i32* %5
%16 = mul nsw i32 11, %15
%17 = add nsw i32 128, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %13
%20 = load i8*, i8** @get_irqcpu_nr.line
%21 = load i32, i32* %5
%22 = mul nsw i32 11, %21
%23 = add nsw i32 128, %22
%24 = call i64 @realloc(i8* %20, i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** @get_irqcpu_nr.line
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 4)
unreachable
30: ; preds = %19
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = load i8*, i8** @get_irqcpu_nr.line
%35 = load i32, i32* %5
%36 = mul nsw i32 11, %35
%37 = add nsw i32 128, %36
%38 = call i32 @memset(i8* %34, i32 0, i32 %37)
br label %39
39: ; preds = %33, %30
br label %40
40: ; preds = %39, %13
br label %41
41: ; preds = %40
br label %42
42: ; preds = %65, %41
%43 = load i8*, i8** @get_irqcpu_nr.line
%44 = load i32, i32* %5
%45 = mul nsw i32 11, %44
%46 = add nsw i32 128, %45
%47 = load i32*, i32** %6
%48 = call i32* @fgets(i8* %43, i32 %46, i32* %47)
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %54
50: ; preds = %42
%51 = load i32, i32* %7
%52 = load i32, i32* %4
%53 = icmp ult i32 %51, %52
br label %54
54: ; preds = %50, %42
%55 = phi i1 [ false, %42 ], [ %53, %50 ]
br i1 %55, label %56, label %66
56: ; preds = %54
%57 = load i8*, i8** @get_irqcpu_nr.line
%58 = getelementptr inbounds i8, i8* %57, i64 2
%59 = load i8, i8* %58
%60 = call i64 @isdigit(i8 signext %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = load i32, i32* %7
%64 = add i32 %63, 1
store i32 %64, i32* %7
br label %65
65: ; preds = %62, %56
br label %42
66: ; preds = %54
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
%69 = load i32, i32* %7
store i32 %69, i32* %3
br label %70
70: ; preds = %66, %11
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@get_irqcpu_nr.line = internal unnamed_addr global i8* null
@.str = [17 x i8] c"/proc/interrupts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"realloc\00"
define i32 @get_irqcpu_nr(i32 %0, i32 %1) {
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %45, label %5
5: ; preds = %2
%6 = load i8*, i8** @get_irqcpu_nr.line
%7 = mul nsw i32 %1, 11
%8 = add nsw i32 %7, 128
%9 = icmp eq i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %5
%11 = tail call i64 @realloc(i8* %6, i32 %8)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** @get_irqcpu_nr.line
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 4)
unreachable
17: ; preds = %10
%18 = icmp eq i8* %6, null
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = tail call i32 @memset(i8* %12, i32 0, i32 %8)
%21 = load i8*, i8** @get_irqcpu_nr.line
br label %22
22: ; preds = %17, %19, %5
%23 = phi i8* [ %12, %17 ], [ %21, %19 ], [ %6, %5 ]
%24 = tail call i32* @fgets(i8* %23, i32 %8, i32* %3)
%25 = icmp ne i32* %24, null
%26 = icmp ne i32 %0, 0
%27 = and i1 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %22, %28
%29 = phi i32 [ %36, %28 ], [ 0, %22 ]
%30 = load i8*, i8** @get_irqcpu_nr.line
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = tail call i64 @isdigit(i8 signext %32)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
%36 = add nuw i32 %29, %35
%37 = load i8*, i8** @get_irqcpu_nr.line
%38 = tail call i32* @fgets(i8* %37, i32 %8, i32* %3)
%39 = icmp ne i32* %38, null
%40 = icmp ult i32 %36, %0
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %28, label %42
42: ; preds = %28, %22
%43 = phi i32 [ 0, %22 ], [ %36, %28 ]
%44 = tail call i32 @fclose(i32* %3)
br label %45
45: ; preds = %2, %42
%46 = phi i32 [ %43, %42 ], [ 0, %2 ]
ret i32 %46
}