#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*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int CountTrees(FILE *fv) {
  int n;
  if (fv == NULL)
    return 0;
  n = 0;
  while (!feof(fv)) {
    if (fgetc(fv) == ';')
      n++;
  }
  rewind(fv);
  return n;
}


x86 assembly (clang, -O0):
<CountTrees>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <CountTrees+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11aa <CountTrees+0x7a>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1178 <CountTrees+0x48>
jmp    119b <CountTrees+0x6b>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0x3b,%eax
jne    1196 <CountTrees+0x66>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <CountTrees+0x2a>
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountTrees>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1177 <CountTrees+0x47>
mov    %rdi,%rbx
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    116d <CountTrees+0x3d>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0x3b,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1150 <CountTrees+0x20>
mov    %rbx,%rdi
call   1030 <rewind@plt>
jmp    1179 <CountTrees+0x49>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CountTrees(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %27
8: ; preds = %1
store i32 0, i32* %4
br label %9
9: ; preds = %22, %8
%10 = load i32*, i32** %3
%11 = call i32 @feof(i32* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32*, i32** %3
%16 = call signext i8 @fgetc(i32* %15)
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 59
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %22
22: ; preds = %19, %14
br label %9
23: ; preds = %9
%24 = load i32*, i32** %3
%25 = call i32 @rewind(i32* %24)
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %7
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @CountTrees(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i32 @feof(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %3, %6
%7 = phi i32 [ %11, %6 ], [ 0, %3 ]
%8 = tail call signext i8 @fgetc(i32* %0)
%9 = icmp eq i8 %8, 59
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = tail call i32 @feof(i32* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %6, %3
%15 = phi i32 [ 0, %3 ], [ %11, %6 ]
%16 = tail call i32 @rewind(i32* %0)
br label %17
17: ; preds = %1, %14
%18 = phi i32 [ %15, %14 ], [ 0, %1 ]
ret i32 %18
}