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


x86 assembly (clang, -O0):
<tgCompare>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%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 <tgCompare+0x4c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1194 <tgCompare+0x54>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x5c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x58(%rbp)
js     11e1 <tgCompare+0xa1>
movss  -0x5c(%rbp),%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x58(%rbp),%xmm0
movss  %xmm0,-0x7c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x78(%rbp)
test   %rax,%rax
movss  %xmm0,-0x74(%rbp)
js     1228 <tgCompare+0xe8>
movss  -0x78(%rbp),%xmm0
movss  %xmm0,-0x74(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdi
movss  -0x7c(%rbp),%xmm0
movss  -0x74(%rbp),%xmm1
divss  %xmm1,%xmm0
call   1060 <tg_big_create@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x84(%rbp)
ff
test   %rax,%rax
movss  %xmm0,-0x80(%rbp)
js     12a0 <tgCompare+0x160>
movss  -0x84(%rbp),%xmm0
ff
movss  %xmm0,-0x80(%rbp)
movss  -0x80(%rbp),%xmm0
movss  %xmm0,-0xa4(%rbp)
ff
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0xa0(%rbp)
ff
test   %rax,%rax
movss  %xmm0,-0x9c(%rbp)
ff
js     12f6 <tgCompare+0x1b6>
movss  -0xa0(%rbp),%xmm0
ff
movss  %xmm0,-0x9c(%rbp)
ff
mov    -0x90(%rbp),%rsi
mov    -0x98(%rbp),%rdi
movss  -0xa4(%rbp),%xmm0
ff
movss  -0x9c(%rbp),%xmm2
ff
movss  0xce4(%rip),%xmm1
mulss  %xmm2,%xmm1
divss  %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    1362 <tgCompare+0x222>
imul   $0xffffffffffffffff,-0x48(%rbp),%rax
mov    %eax,-0x54(%rbp)
jmp    1388 <tgCompare+0x248>
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    137c <tgCompare+0x23c>
mov    -0x50(%rbp),%rax
mov    %eax,-0x54(%rbp)
jmp    1383 <tgCompare+0x243>
movl   $0x0,-0x54(%rbp)
jmp    1388 <tgCompare+0x248>
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    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tgCompare>:
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
test   %rax,%rax
js     1196 <tgCompare+0x56>
cvtsi2ss %rax,%xmm0
test   %rbx,%rbx
jns    11b0 <tgCompare+0x70>
mov    %rbx,%rax
shr    %rax
and    $0x1,%ebx
or     %rax,%rbx
cvtsi2ss %rbx,%xmm1
addss  %xmm1,%xmm1
jmp    11b5 <tgCompare+0x75>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
test   %rbx,%rbx
js     117f <tgCompare+0x3f>
cvtsi2ss %rbx,%xmm1
movss  %xmm0,0xc(%rsp)
divss  %xmm1,%xmm0
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <tg_big_create@plt>
mov    %rax,%r12
test   %r13,%r13
js     11dc <tgCompare+0x9c>
xorps  %xmm1,%xmm1
cvtsi2ss %r13,%xmm1
jmp    11f5 <tgCompare+0xb5>
mov    %r13,%rax
shr    %rax
and    $0x1,%r13d
or     %rax,%r13
xorps  %xmm1,%xmm1
cvtsi2ss %r13,%xmm1
addss  %xmm1,%xmm1
movss  0xc(%rsp),%xmm0
divss  %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 @tgCompare(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 float
%31 = fmul float 1.000000e+00, %30
%32 = load i64, i64* %7
%33 = uitofp i64 %32 to float
%34 = fmul float 1.000000e+00, %33
%35 = fdiv float %31, %34
%36 = call i16* @tg_big_create(i8* %27, i8* %28, float %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 float
%41 = fmul float 1.000000e+00, %40
%42 = load i64, i64* %8
%43 = uitofp i64 %42 to float
%44 = fmul float 1.000000e+00, %43
%45 = fdiv float %41, %44
%46 = call i16* @tg_big_create(i8* %37, i8* %38, float %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 = mul i64 -1, %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 @tgCompare(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 float
%9 = uitofp i64 %4 to float
%10 = fdiv float %8, %9
%11 = tail call i16* @tg_big_create(i8* %0, i8* %2, float %10)
%12 = uitofp i64 %5 to float
%13 = fdiv float %8, %12
%14 = tail call i16* @tg_big_create(i8* %1, i8* %2, float %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
}