#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 */
scalar_t__ EOF;
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ strncasecmp(char *, char *, int);
int count_vcards(FILE *fp) {
  char *line = NULL;
  size_t len = 0;
  int counter = 0;
  while (getline(&line, &len, fp) != EOF)
    if (0 == strncasecmp(line, "BEGIN:VCARD", 11))
      counter++;
  if (line)
    free(line);
  return counter;
}


x86 assembly (clang, -O0):
<count_vcards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <getline@plt>
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
je     11a5 <count_vcards+0x75>
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a0 <count_vcards+0x70>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <count_vcards+0x23>
cmpq   $0x0,-0x10(%rbp)
je     11b9 <count_vcards+0x89>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_vcards>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <getline@plt>
mov    0x2e7c(%rip),%r13
xor    %ebp,%ebp
cmp    0x0(%r13),%rax
je     11bd <count_vcards+0x8d>
xor    %ebp,%ebp
lea    0xe83(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    $0xb,%edx
call   1040 <strncasecmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <getline@plt>
cmp    0x0(%r13),%rax
jne    1190 <count_vcards+0x60>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11cc <count_vcards+0x9c>
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i64 0
@.str = [12 x i8] c"BEGIN:VCARD\00"
define i32 @count_vcards(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %2
store i8* null, i8** %3
store i64 0, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %18, %1
%7 = load i32*, i32** %2
%8 = call i64 @getline(i8** %3, i64* %4, i32* %7)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = call i64 @strncasecmp(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%14 = icmp eq i64 0, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
br label %18
18: ; preds = %15, %11
br label %6
19: ; preds = %6
%20 = load i8*, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@EOF = global i64 0
@.str = [12 x i8] c"BEGIN:VCARD\00"
define i32 @count_vcards(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = call i64 @getline(i8** %2, i64* %3, i32* %0)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %19, label %9
9: ; preds = %1, %9
%10 = phi i32 [ %15, %9 ], [ 0, %1 ]
%11 = load i8*, i8** %2
%12 = call i64 @strncasecmp(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %10, %14
%16 = call i64 @getline(i8** %2, i64* %3, i32* %0)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %9
19: ; preds = %9, %1
%20 = phi i32 [ 0, %1 ], [ %15, %9 ]
%21 = load i8*, i8** %2
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @free(i8* %21)
br label %25
25: ; preds = %23, %19
ret i32 %20
}