#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 short *tg_big_create(unsigned char const *, unsigned char const *,
                              double);
int /*<<< orphan*/ tg_big_destroy(unsigned short *);
unsigned long tg_big_score(unsigned short *);
unsigned long tg_mini_size(unsigned char const *);
int tg_compare(const unsigned char *a, const unsigned char *b,
               const unsigned char *t) {
  unsigned long asz, bsz, max;
  unsigned short *abt, *bbt;
  unsigned long ascore, dirore;
  int r;
  asz = tg_mini_size(a);
  bsz = tg_mini_size(b);
  if (asz > bsz)
    max = asz;
  else
    max = bsz;
  abt = tg_big_create(a, t, (1.0 * max) / (1.0 * asz));
  bbt = tg_big_create(b, t, (1.0 * max) / (1.0 * bsz));
  ascore = tg_big_score(abt);
  dirore = tg_big_score(bbt);
  if (ascore > dirore)
    r = -ascore;
  else if (ascore < dirore)
    r = dirore;
  else
    r = 0;
  tg_big_destroy(abt);
  tg_big_destroy(bbt);
  return r;
}


x86 assembly (clang, -O0):
<tg_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <tg_mini_size@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <tg_mini_size@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    118c <tg_compare+0x4c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1194 <tg_compare+0x54>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movq   -0x30(%rbp),%xmm0
movaps 0xe68(%rip),%xmm3
movaps %xmm3,-0x80(%rbp)
punpckldq %xmm3,%xmm0
movapd 0xe68(%rip),%xmm2
movaps %xmm2,-0x70(%rbp)
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x20(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1060 <tg_big_create@plt>
movaps -0x80(%rbp),%xmm3
movaps -0x70(%rbp),%xmm1
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movq   -0x30(%rbp),%xmm0
punpckldq %xmm3,%xmm0
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
movq   -0x28(%rbp),%xmm2
punpckldq %xmm3,%xmm2
subpd  %xmm1,%xmm2
movaps %xmm2,%xmm1
unpckhpd %xmm2,%xmm2
addsd  %xmm1,%xmm2
movsd  0xdc8(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1060 <tg_big_create@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <tg_big_score@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <tg_big_score@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jbe    127f <tg_compare+0x13f>
xor    %eax,%eax
sub    -0x48(%rbp),%rax
mov    %eax,-0x54(%rbp)
jmp    12a5 <tg_compare+0x165>
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    1299 <tg_compare+0x159>
mov    -0x50(%rbp),%rax
mov    %eax,-0x54(%rbp)
jmp    12a0 <tg_compare+0x160>
movl   $0x0,-0x54(%rbp)
jmp    12a5 <tg_compare+0x165>
mov    -0x38(%rbp),%rdi
call   1040 <tg_big_destroy@plt>
mov    -0x40(%rbp),%rdi
call   1040 <tg_big_destroy@plt>
mov    -0x54(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tg_compare>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <tg_mini_size@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <tg_mini_size@plt>
mov    %rax,%r13
cmp    %rax,%rbx
cmova  %rbx,%rax
movq   %rax,%xmm0
movdqa 0xe83(%rip),%xmm2
punpckldq %xmm2,%xmm0
movapd 0xe87(%rip),%xmm3
subpd  %xmm3,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm4
movapd %xmm1,(%rsp)
movq   %rbx,%xmm0
punpckldq %xmm2,%xmm0
subpd  %xmm3,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm4,%xmm0
divsd  %xmm1,%xmm0
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <tg_big_create@plt>
mov    %rax,%r12
movq   %r13,%xmm0
punpckldq 0xe22(%rip),%xmm0
subpd  0xe2a(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd (%rsp),%xmm0
divsd  %xmm1,%xmm0
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <tg_big_create@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1050 <tg_big_score@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <tg_big_score@plt>
mov    %rax,%rbx
mov    %r15d,%eax
neg    %eax
xor    %ecx,%ecx
cmp    %rbx,%r15
cmovae %ecx,%ebx
cmova  %eax,%ebx
mov    %r12,%rdi
call   1040 <tg_big_destroy@plt>
mov    %r14,%rdi
call   1040 <tg_big_destroy@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @tg_compare(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i16*
%11 = alloca i16*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%15 = load i8*, i8** %4
%16 = call i64 @tg_mini_size(i8* %15)
store i64 %16, i64* %7
%17 = load i8*, i8** %5
%18 = call i64 @tg_mini_size(i8* %17)
store i64 %18, i64* %8
%19 = load i64, i64* %7
%20 = load i64, i64* %8
%21 = icmp ugt i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = load i64, i64* %7
store i64 %23, i64* %9
br label %26
24: ; preds = %3
%25 = load i64, i64* %8
store i64 %25, i64* %9
br label %26
26: ; preds = %24, %22
%27 = load i8*, i8** %4
%28 = load i8*, i8** %6
%29 = load i64, i64* %9
%30 = uitofp i64 %29 to double
%31 = fmul double 1.000000e+00, %30
%32 = load i64, i64* %7
%33 = uitofp i64 %32 to double
%34 = fmul double 1.000000e+00, %33
%35 = fdiv double %31, %34
%36 = call i16* @tg_big_create(i8* %27, i8* %28, double %35)
store i16* %36, i16** %10
%37 = load i8*, i8** %5
%38 = load i8*, i8** %6
%39 = load i64, i64* %9
%40 = uitofp i64 %39 to double
%41 = fmul double 1.000000e+00, %40
%42 = load i64, i64* %8
%43 = uitofp i64 %42 to double
%44 = fmul double 1.000000e+00, %43
%45 = fdiv double %41, %44
%46 = call i16* @tg_big_create(i8* %37, i8* %38, double %45)
store i16* %46, i16** %11
%47 = load i16*, i16** %10
%48 = call i64 @tg_big_score(i16* %47)
store i64 %48, i64* %12
%49 = load i16*, i16** %11
%50 = call i64 @tg_big_score(i16* %49)
store i64 %50, i64* %13
%51 = load i64, i64* %12
%52 = load i64, i64* %13
%53 = icmp ugt i64 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %26
%55 = load i64, i64* %12
%56 = sub i64 0, %55
%57 = trunc i64 %56 to i32
store i32 %57, i32* %14
br label %67
58: ; preds = %26
%59 = load i64, i64* %12
%60 = load i64, i64* %13
%61 = icmp ult i64 %59, %60
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i64, i64* %13
%64 = trunc i64 %63 to i32
store i32 %64, i32* %14
br label %66
65: ; preds = %58
store i32 0, i32* %14
br label %66
66: ; preds = %65, %62
br label %67
67: ; preds = %66, %54
%68 = load i16*, i16** %10
%69 = call i32 @tg_big_destroy(i16* %68)
%70 = load i16*, i16** %11
%71 = call i32 @tg_big_destroy(i16* %70)
%72 = load i32, i32* %14
ret i32 %72
}

LLVM IR (-O2):
define i32 @tg_compare(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @tg_mini_size(i8* %0)
%5 = tail call i64 @tg_mini_size(i8* %1)
%6 = icmp ugt i64 %4, %5
%7 = select i1 %6, i64 %4, i64 %5
%8 = uitofp i64 %7 to double
%9 = uitofp i64 %4 to double
%10 = fdiv double %8, %9
%11 = tail call i16* @tg_big_create(i8* %0, i8* %2, double %10)
%12 = uitofp i64 %5 to double
%13 = fdiv double %8, %12
%14 = tail call i16* @tg_big_create(i8* %1, i8* %2, double %13)
%15 = tail call i64 @tg_big_score(i16* %11)
%16 = tail call i64 @tg_big_score(i16* %14)
%17 = icmp ugt i64 %15, %16
%18 = trunc i64 %15 to i32
%19 = sub i32 0, %18
%20 = icmp ult i64 %15, %16
%21 = trunc i64 %16 to i32
%22 = select i1 %20, i32 %21, i32 0
%23 = select i1 %17, i32 %19, i32 %22
%24 = tail call i32 @tg_big_destroy(i16* %11)
%25 = tail call i32 @tg_big_destroy(i16* %14)
ret i32 %23
}