#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 */
typedef int /*<<< orphan*/ mpfr_t;

/* Variables and functions */
int /*<<< orphan*/ MPFR_RNDN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ m_clear(int /*<<< orphan*/);
int /*<<< orphan*/ m_init2(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpfr_cmp(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_prec(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpfr_set(int /*<<< orphan*/, int /*<<< orphan*/ const,
                            int /*<<< orphan*/);
size_t getMaxIndex(const size_t size, const mpfr_t array[size]) {
  size_t indexMax;
  mpfr_t max;
  assert(size > 0);
  indexMax = size - 1;
  m_init2(max, mpfr_get_prec(array[indexMax]));
  mpfr_set(max, array[0], MPFR_RNDN);
  for (size_t i = 0; i < size; ++i) {
    if (mpfr_cmp(array[i], max) > 0) {
      mpfr_set(max, array[i], MPFR_RNDN);
      indexMax = i;
    }
  }
  m_clear(max);
  return indexMax;
}


x86 assembly (clang, -O0):
<getMaxIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <mpfr_get_prec@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1080 <m_init2@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
call   1030 <mpfr_set@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1232 <getMaxIndex+0xd2>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x1c(%rbp),%esi
call   1050 <mpfr_cmp@plt>
cmp    $0x0,%rax
jle    121c <getMaxIndex+0xbc>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
call   1030 <mpfr_set@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1221 <getMaxIndex+0xc1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11cd <getMaxIndex+0x6d>
mov    -0x1c(%rbp),%edi
call   1070 <m_clear@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMaxIndex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r14
xor    %edi,%edi
mov    %r14,%r15
add    $0xffffffffffffffff,%r15
setb   %dil
call   1040 <assert@plt>
mov    0x0(%r13,%r15,4),%edi
call   1060 <mpfr_get_prec@plt>
mov    %eax,%esi
call   1080 <m_init2@plt>
mov    0x0(%r13),%esi
mov    0x2e4b(%rip),%r12
mov    (%r12),%edx
call   1030 <mpfr_set@plt>
test   %r14,%r14
je     11db <getMaxIndex+0x7b>
xor    %ebx,%ebx
jmp    11b9 <getMaxIndex+0x59>
nop
add    $0x1,%rbx
cmp    %rbx,%r14
je     11e2 <getMaxIndex+0x82>
mov    0x0(%r13,%rbx,4),%edi
call   1050 <mpfr_cmp@plt>
test   %rax,%rax
jle    11b0 <getMaxIndex+0x50>
mov    0x0(%r13,%rbx,4),%esi
mov    (%r12),%edx
call   1030 <mpfr_set@plt>
mov    %rbx,%r15
jmp    11b0 <getMaxIndex+0x50>
mov    $0xffffffffffffffff,%r15
call   1070 <m_clear@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@MPFR_RNDN = global i32 0
define i64 @getMaxIndex(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
store i64 %0, i64* %3
store i32* %1, i32** %4
%8 = load i64, i64* %3
%9 = load i64, i64* %3
%10 = icmp ugt i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i64, i64* %3
%14 = sub i64 %13, 1
store i64 %14, i64* %5
%15 = load i32, i32* %6
%16 = load i32*, i32** %4
%17 = load i64, i64* %5
%18 = getelementptr inbounds i32, i32* %16, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @mpfr_get_prec(i32 %19)
%21 = call i32 @m_init2(i32 %15, i32 %20)
%22 = load i32, i32* %6
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = load i32, i32* @MPFR_RNDN
%27 = call i32 @mpfr_set(i32 %22, i32 %25, i32 %26)
store i64 0, i64* %7
br label %28
28: ; preds = %50, %2
%29 = load i64, i64* %7
%30 = load i64, i64* %3
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %53
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i64, i64* %7
%35 = getelementptr inbounds i32, i32* %33, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %6
%38 = call i64 @mpfr_cmp(i32 %36, i32 %37)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %32
%41 = load i32, i32* %6
%42 = load i32*, i32** %4
%43 = load i64, i64* %7
%44 = getelementptr inbounds i32, i32* %42, i64 %43
%45 = load i32, i32* %44
%46 = load i32, i32* @MPFR_RNDN
%47 = call i32 @mpfr_set(i32 %41, i32 %45, i32 %46)
%48 = load i64, i64* %7
store i64 %48, i64* %5
br label %49
49: ; preds = %40, %32
br label %50
50: ; preds = %49
%51 = load i64, i64* %7
%52 = add i64 %51, 1
store i64 %52, i64* %7
br label %28
53: ; preds = %28
%54 = load i32, i32* %6
%55 = call i32 @m_clear(i32 %54)
%56 = load i64, i64* %5
ret i64 %56
}

LLVM IR (-O2):
@MPFR_RNDN = global i32 0
define i64 @getMaxIndex(i64 %0, i32* nocapture %1) {
%3 = icmp ne i64 %0, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = add i64 %0, -1
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @mpfr_get_prec(i32 %8)
%10 = tail call i32 @m_init2(i32 undef, i32 %9)
%11 = load i32, i32* %1
%12 = load i32, i32* @MPFR_RNDN
%13 = tail call i32 @mpfr_set(i32 undef, i32 %11, i32 %12)
%14 = icmp eq i64 %0, 0
br i1 %14, label %15, label %18
15: ; preds = %29, %2
%16 = phi i64 [ -1, %2 ], [ %30, %29 ]
%17 = tail call i32 @m_clear(i32 undef)
ret i64 %16
18: ; preds = %2, %29
%19 = phi i64 [ %31, %29 ], [ 0, %2 ]
%20 = phi i64 [ %30, %29 ], [ %6, %2 ]
%21 = getelementptr inbounds i32, i32* %1, i64 %19
%22 = load i32, i32* %21
%23 = tail call i64 @mpfr_cmp(i32 %22, i32 undef)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* %21
%27 = load i32, i32* @MPFR_RNDN
%28 = tail call i32 @mpfr_set(i32 undef, i32 %26, i32 %27)
br label %29
29: ; preds = %18, %25
%30 = phi i64 [ %19, %25 ], [ %20, %18 ]
%31 = add nuw i64 %19, 1
%32 = icmp eq i64 %31, %0
br i1 %32, label %15, label %18
}