#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*/ SEEK_SET;
int /*<<< orphan*/ TrimBuffer(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int CountFiles(FILE *fptr) {
  char *result;
  int counter = 0;
  char buffer[1024];
  fseek(fptr, 0, SEEK_SET);
  for (;;) {
    result = fgets(buffer, 1024, fptr);
    if (!result)
      break;
    TrimBuffer(buffer);
    if (buffer[0] != '\0')
      counter++;
  }
  return counter;
}


x86 assembly (clang, -O0):
<CountFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <CountFiles+0x53>
jmp    11ad <CountFiles+0x7d>
lea    -0x420(%rbp),%rdi
call   1030 <TrimBuffer@plt>
movsbl -0x420(%rbp),%eax
cmp    $0x0,%eax
je     11a8 <CountFiles+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <CountFiles+0x2a>
mov    -0x14(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountFiles>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1194 <CountFiles+0x64>
xor    %ebp,%ebp
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <TrimBuffer@plt>
cmpb   $0x1,(%rsp)
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1170 <CountFiles+0x40>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @CountFiles(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32* %0, i32** %2
store i32 0, i32* %4
%6 = load i32*, i32** %2
%7 = load i32, i32* @SEEK_SET
%8 = call i32 @fseek(i32* %6, i32 0, i32 %7)
br label %9
9: ; preds = %26, %1
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i8* @fgets(i8* %10, i32 1024, i32* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %9
br label %27
16: ; preds = %9
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @TrimBuffer(i8* %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %23, %16
br label %9
27: ; preds = %15
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @CountFiles(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %0, i32 0, i32 %4)
%6 = call i8* @fgets(i8* %3, i32 1024, i32* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %14, %8 ], [ 0, %1 ]
%10 = call i32 @TrimBuffer(i8* %3)
%11 = load i8, i8* %3
%12 = icmp ne i8 %11, 0
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %9, %13
%15 = call i8* @fgets(i8* %3, i32 1024, i32* %0)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %8
17: ; preds = %8, %1
%18 = phi i32 [ 0, %1 ], [ %14, %8 ]
ret i32 %18
}