#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 fscanf(int /*<<< orphan*/ *, char *, char *);
int count_towns(FILE *ifp) {
  char buf[100];
  int scanres, i = 0;
  scanres = fscanf(ifp, " BY %[^\n]", buf);
  while (scanres == 1) {
    i++;
    scanres = fscanf(ifp, " BY %[^\n]", buf);
  }
  return i;
}


x86 assembly (clang, -O0):
<count_towns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xecb(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x1,-0x74(%rbp)
jne    116c <count_towns+0x5c>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xea1(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x74(%rbp)
jmp    113d <count_towns+0x2d>
mov    -0x78(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_towns>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
lea    0xedc(%rip),%rsi
mov    %rsp,%rdx
call   1030 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jne    1156 <count_towns+0x46>
xor    %ebp,%ebp
lea    0xec4(%rip),%r14
mov    %rsp,%r15
nop
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     1140 <count_towns+0x30>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c" BY %[^\0A]\00"
define i32 @count_towns(i32* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %11
6: ; preds = %1, %6
%7 = phi i32 [ %8, %6 ], [ 0, %1 ]
%8 = add nuw nsw i32 %7, 1
%9 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %6, label %11
11: ; preds = %6, %1
%12 = phi i32 [ 0, %1 ], [ %8, %6 ]
ret i32 %12
}