#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 */
char *batman_adv_originators_file_path(char const *const, int *const);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
unsigned int mu_badv_mesh_n_nodes(const char *const interface_name,
                                  int *const error) {
  if (error) {
    *error = 0;
  };
  char *bat_interface_originators_file =
      batman_adv_originators_file_path(interface_name, error);
  if (!bat_interface_originators_file) {
    if (error) {
      *error = errno;
    };
    return 0;
  }
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  fp = fopen(bat_interface_originators_file, "r");
  free(bat_interface_originators_file);
  if (!fp) {
    if (error) {
      *error = errno;
    };
    return 0;
  }
  unsigned int counter = 0;
  while ((read = getline(&line, &len, fp)) != -1) {
    counter++;
    if (!strcmp(line, "No batman nodes in range ...\n")) {
      free(line);
      fclose(fp);
      return 1;
    }
  }
  free(line);
  fclose(fp);
  return counter - 2 + 1;
}


x86 assembly (clang, -O0):
<mu_badv_mesh_n_nodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1185 <mu_badv_mesh_n_nodes+0x25>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <batman_adv_originators_file_path@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <mu_badv_mesh_n_nodes+0x67>
cmpq   $0x0,-0x18(%rbp)
je     11bb <mu_badv_mesh_n_nodes+0x5b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12ac <mu_badv_mesh_n_nodes+0x14c>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1225 <mu_badv_mesh_n_nodes+0xc5>
cmpq   $0x0,-0x18(%rbp)
je     1219 <mu_badv_mesh_n_nodes+0xb9>
mov    0x2dcf(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12ac <mu_badv_mesh_n_nodes+0x14c>
movl   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     128e <mu_badv_mesh_n_nodes+0x12e>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1289 <mu_badv_mesh_n_nodes+0x129>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <mu_badv_mesh_n_nodes+0x14c>
jmp    122c <mu_badv_mesh_n_nodes+0xcc>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mu_badv_mesh_n_nodes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
test   %rsi,%rsi
je     11a0 <mu_badv_mesh_n_nodes+0x40>
movl   $0x0,(%r14)
mov    %r14,%rsi
call   1080 <batman_adv_originators_file_path@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11b5 <mu_badv_mesh_n_nodes+0x55>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %ebx,%ebx
jmp    1268 <mu_badv_mesh_n_nodes+0x108>
xor    %ebx,%ebx
xor    %esi,%esi
call   1080 <batman_adv_originators_file_path@plt>
mov    %rax,%r12
test   %rax,%rax
je     1268 <mu_badv_mesh_n_nodes+0x108>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe32(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     1241 <mu_badv_mesh_n_nodes+0xe1>
mov    $0xffffffff,%ebx
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xe06(%rip),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     1256 <mu_badv_mesh_n_nodes+0xf6>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
add    $0x1,%ebx
test   %eax,%eax
jne    1200 <mu_badv_mesh_n_nodes+0xa0>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebx
jmp    1268 <mu_badv_mesh_n_nodes+0x108>
xor    %ebx,%ebx
test   %r14,%r14
je     1268 <mu_badv_mesh_n_nodes+0x108>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
jmp    1268 <mu_badv_mesh_n_nodes+0x108>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [30 x i8] c"No batman nodes in range ...\0A\00"
define i32 @mu_badv_mesh_n_nodes(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32*, i32** %5
store i32 0, i32* %15
br label %16
16: ; preds = %14, %2
%17 = load i8*, i8** %4
%18 = load i32*, i32** %5
%19 = call i8* @batman_adv_originators_file_path(i8* %17, i32* %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %29, label %22
22: ; preds = %16
%23 = load i32*, i32** %5
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = load i32*, i32** %5
store i32 %26, i32* %27
br label %28
28: ; preds = %25, %22
store i32 0, i32* %3
br label %68
29: ; preds = %16
store i8* null, i8** %8
store i64 0, i64* %9
%30 = load i8*, i8** %6
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %31, i32** %7
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
%34 = load i32*, i32** %7
%35 = icmp ne i32* %34, null
br i1 %35, label %43, label %36
36: ; preds = %29
%37 = load i32*, i32** %5
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* @errno
%41 = load i32*, i32** %5
store i32 %40, i32* %41
br label %42
42: ; preds = %39, %36
store i32 0, i32* %3
br label %68
43: ; preds = %29
store i32 0, i32* %11
br label %44
44: ; preds = %59, %43
%45 = load i32*, i32** %7
%46 = call i32 @getline(i8** %8, i64* %9, i32* %45)
store i32 %46, i32* %10
%47 = icmp ne i32 %46, -1
br i1 %47, label %48, label %60
48: ; preds = %44
%49 = load i32, i32* %11
%50 = add i32 %49, 1
store i32 %50, i32* %11
%51 = load i8*, i8** %8
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp ne i32 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %48
%55 = load i8*, i8** %8
%56 = call i32 @free(i8* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
store i32 1, i32* %3
br label %68
59: ; preds = %48
br label %44
60: ; preds = %44
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
%65 = load i32, i32* %11
%66 = sub i32 %65, 2
%67 = add i32 %66, 1
store i32 %67, i32* %3
br label %68
68: ; preds = %60, %54, %42, %28
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [30 x i8] c"No batman nodes in range ...\0A\00"
define i32 @mu_badv_mesh_n_nodes(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = icmp eq i32* %1, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i8* @batman_adv_originators_file_path(i8* %0, i32* null)
%8 = icmp eq i8* %7, null
br i1 %8, label %43, label %14
9: ; preds = %2
store i32 0, i32* %1
%10 = tail call i8* @batman_adv_originators_file_path(i8* %0, i32* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32, i32* @errno
store i32 %13, i32* %1
br label %43
14: ; preds = %9, %6
%15 = phi i8* [ %10, %9 ], [ %7, %6 ]
%16 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%17 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%18 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @free(i8* %15)
%20 = icmp eq i32* %18, null
br i1 %20, label %21, label %24
21: ; preds = %14
br i1 %5, label %41, label %22
22: ; preds = %21
%23 = load i32, i32* @errno
store i32 %23, i32* %1
br label %41
24: ; preds = %14, %28
%25 = phi i32 [ %29, %28 ], [ 0, %14 ]
%26 = call i32 @getline(i8** %3, i64* %4, i32* %18)
%27 = icmp eq i32 %26, -1
br i1 %27, label %36, label %28
28: ; preds = %24
%29 = add i32 %25, 1
%30 = load i8*, i8** %3
%31 = call i32 @strcmp(i8* dereferenceable(1) %30, i8* dereferenceable(30) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %24
33: ; preds = %28
%34 = call i32 @free(i8* %30)
%35 = call i32 @fclose(i32* %18)
br label %41
36: ; preds = %24
%37 = load i8*, i8** %3
%38 = call i32 @free(i8* %37)
%39 = call i32 @fclose(i32* %18)
%40 = add i32 %25, -1
br label %41
41: ; preds = %33, %36, %21, %22
%42 = phi i32 [ 0, %22 ], [ 0, %21 ], [ 1, %33 ], [ %40, %36 ]
br label %43
43: ; preds = %6, %12, %41
%44 = phi i32 [ %42, %41 ], [ 0, %12 ], [ 0, %6 ]
ret i32 %44
}