#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*/ gpio_pulse(char *);
int /*<<< orphan*/ send_bits(unsigned char);
int dds_frequency(double freq, unsigned char phase) {
  int bytes = 4;
  int tuning_word = freq * (4294967296.0 / 125000000.0);
  while (bytes) {
    send_bits(tuning_word & 0xff);
    tuning_word = tuning_word >> 8;
    bytes--;
  }
  send_bits(phase);
  gpio_pulse("25");
  return 0;
}


x86 assembly (clang, -O0):
<dds_frequency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
movsd  %xmm0,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x4,-0x10(%rbp)
movsd  0xebe(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     117f <dds_frequency+0x5f>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
movzbl %al,%edi
call   1040 <send_bits@plt>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <dds_frequency+0x2e>
movzbl -0x9(%rbp),%edi
call   1040 <send_bits@plt>
lea    0xe79(%rip),%rdi
call   1030 <gpio_pulse@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dds_frequency>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mulsd  0xed3(%rip),%xmm0
cvttsd2si %xmm0,%ebx
movzbl %bl,%edi
call   1040 <send_bits@plt>
movzbl %bh,%edi
call   1040 <send_bits@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
call   1040 <send_bits@plt>
shr    $0x18,%ebx
mov    %ebx,%edi
call   1040 <send_bits@plt>
mov    %ebp,%edi
call   1040 <send_bits@plt>
lea    0xea2(%rip),%rdi
call   1030 <gpio_pulse@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"25\00"
define i32 @dds_frequency(double %0, i8 zeroext %1) {
%3 = alloca double
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store double %0, double* %3
store i8 %1, i8* %4
store i32 4, i32* %5
%7 = load double, double* %3
%8 = fmul double %7, 0x40412E0BE826D695
%9 = fptosi double %8 to i32
store i32 %9, i32* %6
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %6
%15 = and i32 %14, 255
%16 = trunc i32 %15 to i8
%17 = call i32 @send_bits(i8 zeroext %16)
%18 = load i32, i32* %6
%19 = ashr i32 %18, 8
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
br label %10
22: ; preds = %10
%23 = load i8, i8* %4
%24 = call i32 @send_bits(i8 zeroext %23)
%25 = call i32 @gpio_pulse(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"25\00"
define i32 @dds_frequency(double %0, i8 zeroext %1) {
%3 = fmul double %0, 0x40412E0BE826D695
%4 = fptosi double %3 to i32
%5 = trunc i32 %4 to i8
%6 = tail call i32 @send_bits(i8 zeroext %5)
%7 = lshr i32 %4, 8
%8 = trunc i32 %7 to i8
%9 = tail call i32 @send_bits(i8 zeroext %8)
%10 = lshr i32 %4, 16
%11 = trunc i32 %10 to i8
%12 = tail call i32 @send_bits(i8 zeroext %11)
%13 = lshr i32 %4, 24
%14 = trunc i32 %13 to i8
%15 = tail call i32 @send_bits(i8 zeroext %14)
%16 = tail call i32 @send_bits(i8 zeroext %1)
%17 = tail call i32 @gpio_pulse(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
ret i32 0
}