#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*/ write16(char *, unsigned int, short);
int /*<<< orphan*/ write32(char *, int, int);
int _change_freq(char *BASE, int channel, int freq) {
  int FREQ, i;
  double freq_frac;
  unsigned int GC314FS_GCoffset[3] = {0x800, 0x1000, 0x1800};
  unsigned int chan_control_map[4] = {0x00, 0x80, 0x100, 0x180};
  freq_frac = (double)freq / (double)100000000;
  FREQ = 4294967296.0 * freq_frac;
  for (i = 0; i < 3; i++) {
    write16(BASE, GC314FS_GCoffset[i] + chan_control_map[channel] + 0x62,
            (short)(FREQ & 0x0000ffff));
    write16(BASE, GC314FS_GCoffset[i] + chan_control_map[channel] + 0x64,
            (short)((FREQ >> 16) & 0x0000ffff));
  }
  write32(BASE, 0x210, 0x152);
  write32(BASE, 0x310, 0x152);
  write32(BASE, 0x350, 0x152);
  write32(BASE, 0x390, 0x152);
  write32(BASE, 0x3d0, 0x152);
  write32(BASE, 0x410, 0x152);
  write32(BASE, 0x450, 0x152);
  write32(BASE, 0x490, 0x152);
  write32(BASE, 0x4d0, 0x152);
  write32(BASE, 0x510, 0x152);
  write32(BASE, 0x550, 0x152);
  write32(BASE, 0x590, 0x152);
  write32(BASE, 0x5d0, 0x152);
  write32(BASE, 0x11c, 0x00010000);
  *((unsigned int *)(BASE + 0x100)) |= 0x00000040;
  *((unsigned int *)(BASE + 0x100)) |= 0x00040000;
  return 1;
}


