#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;
  unsigned int GC314FS_GCoffset[3] = {0x800, 0x1000, 0x1800};
  unsigned int chan_control_map[4] = {0x00, 0x80, 0x100, 0x180};
  FREQ = 4294967296 * freq / 100000000;
  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    0xec7(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x38(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x20,%rax
mov    $0x5f5e100,%ecx
cqto
idiv   %rcx
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11e1 <_change_freq+0xc1>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
mov    -0x24(%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    -0x24(%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    1178 <_change_freq+0x58>
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    %edx,%eax
mov    %rdi,%r14
shl    $0x20,%rax
movabs $0x55e63b88c230e77f,%rcx
3b e6 55
imul   %rcx
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x19,%rbx
add    %eax,%ebx
movslq %esi,%rax
lea    0xea9(%rip),%rcx
mov    (%rcx,%rax,4),%r15d
lea    0x862(%r15),%esi
movswl %bx,%ebp
mov    %ebp,%edx
call   1040 <write16@plt>
lea    0x864(%r15),%esi
sar    $0x10,%ebx
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <write16@plt>
lea    0x1062(%r15),%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <write16@plt>
lea    0x1064(%r15),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <write16@plt>
lea    0x1862(%r15),%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <write16@plt>
add    $0x1864,%r15d
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1040 <write16@plt>
mov    %r14,%rdi
mov    $0x210,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x310,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x350,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x390,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x3d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x410,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x450,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x490,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x4d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x510,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x550,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x590,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x5d0,%esi
mov    $0x152,%edx
call   1030 <write32@plt>
mov    %r14,%rdi
mov    $0x11c,%esi
mov    $0x10000,%edx
call   1030 <write32@plt>
orl    $0x40040,0x100(%r14)
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 [3 x i32]
%10 = alloca [4 x i32]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = bitcast [3 x i32]* %9 to i8*
%12 = bitcast [4 x i32]* %10 to i8*
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = mul nsw i64 4294967296, %14
%16 = sdiv i64 %15, 100000000
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
store i32 0, i32* %8
br label %18
18: ; preds = %53, %3
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %56
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = add i32 %26, %30
%32 = add i32 %31, 98
%33 = load i32, i32* %7
%34 = and i32 %33, 65535
%35 = trunc i32 %34 to i16
%36 = call i32 @write16(i8* %22, i32 %32, i16 signext %35)
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = add i32 %41, %45
%47 = add i32 %46, 100
%48 = load i32, i32* %7
%49 = ashr i32 %48, 16
%50 = and i32 %49, 65535
%51 = trunc i32 %50 to i16
%52 = call i32 @write16(i8* %37, i32 %47, i16 signext %51)
br label %53
53: ; preds = %21
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %18
56: ; preds = %18
%57 = load i8*, i8** %4
%58 = call i32 @write32(i8* %57, i32 528, i32 338)
%59 = load i8*, i8** %4
%60 = call i32 @write32(i8* %59, i32 784, i32 338)
%61 = load i8*, i8** %4
%62 = call i32 @write32(i8* %61, i32 848, i32 338)
%63 = load i8*, i8** %4
%64 = call i32 @write32(i8* %63, i32 912, i32 338)
%65 = load i8*, i8** %4
%66 = call i32 @write32(i8* %65, i32 976, i32 338)
%67 = load i8*, i8** %4
%68 = call i32 @write32(i8* %67, i32 1040, i32 338)
%69 = load i8*, i8** %4
%70 = call i32 @write32(i8* %69, i32 1104, i32 338)
%71 = load i8*, i8** %4
%72 = call i32 @write32(i8* %71, i32 1168, i32 338)
%73 = load i8*, i8** %4
%74 = call i32 @write32(i8* %73, i32 1232, i32 338)
%75 = load i8*, i8** %4
%76 = call i32 @write32(i8* %75, i32 1296, i32 338)
%77 = load i8*, i8** %4
%78 = call i32 @write32(i8* %77, i32 1360, i32 338)
%79 = load i8*, i8** %4
%80 = call i32 @write32(i8* %79, i32 1424, i32 338)
%81 = load i8*, i8** %4
%82 = call i32 @write32(i8* %81, i32 1488, i32 338)
%83 = load i8*, i8** %4
%84 = call i32 @write32(i8* %83, i32 284, i32 65536)
%85 = load i8*, i8** %4
%86 = getelementptr inbounds i8, i8* %85, i64 256
%87 = bitcast i8* %86 to i32*
%88 = load i32, i32* %87
%89 = or i32 %88, 64
store i32 %89, i32* %87
%90 = load i8*, i8** %4
%91 = getelementptr inbounds i8, i8* %90, i64 256
%92 = bitcast i8* %91 to i32*
%93 = load i32, i32* %92
%94 = or i32 %93, 262144
store i32 %94, i32* %92
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 = sext i32 %2 to i64
%5 = shl nsw i64 %4, 32
%6 = sdiv i64 %5, 100000000
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds [4 x i32], [4 x i32]* @__const._change_freq.chan_control_map, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = trunc i64 %6 to i16
%11 = lshr i64 %6, 16
%12 = trunc i64 %11 to i16
%13 = add i32 %9, 2146
%14 = tail call i32 @write16(i8* %0, i32 %13, i16 signext %10)
%15 = add i32 %9, 2148
%16 = tail call i32 @write16(i8* %0, i32 %15, i16 signext %12)
%17 = add i32 %9, 4194
%18 = tail call i32 @write16(i8* %0, i32 %17, i16 signext %10)
%19 = add i32 %9, 4196
%20 = tail call i32 @write16(i8* %0, i32 %19, i16 signext %12)
%21 = add i32 %9, 6242
%22 = tail call i32 @write16(i8* %0, i32 %21, i16 signext %10)
%23 = add i32 %9, 6244
%24 = tail call i32 @write16(i8* %0, i32 %23, i16 signext %12)
%25 = tail call i32 @write32(i8* %0, i32 528, i32 338)
%26 = tail call i32 @write32(i8* %0, i32 784, i32 338)
%27 = tail call i32 @write32(i8* %0, i32 848, i32 338)
%28 = tail call i32 @write32(i8* %0, i32 912, i32 338)
%29 = tail call i32 @write32(i8* %0, i32 976, i32 338)
%30 = tail call i32 @write32(i8* %0, i32 1040, i32 338)
%31 = tail call i32 @write32(i8* %0, i32 1104, i32 338)
%32 = tail call i32 @write32(i8* %0, i32 1168, i32 338)
%33 = tail call i32 @write32(i8* %0, i32 1232, i32 338)
%34 = tail call i32 @write32(i8* %0, i32 1296, i32 338)
%35 = tail call i32 @write32(i8* %0, i32 1360, i32 338)
%36 = tail call i32 @write32(i8* %0, i32 1424, i32 338)
%37 = tail call i32 @write32(i8* %0, i32 1488, i32 338)
%38 = tail call i32 @write32(i8* %0, i32 284, i32 65536)
%39 = getelementptr inbounds i8, i8* %0, i64 256
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = or i32 %41, 262208
store i32 %42, i32* %40
ret i32 1
}