#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*/ fprintf(int /*<<< orphan*/, char *, float, int);
float get_diagonal_dm_simple(float, float, float, int, float);
int /*<<< orphan*/ stderr;
int burst_depth_for_max_dm(float max_dm, float delta_t, size_t nfreq,
                           float freq0, float delta_f, float disp_ind) {
  int depth = 2;
  int imax = 20;
  int i = 0;
  while ((get_diagonal_dm_simple(freq0, freq0 + nfreq * delta_f, delta_t, depth,
                                 disp_ind) < max_dm) &&
         (i < imax)) {
    depth++;
    i++;
  }
  if (i == imax) {
    fprintf(stderr,
            "Failure in burst_depth_for_max_dm.  Did not reach requested DM of "
            "%12.4g at a depth of %d\n",
            max_dm, i);
    return 0;
  }
  return depth;
}


x86 assembly (clang, -O0):
<burst_depth_for_max_dm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
mov    %rdi,-0x18(%rbp)
movss  %xmm2,-0x1c(%rbp)
movss  %xmm3,-0x20(%rbp)
movss  %xmm4,-0x24(%rbp)
movl   $0x2,-0x28(%rbp)
movl   $0x14,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  %xmm0,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x38(%rbp)
test   %rax,%rax
movss  %xmm0,-0x34(%rbp)
js     11a6 <burst_depth_for_max_dm+0x86>
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x3c(%rbp),%xmm0
movss  -0x40(%rbp),%xmm2
movss  -0x34(%rbp),%xmm1
movss  -0x20(%rbp),%xmm3
mulss  %xmm3,%xmm1
addss  %xmm2,%xmm1
movss  -0xc(%rbp),%xmm2
mov    -0x28(%rbp),%edi
movss  -0x24(%rbp),%xmm3
call   1030 <get_diagonal_dm_simple@plt>
movaps %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
xor    %eax,%eax
ucomiss %xmm1,%xmm0
mov    %al,-0x41(%rbp)
jbe    11f6 <burst_depth_for_max_dm+0xd6>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
setl   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1206 <burst_depth_for_max_dm+0xe6>
jmp    121d <burst_depth_for_max_dm+0xfd>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    115a <burst_depth_for_max_dm+0x3a>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    1252 <burst_depth_for_max_dm+0x132>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
movss  -0x8(%rbp),%xmm0
mov    -0x30(%rbp),%edx
lea    0xdbf(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1258 <burst_depth_for_max_dm+0x138>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<burst_depth_for_max_dm>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm4,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0x4(%rsp)
test   %rdi,%rdi
js     114d <burst_depth_for_max_dm+0x2d>
xorps  %xmm1,%xmm1
cvtsi2ss %rdi,%xmm1
jmp    1165 <burst_depth_for_max_dm+0x45>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
xorps  %xmm1,%xmm1
cvtsi2ss %rdi,%xmm1
addss  %xmm1,%xmm1
mulss  %xmm3,%xmm1
movss  0xc(%rsp),%xmm0
addss  %xmm0,%xmm1
mov    $0x2,%ebp
movss  %xmm1,0x14(%rsp)
movss  0x8(%rsp),%xmm2
mov    $0x2,%edi
movss  0x10(%rsp),%xmm3
call   1030 <get_diagonal_dm_simple@plt>
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    1211 <burst_depth_for_max_dm+0xf1>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%ebp
lea    0x3(%rbx),%edi
movss  0xc(%rsp),%xmm0
movss  0x14(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
movss  0x10(%rsp),%xmm3
call   1030 <get_diagonal_dm_simple@plt>
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    11e5 <burst_depth_for_max_dm+0xc5>
cmp    $0x13,%ebx
mov    %ebp,%ebx
jb     11b0 <burst_depth_for_max_dm+0x90>
cmp    $0x14,%ebp
jne    120e <burst_depth_for_max_dm+0xee>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
movss  0x4(%rsp),%xmm0
mov    $0x14,%edx
call   1040 <fprintf@plt>
xor    %ebp,%ebp
jmp    1211 <burst_depth_for_max_dm+0xf1>
add    $0x2,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [91 x i8] c"Failure in burst_depth_for_max_dm. Did not reach requested DM of %12.4g at a depth of %d\0A\00"
define i32 @burst_depth_for_max_dm(float %0, float %1, i64 %2, float %3, float %4, float %5) {
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca i64
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store float %0, float* %8
store float %1, float* %9
store i64 %2, i64* %10
store float %3, float* %11
store float %4, float* %12
store float %5, float* %13
store i32 2, i32* %14
store i32 20, i32* %15
store i32 0, i32* %16
br label %17
17: ; preds = %36, %6
%18 = load float, float* %11
%19 = load float, float* %11
%20 = load i64, i64* %10
%21 = uitofp i64 %20 to float
%22 = load float, float* %12
%23 = call float @llvm.fmuladd.f32(float %21, float %22, float %19)
%24 = load float, float* %9
%25 = load i32, i32* %14
%26 = load float, float* %13
%27 = call float @get_diagonal_dm_simple(float %18, float %23, float %24, i32 %25, float %26)
%28 = load float, float* %8
%29 = fcmp olt float %27, %28
br i1 %29, label %30, label %34
30: ; preds = %17
%31 = load i32, i32* %16
%32 = load i32, i32* %15
%33 = icmp slt i32 %31, %32
br label %34
34: ; preds = %30, %17
%35 = phi i1 [ false, %17 ], [ %33, %30 ]
br i1 %35, label %36, label %41
36: ; preds = %34
%37 = load i32, i32* %14
%38 = add nsw i32 %37, 1
store i32 %38, i32* %14
%39 = load i32, i32* %16
%40 = add nsw i32 %39, 1
store i32 %40, i32* %16
br label %17
41: ; preds = %34
%42 = load i32, i32* %16
%43 = load i32, i32* %15
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = load float, float* %8
%48 = load i32, i32* %16
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), float %47, i32 %48)
store i32 0, i32* %7
br label %52
50: ; preds = %41
%51 = load i32, i32* %14
store i32 %51, i32* %7
br label %52
52: ; preds = %50, %45
%53 = load i32, i32* %7
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [91 x i8] c"Failure in burst_depth_for_max_dm. Did not reach requested DM of %12.4g at a depth of %d\0A\00"
define i32 @burst_depth_for_max_dm(float %0, float %1, i64 %2, float %3, float %4, float %5) {
%7 = uitofp i64 %2 to float
%8 = tail call float @llvm.fmuladd.f32(float %7, float %4, float %3)
%9 = tail call float @get_diagonal_dm_simple(float %3, float %8, float %1, i32 2, float %5)
%10 = fcmp olt float %9, %0
br i1 %10, label %11, label %25
11: ; preds = %6, %11
%12 = phi i32 [ %15, %11 ], [ 0, %6 ]
%13 = phi i32 [ %14, %11 ], [ 2, %6 ]
%14 = add nuw nsw i32 %13, 1
%15 = add nuw nsw i32 %12, 1
%16 = tail call float @get_diagonal_dm_simple(float %3, float %8, float %1, i32 %14, float %5)
%17 = fcmp olt float %16, %0
%18 = icmp ult i32 %12, 19
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %11, label %20
20: ; preds = %11
%21 = icmp eq i32 %15, 20
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), float %0, i32 20)
br label %25
25: ; preds = %6, %20, %22
%26 = phi i32 [ 0, %22 ], [ %14, %20 ], [ 2, %6 ]
ret i32 %26
}