#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 */

/* Variables and functions */
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int use_line(char *line, int *ca_count, char *chn) {
  char buffer1[3], buffer2[4], buffer3;
  strncpy(buffer1, line, 3);
  strncpy(buffer2, line + 12, 4);
  strncpy(&buffer3, line + 16, 1);
  if (strncmp(buffer1, "TER", 3) == 0 && ca_count - 1 > 0)
    return 1;
  if (strncmp(buffer1, "ATO", 3) != 0)
    return 2;
  if (strncmp(buffer2, "CA  ", 4) != 0 && strncmp(buffer2, " CA ", 4) != 0 &&
      strncmp(buffer2, "  CA", 4) != 0)
    return 2;
  if (buffer3 != *chn && buffer3 != ' ')
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<use_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x23(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x27(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xc,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
lea    -0x28(%rbp),%rdi
mov    $0x1,%edx
call   1030 <strncpy@plt>
lea    -0x23(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11af <use_line+0x8f>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
cmp    $0x0,%rax
jbe    11af <use_line+0x8f>
movl   $0x1,-0x4(%rbp)
jmp    1276 <use_line+0x156>
lea    -0x23(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11da <use_line+0xba>
movl   $0x2,-0x4(%rbp)
jmp    1276 <use_line+0x156>
lea    -0x27(%rbp),%rdi
lea    0xe23(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1243 <use_line+0x123>
lea    -0x27(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1243 <use_line+0x123>
lea    -0x27(%rbp),%rdi
lea    0xdef(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1243 <use_line+0x123>
movl   $0x2,-0x4(%rbp)
jmp    1276 <use_line+0x156>
movsbl -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     126f <use_line+0x14f>
movsbl -0x28(%rbp),%eax
cmp    $0x20,%eax
je     126f <use_line+0x14f>
movl   $0x2,-0x4(%rbp)
jmp    1276 <use_line+0x156>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<use_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
lea    0x5(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0xc(%rbx),%rsi
lea    0x1(%rsp),%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
add    $0x10,%rbx
mov    %rsp,%rdi
mov    $0x1,%ebp
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
lea    0xe8b(%rip),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1211 <use_line+0xf1>
lea    0xe72(%rip),%rsi
lea    0x5(%rsp),%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
mov    $0x2,%ebp
test   %rax,%rax
jne    1211 <use_line+0xf1>
lea    0xe56(%rip),%rsi
lea    0x1(%rsp),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11fc <use_line+0xdc>
lea    0xe40(%rip),%rsi
lea    0x1(%rsp),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11fc <use_line+0xdc>
lea    0xe2a(%rip),%rsi
lea    0x1(%rsp),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1211 <use_line+0xf1>
mov    (%rsp),%al
cmp    (%r14),%al
setne  %cl
cmp    $0x20,%al
setne  %al
and    %cl,%al
movzbl %al,%ebp
add    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"TER\00"
@.str.1 = [4 x i8] c"ATO\00"
@.str.2 = [5 x i8] c"CA \00"
@.str.3 = [5 x i8] c" CA \00"
@.str.4 = [5 x i8] c" CA\00"
define i32 @use_line(i8* %0, i32* nocapture readnone %1, i8* nocapture %2) {
%4 = alloca [3 x i8]
%5 = alloca [4 x i8]
%6 = alloca i8
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%9 = call i32 @strncpy(i8* %7, i8* %0, i32 3)
%10 = getelementptr inbounds i8, i8* %0, i64 12
%11 = call i32 @strncpy(i8* %8, i8* %10, i32 4)
%12 = getelementptr inbounds i8, i8* %0, i64 16
%13 = call i32 @strncpy(i8* %6, i8* %12, i32 1)
%14 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %3
%17 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25, %22, %19
%29 = load i8, i8* %6
%30 = load i8, i8* %2
%31 = icmp ne i8 %29, %30
%32 = icmp ne i8 %29, 32
%33 = and i1 %32, %31
%34 = select i1 %33, i32 2, i32 0
br label %35
35: ; preds = %28, %25, %16, %3
%36 = phi i32 [ 1, %3 ], [ 2, %16 ], [ 2, %25 ], [ %34, %28 ]
ret i32 %36
}