#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int strlen(char const *);
int /*<<< orphan*/ *strstr(char *, char const *);
int countAccountId(const char *pAccountId, const char *pAccounts) {
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  FILE *fp;
  int i = 0;
  if (pAccountId == NULL) {
    return -1;
  }
  if (strlen(pAccountId) != 64) {
    return -1;
  }
  fp = fopen(pAccounts, "r");
  if (fp == NULL) {
    return -1;
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    if (strstr(line, pAccountId) != NULL) {
      i++;
    }
  }
  free(line);
  fclose(fp);
  return i;
}


x86 assembly (clang, -O0):
<countAccountId>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <countAccountId+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <countAccountId+0xe6>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x40,%eax
je     11bc <countAccountId+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <countAccountId+0xe6>
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e7 <countAccountId+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <countAccountId+0xe6>
jmp    11ec <countAccountId+0x8c>
mov    -0x38(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     122e <countAccountId+0xce>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1229 <countAccountId+0xc9>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ec <countAccountId+0x8c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countAccountId>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     1207 <countAccountId+0xa7>
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <strlen@plt>
cmp    $0x40,%eax
jne    1207 <countAccountId+0xa7>
lea    0xe61(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1207 <countAccountId+0xa7>
mov    %rax,%r15
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     11f6 <countAccountId+0x96>
mov    %rsp,%r12
lea    0x8(%rsp),%r13
xchg   %ax,%ax
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
jne    11d0 <countAccountId+0x70>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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