#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 */
struct btp_thread {
  int dummy;
};
struct btp_backtrace {
  int dummy;
};

/* Variables and functions */
struct btp_backtrace *btp_backtrace_dup(struct btp_backtrace *);
struct btp_thread *btp_backtrace_find_crash_thread(struct btp_backtrace *);
int /*<<< orphan*/ btp_backtrace_free(struct btp_backtrace *);
float btp_backtrace_quality_simple(struct btp_backtrace *);
int /*<<< orphan*/ btp_normalize_backtrace(struct btp_backtrace *);
float btp_thread_quality(struct btp_thread *);
int /*<<< orphan*/ btp_thread_remove_frames_below_n(struct btp_thread *, int);
float btp_backtrace_quality_complex(struct btp_backtrace *backtrace) {
  backtrace = btp_backtrace_dup(backtrace);
  struct btp_thread *crash_thread = btp_backtrace_find_crash_thread(backtrace);
  btp_normalize_backtrace(backtrace);
  float q1 = btp_backtrace_quality_simple(backtrace);
  if (!crash_thread) {
    btp_backtrace_free(backtrace);
    return q1;
  }
  float q2 = btp_thread_quality(crash_thread);
  btp_thread_remove_frames_below_n(crash_thread, 5);
  float q3 = btp_thread_quality(crash_thread);
  btp_backtrace_free(backtrace);
  return 0.25f * q1 + 0.35f * q2 + 0.4f * q3;
}


