#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);
int /*<<< orphan*/ stderr;
int burst_depth_for_max_dm(float max_dm, float delta_t, size_t nfreq,
                           float freq0, float delta_f) {
  int depth = 2;
  int imax = 20;
  int i = 0;
  while ((get_diagonal_dm_simple(freq0, freq0 + nfreq * delta_f, delta_t,
                                 depth) < 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    $0x40,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
mov    %rdi,-0x18(%rbp)
movss  %xmm2,-0x1c(%rbp)
movss  %xmm3,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
movl   $0x14,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  %xmm0,-0x38(%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,-0x34(%rbp)
test   %rax,%rax
movss  %xmm0,-0x30(%rbp)
js     11a1 <burst_depth_for_max_dm+0x81>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x38(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
movss  -0x20(%rbp),%xmm3
mulss  %xmm3,%xmm1
addss  %xmm2,%xmm1
movss  -0xc(%rbp),%xmm2
mov    -0x24(%rbp),%edi
call   1030 <get_diagonal_dm_simple@plt>
movaps %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
xor    %eax,%eax
ucomiss %xmm1,%xmm0
mov    %al,-0x3d(%rbp)
jbe    11ec <burst_depth_for_max_dm+0xcc>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
setl   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    11fc <burst_depth_for_max_dm+0xdc>
jmp    1213 <burst_depth_for_max_dm+0xf3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1155 <burst_depth_for_max_dm+0x35>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    1248 <burst_depth_for_max_dm+0x128>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
movss  -0x8(%rbp),%xmm0
mov    -0x2c(%rbp),%edx
lea    0xdc9(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124e <burst_depth_for_max_dm+0x12e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<burst_depth_for_max_dm>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm2,0x10(%rsp)
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
test   %rdi,%rdi
js     1147 <burst_depth_for_max_dm+0x27>
xorps  %xmm1,%xmm1
cvtsi2ss %rdi,%xmm1
jmp    115f <burst_depth_for_max_dm+0x3f>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
xorps  %xmm1,%xmm1
cvtsi2ss %rdi,%xmm1
addss  %xmm1,%xmm1
mulss  %xmm3,%xmm1
movss  0x10(%rsp),%xmm0
addss  %xmm0,%xmm1
mov    $0x2,%ebp
movss  %xmm1,0x14(%rsp)
movss  0xc(%rsp),%xmm2
mov    $0x2,%edi
call   1030 <get_diagonal_dm_simple@plt>
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    11fb <burst_depth_for_max_dm+0xdb>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbx),%ebp
lea    0x3(%rbx),%edi
movss  0x10(%rsp),%xmm0
movss  0x14(%rsp),%xmm1
movss  0xc(%rsp),%xmm2
call   1030 <get_diagonal_dm_simple@plt>
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    11cf <burst_depth_for_max_dm+0xaf>
cmp    $0x13,%ebx
mov    %ebp,%ebx
jb     11a0 <burst_depth_for_max_dm+0x80>
cmp    $0x14,%ebp
jne    11f8 <burst_depth_for_max_dm+0xd8>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
movss  0x8(%rsp),%xmm0
mov    $0x14,%edx
call   1040 <fprintf@plt>
xor    %ebp,%ebp
jmp    11fb <burst_depth_for_max_dm+0xdb>
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) {
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca i64
%10 = alloca float
%11 = alloca float
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store float %0, float* %7
store float %1, float* %8
store i64 %2, i64* %9
store float %3, float* %10
store float %4, float* %11
store i32 2, i32* %12
store i32 20, i32* %13
store i32 0, i32* %14
br label %15
15: ; preds = %33, %5
%16 = load float, float* %10
%17 = load float, float* %10
%18 = load i64, i64* %9
%19 = uitofp i64 %18 to float
%20 = load float, float* %11
%21 = call float @llvm.fmuladd.f32(float %19, float %20, float %17)
%22 = load float, float* %8
%23 = load i32, i32* %12
%24 = call float @get_diagonal_dm_simple(float %16, float %21, float %22, i32 %23)
%25 = load float, float* %7
%26 = fcmp olt float %24, %25
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = load i32, i32* %14
%29 = load i32, i32* %13
%30 = icmp slt i32 %28, %29
br label %31
31: ; preds = %27, %15
%32 = phi i1 [ false, %15 ], [ %30, %27 ]
br i1 %32, label %33, label %38
33: ; preds = %31
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
%36 = load i32, i32* %14
%37 = add nsw i32 %36, 1
store i32 %37, i32* %14
br label %15
38: ; preds = %31
%39 = load i32, i32* %14
%40 = load i32, i32* %13
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load float, float* %7
%45 = load i32, i32* %14
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), float %44, i32 %45)
store i32 0, i32* %6
br label %49
47: ; preds = %38
%48 = load i32, i32* %12
store i32 %48, i32* %6
br label %49
49: ; preds = %47, %42
%50 = load i32, i32* %6
ret i32 %50
}

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) {
%6 = uitofp i64 %2 to float
%7 = tail call float @llvm.fmuladd.f32(float %6, float %4, float %3)
%8 = tail call float @get_diagonal_dm_simple(float %3, float %7, float %1, i32 2)
%9 = fcmp olt float %8, %0
br i1 %9, label %10, label %24
10: ; preds = %5, %10
%11 = phi i32 [ %14, %10 ], [ 0, %5 ]
%12 = phi i32 [ %13, %10 ], [ 2, %5 ]
%13 = add nuw nsw i32 %12, 1
%14 = add nuw nsw i32 %11, 1
%15 = tail call float @get_diagonal_dm_simple(float %3, float %7, float %1, i32 %13)
%16 = fcmp olt float %15, %0
%17 = icmp ult i32 %11, 19
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %10, label %19
19: ; preds = %10
%20 = icmp eq i32 %14, 20
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), float %0, i32 20)
br label %24
24: ; preds = %5, %19, %21
%25 = phi i32 [ 0, %21 ], [ %13, %19 ], [ 2, %5 ]
ret i32 %25
}