x86 assembly (clang, -O0):
<_change_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x2c(%rbp)
mov    0xed5(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    0xed3(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xed0(%rip),%rax
mov    %rax,-0x38(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe86(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11f6 <_change_freq+0xd6>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
mov    -0x2c(%rbp,%rax,4),%esi
movslq -0xc(%rbp),%rax
add    -0x40(%rbp,%rax,4),%esi
add    $0x62,%esi
mov    -0x14(%rbp),%eax
and    $0xffff,%eax
movswl %ax,%edx
call   1040 <write16@plt>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
mov    -0x2c(%rbp,%rax,4),%esi
movslq -0xc(%rbp),%rax
add    -0x40(%rbp,%rax,4),%esi
add    $0x64,%esi
mov    -0x14(%rbp),%eax
sar    $0x10,%eax
and    $0xffff,%eax
movswl %ax,%edx
call   1040 <write16@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <_change_freq+0x6d>
mov    -0x8(%rbp),%rdi
mov    $0x210,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x310,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x350,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x390,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x410,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x450,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x490,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x510,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x550,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x590,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x5d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rdi
mov    $0x11c,%esi
mov    $0x10000,%edx
call   1030 <write32@plt>
mov    -0x8(%rbp),%rax
mov    0x100(%rax),%ecx
or     $0x40,%ecx
mov    %ecx,0x100(%rax)
mov    -0x8(%rbp),%rax
mov    0x100(%rax),%ecx
or     $0x40000,%ecx
mov    %ecx,0x100(%rax)
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_change_freq>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cvtsi2sd %edx,%xmm0
divsd  0xeca(%rip),%xmm0
mulsd  0xeca(%rip),%xmm0
cvttsd2si %xmm0,%r14d
movslq %esi,%rax
lea    0xec3(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
lea    0x862(%rbp),%esi
movswl %r14w,%r15d
mov    %r15d,%edx
call   1040 <write16@plt>
lea    0x864(%rbp),%esi
sar    $0x10,%r14d
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <write16@plt>
lea    0x1062(%rbp),%esi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1040 <write16@plt>
lea    0x1064(%rbp),%esi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <write16@plt>
lea    0x1862(%rbp),%esi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1040 <write16@plt>
add    $0x1864,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <write16@plt>
mov    %rbx,%rdi
mov    $0x210,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x310,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x350,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x390,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x3d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x410,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x450,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x490,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x4d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x510,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x550,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x590,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x5d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %rbx,%rdi
mov    $0x11c,%esi
mov    $0x10000,%edx
call   1030 <write32@plt>
orl    $0x40040,0x100(%rbx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const._change_freq.GC314FS_GCoffset = [3 x i32] [i32 2048, i32 4096, i32 6144]
@__const._change_freq.chan_control_map = [4 x i32] [i32 0, i32 128, i32 256, i32 384]
define i32 @_change_freq(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca [3 x i32]
%11 = alloca [4 x i32]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = bitcast [3 x i32]* %10 to i8*
%13 = bitcast [4 x i32]* %11 to i8*
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to double
%16 = fdiv double %15, 1.000000e+08
store double %16, double* %9
%17 = load double, double* %9
%18 = fmul double 0x41F0000000000000, %17
%19 = fptosi double %18 to i32
store i32 %19, i32* %7
store i32 0, i32* %8
br label %20
20: ; preds = %55, %3
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %58
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = add i32 %28, %32
%34 = add i32 %33, 98
%35 = load i32, i32* %7
%36 = and i32 %35, 65535
%37 = trunc i32 %36 to i16
%38 = call i32 @write16(i8* %24, i32 %34, i16 signext %37)
%39 = load i8*, i8** %4
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = add i32 %43, %47
%49 = add i32 %48, 100
%50 = load i32, i32* %7
%51 = ashr i32 %50, 16
%52 = and i32 %51, 65535
%53 = trunc i32 %52 to i16
%54 = call i32 @write16(i8* %39, i32 %49, i16 signext %53)
br label %55
55: ; preds = %23
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %20
58: ; preds = %20
%59 = load i8*, i8** %4
%60 = call i32 @write32(i8* %59, i32 528, i32 338)
%61 = load i8*, i8** %4
%62 = call i32 @write32(i8* %61, i32 784, i32 338)
%63 = load i8*, i8** %4
%64 = call i32 @write32(i8* %63, i32 848, i32 338)
%65 = load i8*, i8** %4
%66 = call i32 @write32(i8* %65, i32 912, i32 338)
%67 = load i8*, i8** %4
%68 = call i32 @write32(i8* %67, i32 976, i32 338)
%69 = load i8*, i8** %4
%70 = call i32 @write32(i8* %69, i32 1040, i32 338)
%71 = load i8*, i8** %4
%72 = call i32 @write32(i8* %71, i32 1104, i32 338)
%73 = load i8*, i8** %4
%74 = call i32 @write32(i8* %73, i32 1168, i32 338)
%75 = load i8*, i8** %4
%76 = call i32 @write32(i8* %75, i32 1232, i32 338)
%77 = load i8*, i8** %4
%78 = call i32 @write32(i8* %77, i32 1296, i32 338)
%79 = load i8*, i8** %4
%80 = call i32 @write32(i8* %79, i32 1360, i32 338)
%81 = load i8*, i8** %4
%82 = call i32 @write32(i8* %81, i32 1424, i32 338)
%83 = load i8*, i8** %4
%84 = call i32 @write32(i8* %83, i32 1488, i32 338)
%85 = load i8*, i8** %4
%86 = call i32 @write32(i8* %85, i32 284, i32 65536)
%87 = load i8*, i8** %4
%88 = getelementptr inbounds i8, i8* %87, i64 256
%89 = bitcast i8* %88 to i32*
%90 = load i32, i32* %89
%91 = or i32 %90, 64
store i32 %91, i32* %89
%92 = load i8*, i8** %4
%93 = getelementptr inbounds i8, i8* %92, i64 256
%94 = bitcast i8* %93 to i32*
%95 = load i32, i32* %94
%96 = or i32 %95, 262144
store i32 %96, i32* %94
ret i32 1
}

LLVM IR (-O2):
@__const._change_freq.chan_control_map = [4 x i32] [i32 0, i32 128, i32 256, i32 384]
define i32 @_change_freq(i8* %0, i32 %1, i32 %2) {
%4 = sitofp i32 %2 to double
%5 = fdiv double %4, 1.000000e+08
%6 = fmul double %5, 0x41F0000000000000
%7 = fptosi double %6 to i32
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds [4 x i32], [4 x i32]* @__const._change_freq.chan_control_map, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = trunc i32 %7 to i16
%12 = lshr i32 %7, 16
%13 = trunc i32 %12 to i16
%14 = add i32 %10, 2146
%15 = tail call i32 @write16(i8* %0, i32 %14, i16 signext %11)
%16 = add i32 %10, 2148
%17 = tail call i32 @write16(i8* %0, i32 %16, i16 signext %13)
%18 = add i32 %10, 4194
%19 = tail call i32 @write16(i8* %0, i32 %18, i16 signext %11)
%20 = add i32 %10, 4196
%21 = tail call i32 @write16(i8* %0, i32 %20, i16 signext %13)
%22 = add i32 %10, 6242
%23 = tail call i32 @write16(i8* %0, i32 %22, i16 signext %11)
%24 = add i32 %10, 6244
%25 = tail call i32 @write16(i8* %0, i32 %24, i16 signext %13)
%26 = tail call i32 @write32(i8* %0, i32 528, i32 338)
%27 = tail call i32 @write32(i8* %0, i32 784, i32 338)
%28 = tail call i32 @write32(i8* %0, i32 848, i32 338)
%29 = tail call i32 @write32(i8* %0, i32 912, i32 338)
%30 = tail call i32 @write32(i8* %0, i32 976, i32 338)
%31 = tail call i32 @write32(i8* %0, i32 1040, i32 338)
%32 = tail call i32 @write32(i8* %0, i32 1104, i32 338)
%33 = tail call i32 @write32(i8* %0, i32 1168, i32 338)
%34 = tail call i32 @write32(i8* %0, i32 1232, i32 338)
%35 = tail call i32 @write32(i8* %0, i32 1296, i32 338)
%36 = tail call i32 @write32(i8* %0, i32 1360, i32 338)
%37 = tail call i32 @write32(i8* %0, i32 1424, i32 338)
%38 = tail call i32 @write32(i8* %0, i32 1488, i32 338)
%39 = tail call i32 @write32(i8* %0, i32 284, i32 65536)
%40 = getelementptr inbounds i8, i8* %0, i64 256
%41 = bitcast i8* %40 to i32*
%42 = load i32, i32* %41
%43 = or i32 %42, 262208
store i32 %43, i32* %41
ret i32 1
}