#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 result {
  int dummy;
};

/* Variables and functions */
double ndcgHalf(struct result *, int, int, double *);
double ndcgNorm(int);
double ndcgMaximize(struct result *r1, int size1, struct result *r2,
                    int size2) {
  double pre1, pre2, max1, max2;
  double norm = ndcgNorm(20);
  size1 = (size1 > 20 ? 20 : size1);
  size2 = (size2 > 20 ? 20 : size2);
  max1 = ndcgHalf(r1, size1, size2, &pre1);
  max2 = ndcgHalf(r2, size2, size1, &pre2);
  max1 += pre1 - pre2;
  max2 += pre2 - pre1;
  return (max1 > max2 ? max1 : max2) / norm;
}


x86 assembly (clang, -O0):
<ndcgMaximize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    $0x14,%edi
call   1040 <ndcgNorm@plt>
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x14,-0xc(%rbp)
jle    115c <ndcgMaximize+0x3c>
mov    $0x14,%eax
mov    %eax,-0x4c(%rbp)
jmp    1162 <ndcgMaximize+0x42>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jle    117f <ndcgMaximize+0x5f>
mov    $0x14,%eax
mov    %eax,-0x50(%rbp)
jmp    1185 <ndcgMaximize+0x65>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1030 <ndcgHalf@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1030 <ndcgHalf@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1202 <ndcgMaximize+0xe2>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    120c <ndcgMaximize+0xec>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndcgMaximize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    $0x14,%ebx
mov    $0x14,%edi
call   1040 <ndcgNorm@plt>
cmp    $0x14,%ebp
cmovge %ebx,%ebp
movsd  %xmm0,0x8(%rsp)
cmp    $0x14,%r12d
cmovl  %r12d,%ebx
lea    0x18(%rsp),%rcx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <ndcgHalf@plt>
movsd  %xmm0,(%rsp)
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <ndcgHalf@plt>
movsd  0x18(%rsp),%xmm2
movsd  0x10(%rsp),%xmm3
movapd %xmm2,%xmm1
subsd  %xmm3,%xmm1
addsd  (%rsp),%xmm1
subsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
maxsd  %xmm3,%xmm1
divsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.result = type { i32 }
define double @ndcgMaximize(%struct.result* %0, i32 %1, %struct.result* %2, i32 %3) {
%5 = alloca %struct.result*
%6 = alloca i32
%7 = alloca %struct.result*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store %struct.result* %0, %struct.result** %5
store i32 %1, i32* %6
store %struct.result* %2, %struct.result** %7
store i32 %3, i32* %8
%14 = call double @ndcgNorm(i32 20)
store double %14, double* %13
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 20
br i1 %16, label %17, label %18
17: ; preds = %4
br label %20
18: ; preds = %4
%19 = load i32, i32* %6
br label %20
20: ; preds = %18, %17
%21 = phi i32 [ 20, %17 ], [ %19, %18 ]
store i32 %21, i32* %6
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 20
br i1 %23, label %24, label %25
24: ; preds = %20
br label %27
25: ; preds = %20
%26 = load i32, i32* %8
br label %27
27: ; preds = %25, %24
%28 = phi i32 [ 20, %24 ], [ %26, %25 ]
store i32 %28, i32* %8
%29 = load %struct.result*, %struct.result** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %8
%32 = call double @ndcgHalf(%struct.result* %29, i32 %30, i32 %31, double* %9)
store double %32, double* %11
%33 = load %struct.result*, %struct.result** %7
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = call double @ndcgHalf(%struct.result* %33, i32 %34, i32 %35, double* %10)
store double %36, double* %12
%37 = load double, double* %9
%38 = load double, double* %10
%39 = fsub double %37, %38
%40 = load double, double* %11
%41 = fadd double %40, %39
store double %41, double* %11
%42 = load double, double* %10
%43 = load double, double* %9
%44 = fsub double %42, %43
%45 = load double, double* %12
%46 = fadd double %45, %44
store double %46, double* %12
%47 = load double, double* %11
%48 = load double, double* %12
%49 = fcmp ogt double %47, %48
br i1 %49, label %50, label %52
50: ; preds = %27
%51 = load double, double* %11
br label %54
52: ; preds = %27
%53 = load double, double* %12
br label %54
54: ; preds = %52, %50
%55 = phi double [ %51, %50 ], [ %53, %52 ]
%56 = load double, double* %13
%57 = fdiv double %55, %56
ret double %57
}

LLVM IR (-O2):
%struct.result = type { i32 }
define double @ndcgMaximize(%struct.result* %0, i32 %1, %struct.result* %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = bitcast double* %5 to i8*
%8 = bitcast double* %6 to i8*
%9 = tail call double @ndcgNorm(i32 20)
%10 = icmp slt i32 %1, 20
%11 = select i1 %10, i32 %1, i32 20
%12 = icmp slt i32 %3, 20
%13 = select i1 %12, i32 %3, i32 20
%14 = call double @ndcgHalf(%struct.result* %0, i32 %11, i32 %13, double* %5)
%15 = call double @ndcgHalf(%struct.result* %2, i32 %13, i32 %11, double* %6)
%16 = load double, double* %5
%17 = load double, double* %6
%18 = fsub double %16, %17
%19 = fadd double %14, %18
%20 = fsub double %17, %16
%21 = fadd double %15, %20
%22 = fcmp ogt double %19, %21
%23 = select i1 %22, double %19, double %21
%24 = fdiv double %23, %9
ret double %24
}