#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ isCommentLine(char *);
scalar_t__ isLabel(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int configz_countLabel(const char *configfile, const char *label) {
  FILE *file = fopen(configfile, "r");
  if (file == NULL) {
    return -1;
  }
  char buffer[1024];
  memset(buffer, 0, 1024);
  int label_len = strlen(label);
  int label_num = 0;
  while (fgets(buffer, 1024, file) != NULL) {
    if (isCommentLine(buffer)) {
      continue;
    }
    if (isLabel(buffer) && strlen(buffer) == label_len + 2 &&
        strncmp(buffer + 1, label, label_len) == 0) {
      label_num++;
    }
  }
  fclose(file);
  return label_num;
}


x86 assembly (clang, -O0):
<configz_countLabel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11be <configz_countLabel+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <configz_countLabel+0x121>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     128f <configz_countLabel+0x10f>
lea    -0x420(%rbp),%rdi
call   1090 <isCommentLine@plt>
cmp    $0x0,%rax
je     1224 <configz_countLabel+0xa4>
jmp    11ea <configz_countLabel+0x6a>
lea    -0x420(%rbp),%rdi
call   1080 <isLabel@plt>
cmp    $0x0,%rax
je     128a <configz_countLabel+0x10a>
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x424(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jne    128a <configz_countLabel+0x10a>
lea    -0x420(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    128a <configz_countLabel+0x10a>
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    11ea <configz_countLabel+0x6a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x428(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configz_countLabel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1240 <configz_countLabel+0xc0>
mov    %rax,%rbx
mov    %rsp,%rbp
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %eax,%r12d
add    $0x2,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1236 <configz_countLabel+0xb6>
mov    %rbp,%rdi
call   1090 <isCommentLine@plt>
test   %rax,%rax
jne    11e0 <configz_countLabel+0x60>
mov    %rbp,%rdi
call   1080 <isLabel@plt>
test   %rax,%rax
je     11e0 <configz_countLabel+0x60>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    %r12d,%eax
jne    11e0 <configz_countLabel+0x60>
lea    0x1(%rsp),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%r15d
jmp    11e0 <configz_countLabel+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1246 <configz_countLabel+0xc6>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @configz_countLabel(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %55
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 1024)
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %8
store i32 0, i32* %9
br label %20
20: ; preds = %50, %29, %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32* @fgets(i8* %21, i32 1024, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i64 @isCommentLine(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
br label %20
30: ; preds = %25
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i64 @isLabel(i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %50
34: ; preds = %30
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 2
%39 = icmp eq i32 %36, %38
br i1 %39, label %40, label %50
40: ; preds = %34
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8*, i8** %5
%44 = load i32, i32* %8
%45 = call i64 @strncmp(i8* %42, i8* %43, i32 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %50
50: ; preds = %47, %40, %34, %30
br label %20
51: ; preds = %20
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32, i32* %9
store i32 %54, i32* %3
br label %55
55: ; preds = %51, %14
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @configz_countLabel(i8* nocapture %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %35, label %6
6: ; preds = %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
%9 = call i32 @strlen(i8* %1)
%10 = add nsw i32 %9, 2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
br label %12
12: ; preds = %28, %6
%13 = phi i32 [ %32, %28 ], [ 0, %6 ]
br label %14
14: ; preds = %27, %12
br label %15
15: ; preds = %14, %18
%16 = call i32* @fgets(i8* %7, i32 1024, i32* %4)
%17 = icmp eq i32* %16, null
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = call i64 @isCommentLine(i8* %7)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %18
%22 = call i64 @isLabel(i8* %7)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = call i32 @strlen(i8* %7)
%26 = icmp eq i32 %25, %10
br i1 %26, label %28, label %27
27: ; preds = %24, %21
br label %14
28: ; preds = %24
%29 = call i64 @strncmp(i8* %11, i8* %1, i32 %9)
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = add nuw nsw i32 %13, %31
br label %12
33: ; preds = %15
%34 = call i32 @fclose(i32* %4)
br label %35
35: ; preds = %2, %33
%36 = phi i32 [ %13, %33 ], [ -1, %2 ]
ret i32 %36
}