#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 */
unsigned int lcs_count(unsigned int *, unsigned int, char const *, char *const);
unsigned matching_line(unsigned *a, unsigned width, const char *s,
                       char *const *lines) {
  unsigned max_count = 0;
  unsigned match_idx = 0;
  unsigned i;
  for (i = 0; lines[i]; ++i) {
    unsigned count;
    count = lcs_count(a, width, s, lines[i]);
    if (count > max_count) {
      max_count = count;
      match_idx = i;
    }
  }
  return match_idx;
}


x86 assembly (clang, -O0):
<matching_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     1197 <matching_line+0x87>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rcx
call   1030 <lcs_count@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jbe    1184 <matching_line+0x74>
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1189 <matching_line+0x79>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113c <matching_line+0x2c>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matching_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rax
mov    (%rcx),%rcx
test   %rcx,%rcx
je     1187 <matching_line+0x77>
mov    %rdx,%r12
mov    %esi,%r13d
mov    %rdi,%r15
xor    %ebx,%ebx
mov    $0x1,%r14d
xor    %ebp,%ebp
mov    %rax,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%r14),%eax
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r12,%rdx
call   1030 <lcs_count@plt>
cmp    %ebx,%eax
cmova  0xc(%rsp),%ebp
cmova  %eax,%ebx
mov    %r14d,%eax
mov    0x10(%rsp),%rcx
mov    (%rcx,%rax,8),%rcx
add    $0x1,%r14d
test   %rcx,%rcx
jne    1150 <matching_line+0x40>
jmp    1189 <matching_line+0x79>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @matching_line(i32* %0, i32 %1, i8* %2, i8** %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8** %3, i8*** %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %37, %4
%14 = load i8**, i8*** %8
%15 = load i32, i32* %11
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %40
20: ; preds = %13
%21 = load i32*, i32** %5
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = load i8**, i8*** %8
%25 = load i32, i32* %11
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @lcs_count(i32* %21, i32 %22, i8* %23, i8* %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = load i32, i32* %9
%32 = icmp ugt i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %20
%34 = load i32, i32* %12
store i32 %34, i32* %9
%35 = load i32, i32* %11
store i32 %35, i32* %10
br label %36
36: ; preds = %33, %20
br label %37
37: ; preds = %36
%38 = load i32, i32* %11
%39 = add i32 %38, 1
store i32 %39, i32* %11
br label %13
40: ; preds = %13
%41 = load i32, i32* %10
ret i32 %41
}

LLVM IR (-O2):
define i32 @matching_line(i32* %0, i32 %1, i8* %2, i8** nocapture %3) {
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4, %7
%8 = phi i8* [ %19, %7 ], [ %5, %4 ]
%9 = phi i32 [ %15, %7 ], [ 0, %4 ]
%10 = phi i32 [ %16, %7 ], [ 0, %4 ]
%11 = phi i32 [ %14, %7 ], [ 0, %4 ]
%12 = tail call i32 @lcs_count(i32* %0, i32 %1, i8* %2, i8* %8)
%13 = icmp ugt i32 %12, %9
%14 = select i1 %13, i32 %10, i32 %11
%15 = select i1 %13, i32 %12, i32 %9
%16 = add i32 %10, 1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %3, i64 %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %7
21: ; preds = %7, %4
%22 = phi i32 [ 0, %4 ], [ %14, %7 ]
ret i32 %22
}