#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 */
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int *realloc(int *, int);
void find_freq_points(double f_min, double f_max, double *frequencies,
                      int nb_frequency_points, int *idx, int *length_idx) {
  int a, length;
  int *tmp_idx;
  tmp_idx = (int *)malloc(sizeof(int));
  length = 0;
  for (a = 0; a < nb_frequency_points; a++) {
    if (frequencies[a] >= f_min && frequencies[a] <= f_max) {
      length++;
      if ((tmp_idx = realloc((int *)idx, length * sizeof(int))) == NULL) {
        printf("Re-allocation error of idx in function find_freq_points\n");
      }
      tmp_idx[length] = a;
      idx = tmp_idx;
    }
  }
  length_idx = &length;
  free(tmp_idx);
}


x86 assembly (clang, -O0):
<find_freq_points>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121c <find_freq_points+0xdc>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1209 <find_freq_points+0xc9>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1209 <find_freq_points+0xc9>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11f3 <find_freq_points+0xb3>
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edx
mov    -0x40(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    120e <find_freq_points+0xce>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117d <find_freq_points+0x3d>
lea    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_freq_points>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    $0x4,%edi
call   1050 <malloc@plt>
test   %ebp,%ebp
jle    11e4 <find_freq_points+0xa4>
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xe84(%rip),%r15
xor    %r13d,%r13d
jmp    11a2 <find_freq_points+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %r13d,%rax
mov    %ebp,(%rbx,%rax,4)
mov    %rbx,%rax
add    $0x1,%rbp
cmp    %rbp,%r12
je     11e4 <find_freq_points+0xa4>
movsd  (%r14,%rbp,8),%xmm0
ucomisd 0x10(%rsp),%xmm0
jb     1199 <find_freq_points+0x59>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     1199 <find_freq_points+0x59>
mov    %r13d,%eax
add    $0x1,%r13d
lea    0x4(,%rax,4),%esi
mov    %rbx,%rdi
call   1060 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <find_freq_points+0x50>
mov    %r15,%rdi
call   1040 <puts@plt>
jmp    1190 <find_freq_points+0x50>
mov    %rax,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"Re-allocation error of idx in function find_freq_points\0A\00"
define void @find_freq_points(double %0, double %1, double* %2, i32 %3, i32* %4, i32* %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
store double %0, double* %7
store double %1, double* %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%16 = call i64 @malloc(i32 4)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %15
store i32 0, i32* %14
store i32 0, i32* %13
br label %18
18: ; preds = %58, %6
%19 = load i32, i32* %13
%20 = load i32, i32* %10
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %61
22: ; preds = %18
%23 = load double*, double** %9
%24 = load i32, i32* %13
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %7
%29 = fcmp oge double %27, %28
br i1 %29, label %30, label %57
30: ; preds = %22
%31 = load double*, double** %9
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double, double* %8
%37 = fcmp ole double %35, %36
br i1 %37, label %38, label %57
38: ; preds = %30
%39 = load i32, i32* %14
%40 = add nsw i32 %39, 1
store i32 %40, i32* %14
%41 = load i32*, i32** %11
%42 = load i32, i32* %14
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 4
%45 = trunc i64 %44 to i32
%46 = call i32* @realloc(i32* %41, i32 %45)
store i32* %46, i32** %15
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %38
%49 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %48, %38
%51 = load i32, i32* %13
%52 = load i32*, i32** %15
%53 = load i32, i32* %14
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
store i32 %51, i32* %55
%56 = load i32*, i32** %15
store i32* %56, i32** %11
br label %57
57: ; preds = %50, %30, %22
br label %58
58: ; preds = %57
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 1
store i32 %60, i32* %13
br label %18
61: ; preds = %18
store i32* %14, i32** %12
%62 = load i32*, i32** %15
%63 = call i32 @free(i32* %62)
ret void
}

LLVM IR (-O2):
@str = [56 x i8] c"Re-allocation error of idx in function find_freq_points\00"
define void @find_freq_points(double %0, double %1, double* nocapture %2, i32 %3, i32* %4, i32* nocapture readnone %5) {
%7 = tail call i64 @malloc(i32 4)
%8 = inttoptr i64 %7 to i32*
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %10, %33
%13 = phi i64 [ 0, %10 ], [ %37, %33 ]
%14 = phi i32* [ %8, %10 ], [ %36, %33 ]
%15 = phi i32* [ %4, %10 ], [ %35, %33 ]
%16 = phi i32 [ 0, %10 ], [ %34, %33 ]
%17 = getelementptr inbounds double, double* %2, i64 %13
%18 = load double, double* %17
%19 = fcmp ult double %18, %0
%20 = fcmp ugt double %18, %1
%21 = or i1 %19, %20
br i1 %21, label %33, label %22
22: ; preds = %12
%23 = add nsw i32 %16, 1
%24 = sext i32 %23 to i64
%25 = shl i32 %23, 2
%26 = tail call i32* @realloc(i32* %15, i32 %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
%31 = getelementptr inbounds i32, i32* %26, i64 %24
%32 = trunc i64 %13 to i32
store i32 %32, i32* %31
br label %33
33: ; preds = %12, %30
%34 = phi i32 [ %23, %30 ], [ %16, %12 ]
%35 = phi i32* [ %26, %30 ], [ %15, %12 ]
%36 = phi i32* [ %26, %30 ], [ %14, %12 ]
%37 = add nuw nsw i64 %13, 1
%38 = icmp eq i64 %37, %11
br i1 %38, label %39, label %12
39: ; preds = %33, %6
%40 = phi i32* [ %8, %6 ], [ %36, %33 ]
%41 = tail call i32 @free(i32* %40)
ret void
}