#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 */
double atof(char *);
double compute_rho(double *, double *, int, int *);
int /*<<< orphan*/ dump_pairing(int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ load_ranking(char *, int *, double **);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ select_pairing(int *, int, int, char **, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ tune_rho(double *, double *, int, int *, double, double,
                            double);
int main(int argc, char *argv[]) {
  int N1, N2;
  double *R1 = NULL;
  double *R2 = NULL;
  double eps, beta, rho, rho_target;
  int *pairing = NULL;
  srand(time(NULL));
  if (argc < 6) {
    printf("Usage: %s <rank1> <rank2> <rho> <eps> <beta> [RND|NAT|INV]\n",
           argv[0]);
    exit(1);
  }
  rho_target = atof(argv[3]);
  eps = atof(argv[4]);
  beta = atof(argv[5]);
  load_ranking(argv[1], &N1, &R1);
  load_ranking(argv[2], &N2, &R2);
  if (N1 != N2) {
    printf("Error!!!! The two files must have the same number of lines!!!! "
           "Exiting...\n");
    exit(1);
  }
  pairing = malloc(N1 * sizeof(int));
  select_pairing(pairing, N1, argc, argv, 6);
  rho = compute_rho(R1, R2, N1, pairing);
  fprintf(stderr, "%g\n", rho);
  tune_rho(R1, R2, N1, pairing, eps, beta, rho_target);
  dump_pairing(pairing, N1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x50(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x6,-0x4(%rbp)
jge    1220 <main+0x60>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10c0 <load_ranking@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10c0 <load_ranking@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     12a4 <main+0xe4>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x6,%r8d
call   1090 <select_pairing@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x50(%rbp),%rcx
call   1030 <compute_rho@plt>
movsd  %xmm0,-0x40(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
movsd  -0x40(%rbp),%xmm0
lea    0xd89(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x50(%rbp),%rcx
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
call   10e0 <tune_rho@plt>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <dump_pairing@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmp    $0x5,%r14d
jle    12fc <main+0x12c>
mov    0x18(%r15),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x30(%rsp)
mov    0x20(%r15),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x28(%rsp)
mov    0x28(%r15),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x20(%rsp)
mov    0x8(%r15),%rdi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   10d0 <load_ranking@plt>
mov    0x10(%r15),%rdi
lea    0x1c(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   10d0 <load_ranking@plt>
mov    0x4(%rsp),%ebx
cmp    0x1c(%rsp),%ebx
jne    1317 <main+0x147>
lea    0x0(,%rbx,4),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15,%rcx
mov    $0x6,%r8d
call   10a0 <select_pairing@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %rbp,%rcx
call   1030 <compute_rho@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %rbp,%rcx
movsd  0x28(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
call   10f0 <tune_rho@plt>
mov    0x4(%rsp),%esi
mov    %rbp,%rdi
call   10c0 <dump_pairing@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xcfa(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd22(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"Usage: %s <rank1> <rank2> <rho> <eps> <beta> [RND|NAT|INV]\0A\00"
@.str.1 = [75 x i8] c"Error!!!! The two files must have the same number of lines!!!! Exiting...\0A\00"
@stderr = global i32 0
@.str.2 = [4 x i8] c"%g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store double* null, double** %7
store double* null, double** %8
store i32* null, i32** %13
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 6
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call double @atof(i8* %27)
store double %28, double* %12
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 4
%31 = load i8*, i8** %30
%32 = call double @atof(i8* %31)
store double %32, double* %9
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 5
%35 = load i8*, i8** %34
%36 = call double @atof(i8* %35)
store double %36, double* %10
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @load_ranking(i8* %39, i32* %5, double** %7)
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @load_ranking(i8* %43, i32* %6, double** %8)
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %24
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %24
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 4
%55 = trunc i64 %54 to i32
%56 = call i32* @malloc(i32 %55)
store i32* %56, i32** %13
%57 = load i32*, i32** %13
%58 = load i32, i32* %5
%59 = load i32, i32* %3
%60 = load i8**, i8*** %4
%61 = call i32 @select_pairing(i32* %57, i32 %58, i32 %59, i8** %60, i32 6)
%62 = load double*, double** %7
%63 = load double*, double** %8
%64 = load i32, i32* %5
%65 = load i32*, i32** %13
%66 = call double @compute_rho(double* %62, double* %63, i32 %64, i32* %65)
store double %66, double* %11
%67 = load i32, i32* @stderr
%68 = load double, double* %11
%69 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %68)
%70 = load double*, double** %7
%71 = load double*, double** %8
%72 = load i32, i32* %5
%73 = load i32*, i32** %13
%74 = load double, double* %9
%75 = load double, double* %10
%76 = load double, double* %12
%77 = call i32 @tune_rho(double* %70, double* %71, i32 %72, i32* %73, double %74, double %75, double %76)
%78 = load i32*, i32** %13
%79 = load i32, i32* %5
%80 = call i32 @dump_pairing(i32* %78, i32 %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [60 x i8] c"Usage: %s <rank1> <rank2> <rho> <eps> <beta> [RND|NAT|INV]\0A\00"
@stderr = global i32 0
@.str.2 = [4 x i8] c"%g\0A\00"
@str = [74 x i8] c"Error!!!! The two files must have the same number of lines!!!! Exiting...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast double** %5 to i8*
store double* null, double** %5
%10 = bitcast double** %6 to i8*
store double* null, double** %6
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
%13 = icmp slt i32 %0, 6
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call double @atof(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call double @atof(i8* %23)
%25 = getelementptr inbounds i8*, i8** %1, i64 5
%26 = load i8*, i8** %25
%27 = tail call double @atof(i8* %26)
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @load_ranking(i8* %29, i32* %3, double** %5)
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @load_ranking(i8* %32, i32* %4, double** %6)
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = icmp eq i32 %34, %35
br i1 %36, label %40, label %37
37: ; preds = %18
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %18
%41 = shl i32 %34, 2
%42 = call i32* @malloc(i32 %41)
%43 = call i32 @select_pairing(i32* %42, i32 %34, i32 %0, i8** %1, i32 6)
%44 = load double*, double** %5
%45 = load double*, double** %6
%46 = load i32, i32* %3
%47 = call double @compute_rho(double* %44, double* %45, i32 %46, i32* %42)
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %47)
%50 = load double*, double** %5
%51 = load double*, double** %6
%52 = load i32, i32* %3
%53 = call i32 @tune_rho(double* %50, double* %51, i32 %52, i32* %42, double %24, double %27, double %21)
%54 = load i32, i32* %3
%55 = call i32 @dump_pairing(i32* %42, i32 %54)
ret i32 0
}