#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 int32_t;

/* Variables and functions */
int optima_comparison(char *, char *, int);
scalar_t__ optima_found_lb(char *, int);
char *optima_seek_line(char *, int);
int optima_comparison_full(char *a, char *b, int32_t index, int32_t len) {
  b = optima_seek_line(b, index);
  if (b == NULL)
    return -1;
  if (optima_found_lb(b, len) != 0)
    return 0;
  int32_t count = 0;
  while (1) {
    if (optima_comparison(a, b, len) == 1) {
      count++;
      a = optima_seek_line(a, len);
    } else {
      a = optima_seek_line(a, 1);
    }
    if (a == NULL)
      break;
  }
  return count;
}


x86 assembly (clang, -O0):
<optima_comparison_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <optima_seek_line@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116d <optima_comparison_full+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <optima_comparison_full+0xca>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <optima_found_lb@plt>
cmp    $0x0,%rax
je     118f <optima_comparison_full+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11fa <optima_comparison_full+0xca>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <optima_comparison@plt>
cmp    $0x1,%eax
jne    11cd <optima_comparison_full+0x9d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <optima_seek_line@plt>
mov    %rax,-0x10(%rbp)
jmp    11df <optima_comparison_full+0xaf>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <optima_seek_line@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ef <optima_comparison_full+0xbf>
jmp    11f4 <optima_comparison_full+0xc4>
jmp    1196 <optima_comparison_full+0x66>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optima_comparison_full>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %edx,%esi
call   1050 <optima_seek_line@plt>
test   %rax,%rax
je     11a3 <optima_comparison_full+0x73>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15d,%esi
call   1030 <optima_found_lb@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    11a8 <optima_comparison_full+0x78>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <optima_comparison@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
mov    $0x1,%esi
cmove  %r15d,%esi
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <optima_seek_line@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <optima_comparison_full+0x40>
jmp    11a8 <optima_comparison_full+0x78>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @optima_comparison_full(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %7
%12 = load i32, i32* %8
%13 = call i8* @optima_seek_line(i8* %11, i32 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %46
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = load i32, i32* %9
%20 = call i64 @optima_found_lb(i8* %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %5
br label %46
23: ; preds = %17
store i32 0, i32* %10
br label %24
24: ; preds = %23, %43
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = load i32, i32* %9
%28 = call i32 @optima_comparison(i8* %25, i8* %26, i32 %27)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
%33 = load i8*, i8** %6
%34 = load i32, i32* %9
%35 = call i8* @optima_seek_line(i8* %33, i32 %34)
store i8* %35, i8** %6
br label %39
36: ; preds = %24
%37 = load i8*, i8** %6
%38 = call i8* @optima_seek_line(i8* %37, i32 1)
store i8* %38, i8** %6
br label %39
39: ; preds = %36, %30
%40 = load i8*, i8** %6
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %39
br label %44
43: ; preds = %39
br label %24
44: ; preds = %42
%45 = load i32, i32* %10
store i32 %45, i32* %5
br label %46
46: ; preds = %44, %22, %16
%47 = load i32, i32* %5
ret i32 %47
}

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