#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 *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ realloc(char *, int);
int strcspn(char *, char *);
int get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr) {
  FILE *fp;
  char *line = NULL;
  unsigned int irq = 0;
  int p;
  if ((fp = fopen(file, "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)) {
    p = strcspn(line, ":");
    if ((p > 0) && (p < 16)) {
      irq++;
    }
  }
  fclose(fp);
  free(line);
  return irq;
}


x86 assembly (clang, -O0):
<get_irqcpu_nr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11db <get_irqcpu_nr+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    12f2 <get_irqcpu_nr+0x162>
jmp    11e0 <get_irqcpu_nr+0x50>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
imul   $0xb,-0x18(%rbp),%eax
add    $0x80,%eax
cmp    $0x0,%eax
je     1256 <get_irqcpu_nr+0xc6>
mov    -0x28(%rbp),%rdi
imul   $0xb,-0x18(%rbp),%esi
add    $0x80,%esi
call   1080 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1231 <get_irqcpu_nr+0xa1>
lea    0xde0(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
jne    1251 <get_irqcpu_nr+0xc1>
mov    -0x28(%rbp),%rdi
imul   $0xb,-0x18(%rbp),%edx
add    $0x80,%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    1256 <get_irqcpu_nr+0xc6>
jmp    125b <get_irqcpu_nr+0xcb>
jmp    1260 <get_irqcpu_nr+0xd0>
mov    -0x28(%rbp),%rdi
imul   $0xb,-0x18(%rbp),%esi
add    $0x80,%esi
mov    -0x20(%rbp),%rdx
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
je     1295 <get_irqcpu_nr+0x105>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setb   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    12a5 <get_irqcpu_nr+0x115>
jmp    12da <get_irqcpu_nr+0x14a>
mov    -0x28(%rbp),%rdi
lea    0xd5a(%rip),%rsi
call   1060 <strcspn@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    12d5 <get_irqcpu_nr+0x145>
cmpl   $0x10,-0x30(%rbp)
jge    12d5 <get_irqcpu_nr+0x145>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1260 <get_irqcpu_nr+0xd0>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_irqcpu_nr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e8 <get_irqcpu_nr+0x58>
mov    %rax,%r14
lea    (%rbx,%rbx,4),%eax
lea    (%rbx,%rax,2),%r12d
xor    %ebx,%ebx
sub    $0xffffff80,%r12d
je     11ec <get_irqcpu_nr+0x5c>
xor    %edi,%edi
mov    %r12d,%esi
call   1080 <realloc@plt>
test   %rax,%rax
je     125d <get_irqcpu_nr+0xcd>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1050 <memset@plt>
jmp    11ee <get_irqcpu_nr+0x5e>
xor    %ebx,%ebx
jmp    124c <get_irqcpu_nr+0xbc>
xor    %ebp,%ebp
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     123c <get_irqcpu_nr+0xac>
test   %r15d,%r15d
je     123c <get_irqcpu_nr+0xac>
xor    %ebx,%ebx
lea    0xdfb(%rip),%r13
nop
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <strcspn@plt>
add    $0xffffffff,%eax
cmp    $0xf,%eax
adc    $0x0,%ebx
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     123c <get_irqcpu_nr+0xac>
cmp    %r15d,%ebx
jb     1210 <get_irqcpu_nr+0x80>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>

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

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