#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 */

/* Variables and functions */
scalar_t__ next_line(char *);
int /*<<< orphan*/ reset_buffer();
char *strstr(char *, char *);
int count_vertices() {
  int result = 0;
  char *ptr;
  char line[1000];
  reset_buffer();
  while (next_line(line) == 0) {
    ptr = strstr(line, "node");
    if (ptr != NULL)
      result++;
  }
  return result;
}


x86 assembly (clang, -O0):
<count_vertices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <reset_buffer@plt>
lea    -0x400(%rbp),%rdi
call   1030 <next_line@plt>
cmp    $0x0,%rax
jne    118f <count_vertices+0x5f>
lea    -0x400(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <count_vertices+0x5a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1149 <count_vertices+0x19>
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_vertices>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <reset_buffer@plt>
mov    %rsp,%rdi
call   1030 <next_line@plt>
test   %rax,%rax
jne    117f <count_vertices+0x4f>
xor    %ebx,%ebx
lea    0xea5(%rip),%r14
mov    %rsp,%r15
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
mov    %r15,%rdi
call   1030 <next_line@plt>
test   %rax,%rax
je     1160 <count_vertices+0x30>
mov    %ebx,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"node\00"
define i32 @count_vertices() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [1000 x i8]
store i32 0, i32* %1
%4 = call i32 (...) @reset_buffer()
br label %5
5: ; preds = %17, %0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = call i64 @next_line(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
br label %17
17: ; preds = %14, %9
br label %5
18: ; preds = %5
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"node\00"
define i32 @count_vertices() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @reset_buffer()
%4 = call i64 @next_line(i8* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %0, %6
%7 = phi i32 [ %11, %6 ], [ 0, %0 ]
%8 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = call i64 @next_line(i8* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %6, %0
%15 = phi i32 [ 0, %0 ], [ %11, %6 ]
ret i32 %15
}