#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*/ set_spi_prescaler(unsigned int, int);
scalar_t__ spi_busy(unsigned int);
int /*<<< orphan*/ spi_write(unsigned int, int);
void init_radiomodem(unsigned int fd, double freq_i, double freq_o,
                     double fosc) {
  double deuxPuisVingt = 1048576.0;
  int reg_o = (freq_o * deuxPuisVingt) / fosc;
  int reg_i = (freq_i * deuxPuisVingt) / fosc;
  set_spi_prescaler(fd, 15);
  spi_write(fd, 0x8000 + 0x0F);
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8D00 + ((0x07 << 5) | (0x05 << 2) | (0x01)));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8E00 + ((0x04 << 1) | (0x00)));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8100 + ((0xFF) & (reg_i >> 16)));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8200 + ((0xFF) & (reg_i >> 8)));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8300 + (0xFF & reg_i));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8400 + (0xFF & (reg_o >> 16)));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8500 + (0xFF & (reg_o >> 8)));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x8600 + (0xFF & reg_o));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x9000 + 0x02);
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x9200 + (1 << 4));
  while (spi_busy(fd))
    ;
  spi_write(fd, 0x9300 + 0x80);
  while (spi_busy(fd))
    ;
}


x86 assembly (clang, -O0):
<init_radiomodem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  0xeae(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xf,%esi
call   1050 <set_spi_prescaler@plt>
mov    -0x4(%rbp),%edi
mov    $0x800f,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     11b4 <init_radiomodem+0x84>
jmp    119d <init_radiomodem+0x6d>
mov    -0x4(%rbp),%edi
mov    $0x8df5,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     11d8 <init_radiomodem+0xa8>
jmp    11c1 <init_radiomodem+0x91>
mov    -0x4(%rbp),%edi
mov    $0x8e08,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     11fc <init_radiomodem+0xcc>
jmp    11e5 <init_radiomodem+0xb5>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%esi
sar    $0x10,%esi
and    $0xff,%esi
add    $0x8100,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     122d <init_radiomodem+0xfd>
jmp    1216 <init_radiomodem+0xe6>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
add    $0x8200,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     125e <init_radiomodem+0x12e>
jmp    1247 <init_radiomodem+0x117>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%esi
and    $0xff,%esi
add    $0x8300,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     128c <init_radiomodem+0x15c>
jmp    1275 <init_radiomodem+0x145>
mov    -0x4(%rbp),%edi
mov    -0x2c(%rbp),%esi
sar    $0x10,%esi
and    $0xff,%esi
add    $0x8400,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     12bd <init_radiomodem+0x18d>
jmp    12a6 <init_radiomodem+0x176>
mov    -0x4(%rbp),%edi
mov    -0x2c(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
add    $0x8500,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     12ee <init_radiomodem+0x1be>
jmp    12d7 <init_radiomodem+0x1a7>
mov    -0x4(%rbp),%edi
mov    -0x2c(%rbp),%esi
and    $0xff,%esi
add    $0x8600,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     131c <init_radiomodem+0x1ec>
jmp    1305 <init_radiomodem+0x1d5>
mov    -0x4(%rbp),%edi
mov    $0x9002,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     1340 <init_radiomodem+0x210>
jmp    1329 <init_radiomodem+0x1f9>
mov    -0x4(%rbp),%edi
mov    $0x9210,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     1364 <init_radiomodem+0x234>
jmp    134d <init_radiomodem+0x21d>
mov    -0x4(%rbp),%edi
mov    $0x9380,%esi
call   1030 <spi_write@plt>
mov    -0x4(%rbp),%edi
call   1040 <spi_busy@plt>
cmp    $0x0,%rax
je     1388 <init_radiomodem+0x258>
jmp    1371 <init_radiomodem+0x241>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_radiomodem>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movsd  0xebe(%rip),%xmm3
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
movsd  %xmm1,(%rsp)
mulsd  %xmm3,%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xf,%esi
call   1050 <set_spi_prescaler@plt>
mov    %ebx,%edi
mov    $0x800f,%esi
call   1030 <spi_write@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    1180 <init_radiomodem+0x50>
cvttsd2si (%rsp),%ebp
mov    %ebx,%edi
mov    $0x8df5,%esi
call   1030 <spi_write@plt>
nopl   (%rax)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    11a0 <init_radiomodem+0x70>
mov    %ebx,%edi
mov    $0x8e08,%esi
call   1030 <spi_write@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    11c0 <init_radiomodem+0x90>
cvttsd2si 0x8(%rsp),%eax
mov    %eax,%r14d
shr    $0x10,%eax
movzbl %al,%esi
or     $0x8100,%esi
mov    %ebx,%edi
call   1030 <spi_write@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    11f0 <init_radiomodem+0xc0>
mov    %r14d,%eax
movzbl %ah,%esi
or     $0x8200,%esi
mov    %ebx,%edi
call   1030 <spi_write@plt>
nop
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    1210 <init_radiomodem+0xe0>
movzbl %r14b,%esi
or     $0x8300,%esi
mov    %ebx,%edi
call   1030 <spi_write@plt>
nopl   (%rax)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    1230 <init_radiomodem+0x100>
mov    %ebp,%eax
shr    $0x10,%eax
movzbl %al,%esi
or     $0x8400,%esi
mov    %ebx,%edi
call   1030 <spi_write@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    1260 <init_radiomodem+0x130>
mov    %ebp,%eax
movzbl %ah,%esi
or     $0x8500,%esi
mov    %ebx,%edi
call   1030 <spi_write@plt>
xchg   %ax,%ax
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    1280 <init_radiomodem+0x150>
movzbl %bpl,%esi
or     $0x8600,%esi
mov    %ebx,%edi
call   1030 <spi_write@plt>
nopl   (%rax)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    12a0 <init_radiomodem+0x170>
mov    %ebx,%edi
mov    $0x9002,%esi
call   1030 <spi_write@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    12c0 <init_radiomodem+0x190>
mov    %ebx,%edi
mov    $0x9210,%esi
call   1030 <spi_write@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    12e0 <init_radiomodem+0x1b0>
mov    %ebx,%edi
mov    $0x9380,%esi
call   1030 <spi_write@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <spi_busy@plt>
test   %rax,%rax
jne    1300 <init_radiomodem+0x1d0>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @init_radiomodem(i32 %0, double %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store double 0x4130000000000000, double* %9
%12 = load double, double* %7
%13 = load double, double* %9
%14 = fmul double %12, %13
%15 = load double, double* %8
%16 = fdiv double %14, %15
%17 = fptosi double %16 to i32
store i32 %17, i32* %10
%18 = load double, double* %6
%19 = load double, double* %9
%20 = fmul double %18, %19
%21 = load double, double* %8
%22 = fdiv double %20, %21
%23 = fptosi double %22 to i32
store i32 %23, i32* %11
%24 = load i32, i32* %5
%25 = call i32 @set_spi_prescaler(i32 %24, i32 15)
%26 = load i32, i32* %5
%27 = call i32 @spi_write(i32 %26, i32 32783)
br label %28
28: ; preds = %32, %4
%29 = load i32, i32* %5
%30 = call i64 @spi_busy(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
br label %28
33: ; preds = %28
%34 = load i32, i32* %5
%35 = call i32 @spi_write(i32 %34, i32 36341)
br label %36
36: ; preds = %40, %33
%37 = load i32, i32* %5
%38 = call i64 @spi_busy(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
br label %36
41: ; preds = %36
%42 = load i32, i32* %5
%43 = call i32 @spi_write(i32 %42, i32 36360)
br label %44
44: ; preds = %48, %41
%45 = load i32, i32* %5
%46 = call i64 @spi_busy(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
br label %44
49: ; preds = %44
%50 = load i32, i32* %5
%51 = load i32, i32* %11
%52 = ashr i32 %51, 16
%53 = and i32 255, %52
%54 = add nsw i32 33024, %53
%55 = call i32 @spi_write(i32 %50, i32 %54)
br label %56
56: ; preds = %60, %49
%57 = load i32, i32* %5
%58 = call i64 @spi_busy(i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %56
br label %56
61: ; preds = %56
%62 = load i32, i32* %5
%63 = load i32, i32* %11
%64 = ashr i32 %63, 8
%65 = and i32 255, %64
%66 = add nsw i32 33280, %65
%67 = call i32 @spi_write(i32 %62, i32 %66)
br label %68
68: ; preds = %72, %61
%69 = load i32, i32* %5
%70 = call i64 @spi_busy(i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %68
br label %68
73: ; preds = %68
%74 = load i32, i32* %5
%75 = load i32, i32* %11
%76 = and i32 255, %75
%77 = add nsw i32 33536, %76
%78 = call i32 @spi_write(i32 %74, i32 %77)
br label %79
79: ; preds = %83, %73
%80 = load i32, i32* %5
%81 = call i64 @spi_busy(i32 %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %79
br label %79
84: ; preds = %79
%85 = load i32, i32* %5
%86 = load i32, i32* %10
%87 = ashr i32 %86, 16
%88 = and i32 255, %87
%89 = add nsw i32 33792, %88
%90 = call i32 @spi_write(i32 %85, i32 %89)
br label %91
91: ; preds = %95, %84
%92 = load i32, i32* %5
%93 = call i64 @spi_busy(i32 %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %96
95: ; preds = %91
br label %91
96: ; preds = %91
%97 = load i32, i32* %5
%98 = load i32, i32* %10
%99 = ashr i32 %98, 8
%100 = and i32 255, %99
%101 = add nsw i32 34048, %100
%102 = call i32 @spi_write(i32 %97, i32 %101)
br label %103
103: ; preds = %107, %96
%104 = load i32, i32* %5
%105 = call i64 @spi_busy(i32 %104)
%106 = icmp ne i64 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %103
br label %103
108: ; preds = %103
%109 = load i32, i32* %5
%110 = load i32, i32* %10
%111 = and i32 255, %110
%112 = add nsw i32 34304, %111
%113 = call i32 @spi_write(i32 %109, i32 %112)
br label %114
114: ; preds = %118, %108
%115 = load i32, i32* %5
%116 = call i64 @spi_busy(i32 %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %114
br label %114
119: ; preds = %114
%120 = load i32, i32* %5
%121 = call i32 @spi_write(i32 %120, i32 36866)
br label %122
122: ; preds = %126, %119
%123 = load i32, i32* %5
%124 = call i64 @spi_busy(i32 %123)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %122
br label %122
127: ; preds = %122
%128 = load i32, i32* %5
%129 = call i32 @spi_write(i32 %128, i32 37392)
br label %130
130: ; preds = %134, %127
%131 = load i32, i32* %5
%132 = call i64 @spi_busy(i32 %131)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %135
134: ; preds = %130
br label %130
135: ; preds = %130
%136 = load i32, i32* %5
%137 = call i32 @spi_write(i32 %136, i32 37760)
br label %138
138: ; preds = %142, %135
%139 = load i32, i32* %5
%140 = call i64 @spi_busy(i32 %139)
%141 = icmp ne i64 %140, 0
br i1 %141, label %142, label %143
142: ; preds = %138
br label %138
143: ; preds = %138
ret void
}

LLVM IR (-O2):
define void @init_radiomodem(i32 %0, double %1, double %2, double %3) {
%5 = fmul double %2, 0x4130000000000000
%6 = fdiv double %5, %3
%7 = fmul double %1, 0x4130000000000000
%8 = fdiv double %7, %3
%9 = tail call i32 @set_spi_prescaler(i32 %0, i32 15)
%10 = tail call i32 @spi_write(i32 %0, i32 32783)
br label %11
11: ; preds = %11, %4
%12 = tail call i64 @spi_busy(i32 %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %11
14: ; preds = %11
%15 = fptosi double %6 to i32
%16 = tail call i32 @spi_write(i32 %0, i32 36341)
br label %17
17: ; preds = %17, %14
%18 = tail call i64 @spi_busy(i32 %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %17
20: ; preds = %17
%21 = tail call i32 @spi_write(i32 %0, i32 36360)
br label %22
22: ; preds = %22, %20
%23 = tail call i64 @spi_busy(i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %22
25: ; preds = %22
%26 = fptosi double %8 to i32
%27 = lshr i32 %26, 16
%28 = and i32 %27, 255
%29 = or i32 %28, 33024
%30 = tail call i32 @spi_write(i32 %0, i32 %29)
br label %31
31: ; preds = %31, %25
%32 = tail call i64 @spi_busy(i32 %0)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %31
34: ; preds = %31
%35 = lshr i32 %26, 8
%36 = and i32 %35, 255
%37 = or i32 %36, 33280
%38 = tail call i32 @spi_write(i32 %0, i32 %37)
br label %39
39: ; preds = %39, %34
%40 = tail call i64 @spi_busy(i32 %0)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %39
42: ; preds = %39
%43 = and i32 %26, 255
%44 = or i32 %43, 33536
%45 = tail call i32 @spi_write(i32 %0, i32 %44)
br label %46
46: ; preds = %46, %42
%47 = tail call i64 @spi_busy(i32 %0)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %46
49: ; preds = %46
%50 = lshr i32 %15, 16
%51 = and i32 %50, 255
%52 = or i32 %51, 33792
%53 = tail call i32 @spi_write(i32 %0, i32 %52)
br label %54
54: ; preds = %54, %49
%55 = tail call i64 @spi_busy(i32 %0)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %54
57: ; preds = %54
%58 = lshr i32 %15, 8
%59 = and i32 %58, 255
%60 = or i32 %59, 34048
%61 = tail call i32 @spi_write(i32 %0, i32 %60)
br label %62
62: ; preds = %62, %57
%63 = tail call i64 @spi_busy(i32 %0)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %62
65: ; preds = %62
%66 = and i32 %15, 255
%67 = or i32 %66, 34304
%68 = tail call i32 @spi_write(i32 %0, i32 %67)
br label %69
69: ; preds = %69, %65
%70 = tail call i64 @spi_busy(i32 %0)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %69
72: ; preds = %69
%73 = tail call i32 @spi_write(i32 %0, i32 36866)
br label %74
74: ; preds = %74, %72
%75 = tail call i64 @spi_busy(i32 %0)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %74
77: ; preds = %74
%78 = tail call i32 @spi_write(i32 %0, i32 37392)
br label %79
79: ; preds = %79, %77
%80 = tail call i64 @spi_busy(i32 %0)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %79
82: ; preds = %79
%83 = tail call i32 @spi_write(i32 %0, i32 37760)
br label %84
84: ; preds = %84, %82
%85 = tail call i64 @spi_busy(i32 %0)
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %84
87: ; preds = %84
ret void
}