#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*/ dds_frequency(double, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int spread(double freq) {
  int range = 500000;
  int v_range = 0;
  fprintf(stderr, "freqspread:%lf\n", freq);
  while (1) {
    dds_frequency(freq + (double)v_range, 0);
    usleep(1000);
    if (v_range > range)
      v_range = 0;
    v_range += 80000;
  }
  return 0;
}


x86 assembly (clang, -O0):
<spread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x7a120,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
lea    0xea0(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
xor    %edi,%edi
call   1040 <dds_frequency@plt>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1197 <spread+0x67>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x13880,%eax
mov    %eax,-0x10(%rbp)
jmp    1165 <spread+0x35>

x86 assembly (clang, -O2):
<spread>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
movsd  %xmm0,(%rsp)
call   1030 <fprintf@plt>
xor    %ebx,%ebx
mov    $0x13880,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
addsd  (%rsp),%xmm0
xor    %edi,%edi
call   1040 <dds_frequency@plt>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
cmp    $0x7a121,%ebx
lea    0x13880(%rbx),%eax
cmovge %ebp,%eax
mov    %eax,%ebx
jmp    1160 <spread+0x30>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"freqspread:%lf\0A\00"
define i32 @spread(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
store double %0, double* %2
store i32 500000, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* @stderr
%6 = load double, double* %2
%7 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %6)
br label %8
8: ; preds = %1, %19
%9 = load double, double* %2
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = fadd double %9, %11
%13 = call i32 @dds_frequency(double %12, i32 0)
%14 = call i32 @usleep(i32 1000)
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %8
store i32 0, i32* %4
br label %19
19: ; preds = %18, %8
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 80000
store i32 %21, i32* %4
br label %8
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"freqspread:%lf\0A\00"
define i32 @spread(double %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %0)
br label %4
4: ; preds = %4, %1
%5 = phi i32 [ 0, %1 ], [ %12, %4 ]
%6 = sitofp i32 %5 to double
%7 = fadd double %6, %0
%8 = tail call i32 @dds_frequency(double %7, i32 0)
%9 = tail call i32 @usleep(i32 1000)
%10 = icmp sgt i32 %5, 500000
%11 = add nsw i32 %5, 80000
%12 = select i1 %10, i32 80000, i32 %11
br label %4
}