#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 *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int use_line(char *, int *, char *);
int count_ca(char *pdf_file, char *chn) {
  FILE *file;
  int ca_count = 0, is_usable;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  file = fopen(pdf_file, "r");
  while ((read = getline(&line, &len, file)) != -1) {
    is_usable = use_line(line, &ca_count, chn);
    if (is_usable == 1)
      break;
    else if (is_usable == 2)
      continue;
    ca_count++;
  }
  fclose(file);
  return ca_count;
}


x86 assembly (clang, -O0):
<count_ca>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     11dd <count_ca+0x9d>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
call   1040 <use_line@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11bb <count_ca+0x7b>
jmp    11dd <count_ca+0x9d>
cmpl   $0x2,-0x20(%rbp)
jne    11ca <count_ca+0x8a>
jmp    117b <count_ca+0x3b>
jmp    11cf <count_ca+0x8f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <count_ca+0x3b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_ca>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe8f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11e4 <count_ca+0xa4>
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x18(%rsp),%r13
jmp    11c3 <count_ca+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11e4 <count_ca+0xa4>
mov    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <use_line@plt>
cmp    $0x2,%eax
je     11b0 <count_ca+0x70>
cmp    $0x1,%eax
je     11e4 <count_ca+0xa4>
addl   $0x1,0xc(%rsp)
jmp    11b0 <count_ca+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @count_ca(i8* nocapture %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @getline(i8** %4, i64* %5, i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %21, label %12
12: ; preds = %2, %18
%13 = load i8*, i8** %4
%14 = call i32 @use_line(i8* %13, i32* %3, i8* %1)
switch i32 %14, label %15 [
i32 1, label %21
i32 2, label %18
]
15: ; preds = %12
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %12
%19 = call i32 @getline(i8** %4, i64* %5, i32* %9)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %12
21: ; preds = %18, %12, %2
%22 = call i32 @fclose(i32* %9)
%23 = load i32, i32* %3
ret i32 %23
}