#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int strcspn(char *, char *);
int get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr) {
  FILE *fp;
  char *line = NULL;
  int irq = 0;
  int p;
  if ((fp = fopen(file, "r")) == NULL)
    return 0;
  do {
    char *_p_ = line;
    if ((128 + 11 * cpu_nr) != 0) {
      if ((line = (char *)realloc(line, (128 + 11 * cpu_nr))) == NULL) {
        perror("realloc");
        exit(4);
      }
      if (!_p_) {
        memset(line, 0, (128 + 11 * cpu_nr));
      }
    }
    if (!line) {
      fprintf(stderr, "srealloc\n");
      exit(4);
    }
  } 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    0xe34(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11eb <get_irqcpu_nr+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    132c <get_irqcpu_nr+0x18c>
jmp    11f0 <get_irqcpu_nr+0x50>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
imul   $0xb,-0x18(%rbp),%eax
add    $0x80,%eax
cmp    $0x0,%eax
je     1266 <get_irqcpu_nr+0xc6>
mov    -0x28(%rbp),%rdi
imul   $0xb,-0x18(%rbp),%esi
add    $0x80,%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1241 <get_irqcpu_nr+0xa1>
lea    0xdd0(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
jne    1261 <get_irqcpu_nr+0xc1>
mov    -0x28(%rbp),%rdi
imul   $0xb,-0x18(%rbp),%edx
add    $0x80,%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    1266 <get_irqcpu_nr+0xc6>
cmpq   $0x0,-0x28(%rbp)
jne    1290 <get_irqcpu_nr+0xf0>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>
jmp    1295 <get_irqcpu_nr+0xf5>
jmp    129a <get_irqcpu_nr+0xfa>
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     12cf <get_irqcpu_nr+0x12f>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    12df <get_irqcpu_nr+0x13f>
jmp    1314 <get_irqcpu_nr+0x174>
mov    -0x28(%rbp),%rdi
lea    0xd2a(%rip),%rsi
call   1060 <strcspn@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    130f <get_irqcpu_nr+0x16f>
cmpl   $0x10,-0x30(%rbp)
jge    130f <get_irqcpu_nr+0x16f>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    129a <get_irqcpu_nr+0xfa>
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,%r14d
lea    0xe49(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     125e <get_irqcpu_nr+0xbe>
mov    %rax,%r15
lea    (%rbx,%rbx,4),%eax
lea    (%rbx,%rax,2),%r12d
sub    $0xffffff80,%r12d
je     1271 <get_irqcpu_nr+0xd1>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12d,%esi
call   1090 <realloc@plt>
test   %rax,%rax
je     1290 <get_irqcpu_nr+0xf0>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124c <get_irqcpu_nr+0xac>
test   %r14d,%r14d
jle    124c <get_irqcpu_nr+0xac>
xor    %ebp,%ebp
lea    0xdf5(%rip),%r13
nop
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcspn@plt>
add    $0xffffffff,%eax
cmp    $0xf,%eax
adc    $0x0,%ebp
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124c <get_irqcpu_nr+0xac>
cmp    %r14d,%ebp
jl     1220 <get_irqcpu_nr+0x80>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1260 <get_irqcpu_nr+0xc0>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>
lea    0xd6b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"realloc\00"
@stderr = global i32 0
@.str.2 = [10 x i8] c"srealloc\0A\00"
@.str.3 = [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 %86
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
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %52, label %48
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 4)
unreachable
52: ; preds = %45
br label %53
53: ; preds = %52
br label %54
54: ; preds = %79, %53
%55 = load i8*, i8** %9
%56 = load i32, i32* %7
%57 = mul nsw i32 11, %56
%58 = add nsw i32 128, %57
%59 = load i32*, i32** %8
%60 = call i32* @fgets(i8* %55, i32 %58, i32* %59)
%61 = icmp ne i32* %60, null
br i1 %61, label %62, label %66
62: ; preds = %54
%63 = load i32, i32* %10
%64 = load i32, i32* %6
%65 = icmp slt i32 %63, %64
br label %66
66: ; preds = %62, %54
%67 = phi i1 [ false, %54 ], [ %65, %62 ]
br i1 %67, label %68, label %80
68: ; preds = %66
%69 = load i8*, i8** %9
%70 = call i32 @strcspn(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 %70, i32* %11
%71 = load i32, i32* %11
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i32, i32* %11
%75 = icmp slt i32 %74, 16
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32, i32* %10
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
br label %79
79: ; preds = %76, %73, %68
br label %54
80: ; preds = %66
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
%83 = load i8*, i8** %9
%84 = call i32 @free(i8* %83)
%85 = load i32, i32* %10
store i32 %85, i32* %4
br label %86
86: ; preds = %80, %16
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"realloc\00"
@stderr = global i32 0
@.str.2 = [10 x i8] c"srealloc\0A\00"
@.str.3 = [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 %42, 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 %23, 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)
%19 = tail call i32* @fgets(i8* %12, i32 %8, i32* %4)
%20 = icmp ne i32* %19, null
%21 = icmp sgt i32 %1, 0
%22 = and i1 %20, %21
br i1 %22, label %27, label %38
23: ; preds = %6
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 4)
unreachable
27: ; preds = %17, %27
%28 = phi i32 [ %33, %27 ], [ 0, %17 ]
%29 = tail call i32 @strcspn(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = add i32 %29, -1
%31 = icmp ult i32 %30, 15
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %28, %32
%34 = tail call i32* @fgets(i8* %12, i32 %8, i32* %4)
%35 = icmp ne i32* %34, null
%36 = icmp slt i32 %33, %1
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %27, label %38
38: ; preds = %27, %17
%39 = phi i32 [ 0, %17 ], [ %33, %27 ]
%40 = tail call i32 @fclose(i32* %4)
%41 = tail call i32 @free(i8* %12)
br label %42
42: ; preds = %3, %38
%43 = phi i32 [ %39, %38 ], [ 0, %3 ]
ret i32 %43
}