#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);
size_t getMinIndex(size_t const, int /*<<< orphan*/ const *);
int /*<<< orphan*/ m_clear(int /*<<< orphan*/);
int /*<<< orphan*/ m_init2(int /*<<< orphan*/, int /*<<< orphan*/);
size_t *malloc(int);
scalar_t__ mpfr_cmp(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpfr_get_prec(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpfr_set(int /*<<< orphan*/, int /*<<< orphan*/ const,
                            int /*<<< orphan*/);
int getAllMinIndexes(size_t **indexArray, const size_t size,
                     const mpfr_t array[size]) {
  size_t indexMin;
  indexMin = getMinIndex(size, array);
  mpfr_t minValue;
  m_init2(minValue, mpfr_get_prec(array[size - 1]));
  mpfr_set(minValue, array[indexMin], MPFR_RNDN);
  long int nbMin = 0;
  for (size_t i = 0; i < size; ++i) {
    if (mpfr_cmp(minValue, array[i]) == 0) {
      ++nbMin;
    }
  }
  assert(nbMin != 0);
  *indexArray = malloc(sizeof(size_t) * nbMin);
  size_t indexMinArray = 0;
  for (size_t i = 0; i < size; ++i) {
    if (mpfr_cmp(minValue, array[i]) == 0) {
      (*indexArray)[indexMinArray] = i;
      ++indexMinArray;
    }
  }
  m_clear(minValue);
  return nbMin;
}


x86 assembly (clang, -O0):
<getAllMinIndexes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <getMinIndex@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,4),%edi
call   1080 <mpfr_get_prec@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   10a0 <m_init2@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
call   1030 <mpfr_set@plt>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1242 <getAllMinIndexes+0xc2>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1070 <mpfr_cmp@plt>
cmp    $0x0,%rax
jne    122c <getAllMinIndexes+0xac>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1231 <getAllMinIndexes+0xb1>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11f5 <getAllMinIndexes+0x75>
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12dd <getAllMinIndexes+0x15d>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1070 <mpfr_cmp@plt>
cmp    $0x0,%rax
jne    12c7 <getAllMinIndexes+0x147>
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12cc <getAllMinIndexes+0x14c>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    127d <getAllMinIndexes+0xfd>
mov    -0x24(%rbp),%edi
call   1090 <m_clear@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAllMinIndexes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1060 <getMinIndex@plt>
mov    %rax,%rbx
lea    -0x1(%r12),%rax
mov    (%r14,%rax,4),%edi
call   1080 <mpfr_get_prec@plt>
mov    %eax,%esi
call   10a0 <m_init2@plt>
mov    (%r14,%rbx,4),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
call   1030 <mpfr_set@plt>
cmp    $0x1,%r12
jae    11d4 <getAllMinIndexes+0x54>
xor    %r13d,%r13d
jmp    11fa <getAllMinIndexes+0x7a>
xor    %ebx,%ebx
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    (%r14,%rbx,4),%esi
call   1070 <mpfr_cmp@plt>
cmp    $0x1,%rax
adc    $0x0,%r13
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11e0 <getAllMinIndexes+0x60>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1040 <assert@plt>
lea    0x0(,%r13,8),%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
test   %r12,%r12
je     1254 <getAllMinIndexes+0xd4>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1239 <getAllMinIndexes+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1254 <getAllMinIndexes+0xd4>
mov    (%r14,%rbx,4),%esi
call   1070 <mpfr_cmp@plt>
test   %rax,%rax
jne    1230 <getAllMinIndexes+0xb0>
mov    (%r15),%rax
mov    %rbx,(%rax,%rbp,8)
add    $0x1,%rbp
jmp    1230 <getAllMinIndexes+0xb0>
call   1090 <m_clear@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MPFR_RNDN = global i32 0
define i32 @getAllMinIndexes(i64** %0, i64 %1, i32* %2) {
%4 = alloca i64**
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i64** %0, i64*** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%13 = load i64, i64* %5
%14 = load i64, i64* %5
%15 = load i32*, i32** %6
%16 = call i64 @getMinIndex(i64 %14, i32* %15)
store i64 %16, i64* %7
%17 = load i32, i32* %8
%18 = load i32*, i32** %6
%19 = load i64, i64* %5
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = call i32 @mpfr_get_prec(i32 %22)
%24 = call i32 @m_init2(i32 %17, i32 %23)
%25 = load i32, i32* %8
%26 = load i32*, i32** %6
%27 = load i64, i64* %7
%28 = getelementptr inbounds i32, i32* %26, i64 %27
%29 = load i32, i32* %28
%30 = load i32, i32* @MPFR_RNDN
%31 = call i32 @mpfr_set(i32 %25, i32 %29, i32 %30)
store i64 0, i64* %9
store i64 0, i64* %10
br label %32
32: ; preds = %48, %3
%33 = load i64, i64* %10
%34 = load i64, i64* %5
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %51
36: ; preds = %32
%37 = load i32, i32* %8
%38 = load i32*, i32** %6
%39 = load i64, i64* %10
%40 = getelementptr inbounds i32, i32* %38, i64 %39
%41 = load i32, i32* %40
%42 = call i64 @mpfr_cmp(i32 %37, i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = load i64, i64* %9
%46 = add nsw i64 %45, 1
store i64 %46, i64* %9
br label %47
47: ; preds = %44, %36
br label %48
48: ; preds = %47
%49 = load i64, i64* %10
%50 = add i64 %49, 1
store i64 %50, i64* %10
br label %32
51: ; preds = %32
%52 = load i64, i64* %9
%53 = icmp ne i64 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load i64, i64* %9
%57 = mul i64 8, %56
%58 = trunc i64 %57 to i32
%59 = call i64* @malloc(i32 %58)
%60 = load i64**, i64*** %4
store i64* %59, i64** %60
store i64 0, i64* %11
store i64 0, i64* %12
br label %61
61: ; preds = %82, %51
%62 = load i64, i64* %12
%63 = load i64, i64* %5
%64 = icmp ult i64 %62, %63
br i1 %64, label %65, label %85
65: ; preds = %61
%66 = load i32, i32* %8
%67 = load i32*, i32** %6
%68 = load i64, i64* %12
%69 = getelementptr inbounds i32, i32* %67, i64 %68
%70 = load i32, i32* %69
%71 = call i64 @mpfr_cmp(i32 %66, i32 %70)
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %81
73: ; preds = %65
%74 = load i64, i64* %12
%75 = load i64**, i64*** %4
%76 = load i64*, i64** %75
%77 = load i64, i64* %11
%78 = getelementptr inbounds i64, i64* %76, i64 %77
store i64 %74, i64* %78
%79 = load i64, i64* %11
%80 = add i64 %79, 1
store i64 %80, i64* %11
br label %81
81: ; preds = %73, %65
br label %82
82: ; preds = %81
%83 = load i64, i64* %12
%84 = add i64 %83, 1
store i64 %84, i64* %12
br label %61
85: ; preds = %61
%86 = load i32, i32* %8
%87 = call i32 @m_clear(i32 %86)
%88 = load i64, i64* %9
%89 = trunc i64 %88 to i32
ret i32 %89
}

LLVM IR (-O2):
@MPFR_RNDN = global i32 0
define i32 @getAllMinIndexes(i64** nocapture %0, i64 %1, i32* %2) {
%4 = tail call i64 @getMinIndex(i64 %1, i32* %2)
%5 = add i64 %1, -1
%6 = getelementptr inbounds i32, i32* %2, i64 %5
%7 = load i32, i32* %6
%8 = tail call i32 @mpfr_get_prec(i32 %7)
%9 = tail call i32 @m_init2(i32 undef, i32 %8)
%10 = getelementptr inbounds i32, i32* %2, i64 %4
%11 = load i32, i32* %10
%12 = load i32, i32* @MPFR_RNDN
%13 = tail call i32 @mpfr_set(i32 undef, i32 %11, i32 %12)
%14 = icmp eq i64 %1, 0
br i1 %14, label %15, label %23
15: ; preds = %23, %3
%16 = phi i64 [ 0, %3 ], [ %31, %23 ]
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = trunc i64 %16 to i32
%21 = shl i32 %20, 3
%22 = tail call i64* @malloc(i32 %21)
store i64* %22, i64** %0
br i1 %14, label %34, label %36
23: ; preds = %3, %23
%24 = phi i64 [ %32, %23 ], [ 0, %3 ]
%25 = phi i64 [ %31, %23 ], [ 0, %3 ]
%26 = getelementptr inbounds i32, i32* %2, i64 %24
%27 = load i32, i32* %26
%28 = tail call i64 @mpfr_cmp(i32 undef, i32 %27)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i64
%31 = add nuw nsw i64 %25, %30
%32 = add nuw i64 %24, 1
%33 = icmp eq i64 %32, %1
br i1 %33, label %15, label %23
34: ; preds = %47, %15
%35 = tail call i32 @m_clear(i32 undef)
ret i32 %20
36: ; preds = %15, %47
%37 = phi i64 [ %49, %47 ], [ 0, %15 ]
%38 = phi i64 [ %48, %47 ], [ 0, %15 ]
%39 = getelementptr inbounds i32, i32* %2, i64 %37
%40 = load i32, i32* %39
%41 = tail call i64 @mpfr_cmp(i32 undef, i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i64*, i64** %0
%45 = getelementptr inbounds i64, i64* %44, i64 %38
store i64 %37, i64* %45
%46 = add i64 %38, 1
br label %47
47: ; preds = %36, %43
%48 = phi i64 [ %46, %43 ], [ %38, %36 ]
%49 = add nuw i64 %37, 1
%50 = icmp eq i64 %49, %1
br i1 %50, label %34, label %36
}