x86 assembly (clang, -O0):
<btp_backtrace_quality_complex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <btp_backtrace_dup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <btp_backtrace_find_crash_thread@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <btp_normalize_backtrace@plt>
mov    -0x10(%rbp),%rdi
call   1030 <btp_backtrace_quality_simple@plt>
movss  %xmm0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <btp_backtrace_quality_complex+0x60>
mov    -0x10(%rbp),%rdi
call   1040 <btp_backtrace_free@plt>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    123f <btp_backtrace_quality_complex+0xcf>
mov    -0x18(%rbp),%rdi
call   1080 <btp_thread_quality@plt>
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x5,%esi
call   1090 <btp_thread_remove_frames_below_n@plt>
mov    -0x18(%rbp),%rdi
call   1080 <btp_thread_quality@plt>
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <btp_backtrace_free@plt>
movss  -0x1c(%rbp),%xmm1
movss  0xdf8(%rip),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  0xde7(%rip),%xmm2
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
movss  0xdce(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btp_backtrace_quality_complex>:
push   %r14
push   %rbx
sub    $0x18,%rsp
call   1070 <btp_backtrace_dup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <btp_backtrace_find_crash_thread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <btp_normalize_backtrace@plt>
mov    %rbx,%rdi
call   1030 <btp_backtrace_quality_simple@plt>
movss  %xmm0,0xc(%rsp)
test   %r14,%r14
je     120a <btp_backtrace_quality_complex+0x9a>
mov    %r14,%rdi
call   1080 <btp_thread_quality@plt>
movss  %xmm0,0x14(%rsp)
mov    %r14,%rdi
mov    $0x5,%esi
call   1090 <btp_thread_remove_frames_below_n@plt>
mov    %r14,%rdi
call   1080 <btp_thread_quality@plt>
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <btp_backtrace_free@plt>
movss  0x14(%rsp),%xmm1
mulss  0xe1c(%rip),%xmm1
movss  0xc(%rsp),%xmm2
mulss  0xe12(%rip),%xmm2
addss  %xmm1,%xmm2
movss  0x10(%rsp),%xmm0
mulss  0xe04(%rip),%xmm0
addss  %xmm2,%xmm0
jmp    1218 <btp_backtrace_quality_complex+0xa8>
mov    %rbx,%rdi
call   1040 <btp_backtrace_free@plt>
movss  0xc(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.btp_backtrace = type { i32 }
%struct.btp_thread = type { i32 }
define float @btp_backtrace_quality_complex(%struct.btp_backtrace* %0) {
%2 = alloca float
%3 = alloca %struct.btp_backtrace*
%4 = alloca %struct.btp_thread*
%5 = alloca float
%6 = alloca float
%7 = alloca float
store %struct.btp_backtrace* %0, %struct.btp_backtrace** %3
%8 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%9 = call %struct.btp_backtrace* @btp_backtrace_dup(%struct.btp_backtrace* %8)
store %struct.btp_backtrace* %9, %struct.btp_backtrace** %3
%10 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%11 = call %struct.btp_thread* @btp_backtrace_find_crash_thread(%struct.btp_backtrace* %10)
store %struct.btp_thread* %11, %struct.btp_thread** %4
%12 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%13 = call i32 @btp_normalize_backtrace(%struct.btp_backtrace* %12)
%14 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%15 = call float @btp_backtrace_quality_simple(%struct.btp_backtrace* %14)
store float %15, float* %5
%16 = load %struct.btp_thread*, %struct.btp_thread** %4
%17 = icmp ne %struct.btp_thread* %16, null
br i1 %17, label %22, label %18
18: ; preds = %1
%19 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%20 = call i32 @btp_backtrace_free(%struct.btp_backtrace* %19)
%21 = load float, float* %5
store float %21, float* %2
br label %37
22: ; preds = %1
%23 = load %struct.btp_thread*, %struct.btp_thread** %4
%24 = call float @btp_thread_quality(%struct.btp_thread* %23)
store float %24, float* %6
%25 = load %struct.btp_thread*, %struct.btp_thread** %4
%26 = call i32 @btp_thread_remove_frames_below_n(%struct.btp_thread* %25, i32 5)
%27 = load %struct.btp_thread*, %struct.btp_thread** %4
%28 = call float @btp_thread_quality(%struct.btp_thread* %27)
store float %28, float* %7
%29 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%30 = call i32 @btp_backtrace_free(%struct.btp_backtrace* %29)
%31 = load float, float* %5
%32 = load float, float* %6
%33 = fmul float 0x3FD6666660000000, %32
%34 = call float @llvm.fmuladd.f32(float 2.500000e-01, float %31, float %33)
%35 = load float, float* %7
%36 = call float @llvm.fmuladd.f32(float 0x3FD99999A0000000, float %35, float %34)
store float %36, float* %2
br label %37
37: ; preds = %22, %18
%38 = load float, float* %2
ret float %38
}

LLVM IR (-O2):
%struct.btp_backtrace = type { i32 }
%struct.btp_thread = type { i32 }
define float @btp_backtrace_quality_complex(%struct.btp_backtrace* %0) {
%2 = tail call %struct.btp_backtrace* @btp_backtrace_dup(%struct.btp_backtrace* %0)
%3 = tail call %struct.btp_thread* @btp_backtrace_find_crash_thread(%struct.btp_backtrace* %2)
%4 = tail call i32 @btp_normalize_backtrace(%struct.btp_backtrace* %2)
%5 = tail call float @btp_backtrace_quality_simple(%struct.btp_backtrace* %2)
%6 = icmp eq %struct.btp_thread* %3, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @btp_backtrace_free(%struct.btp_backtrace* %2)
br label %17
9: ; preds = %1
%10 = tail call float @btp_thread_quality(%struct.btp_thread* %3)
%11 = tail call i32 @btp_thread_remove_frames_below_n(%struct.btp_thread* %3, i32 5)
%12 = tail call float @btp_thread_quality(%struct.btp_thread* %3)
%13 = tail call i32 @btp_backtrace_free(%struct.btp_backtrace* %2)
%14 = fmul float %10, 0x3FD6666660000000
%15 = tail call float @llvm.fmuladd.f32(float %5, float 2.500000e-01, float %14)
%16 = tail call float @llvm.fmuladd.f32(float %12, float 0x3FD99999A0000000, float %15)
br label %17
17: ; preds = %9, %7
%18 = phi float [ %16, %9 ], [ %5, %7 ]
ret float %18
}