#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ io_error();
int number_of_interface(void) {
  FILE *statfp;
  statfp = fopen("/proc/net/dev", "r");
  if (statfp == NULL) {
    io_error();
    exit(1);
  }
  int n_iface = 0;
  char buffer[255];
  fgets(buffer, 255, statfp);
  fgets(buffer, 255, statfp);
  while (fgets(buffer, 255, statfp)) {
    n_iface++;
  }
  fclose(statfp);
  return (n_iface);
}


x86 assembly (clang, -O0):
<number_of_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118e <number_of_interface+0x3e>
mov    $0x0,%al
call   1070 <io_error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ec <number_of_interface+0x9c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bf <number_of_interface+0x6f>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_of_interface>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ce <number_of_interface+0x7e>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    $0xffffffff,%ebp
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11a0 <number_of_interface+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1070 <io_error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @number_of_interface() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [255 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (...) @io_error()
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
store i32 0, i32* %2
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i64 @fgets(i8* %11, i32 255, i32* %12)
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %1
%16 = call i64 @fgets(i8* %14, i32 255, i32* %15)
br label %17
17: ; preds = %22, %10
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%19 = load i32*, i32** %1
%20 = call i64 @fgets(i8* %18, i32 255, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %17
25: ; preds = %17
%26 = load i32*, i32** %1
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @number_of_interface() {
%1 = alloca [255 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 (...) @io_error()
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%9 = call i64 @fgets(i8* %8, i32 255, i32* %2)
%10 = call i64 @fgets(i8* %8, i32 255, i32* %2)
br label %11
11: ; preds = %11, %7
%12 = phi i32 [ 0, %7 ], [ %15, %11 ]
%13 = call i64 @fgets(i8* %8, i32 255, i32* %2)
%14 = icmp eq i64 %13, 0
%15 = add nuw nsw i32 %12, 1
br i1 %14, label %16, label %11
16: ; preds = %11
%17 = call i32 @fclose(i32* %2)
ret i32 %12
}