#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 */
typedef int uint8_t;
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
int16_t sin16_C(uint16_t theta) {
  static const uint16_t base[] = {0,     6393,  12539, 18204,
                                  23170, 27245, 30273, 32137};
  static const uint8_t slope[] = {49, 48, 44, 38, 31, 23, 14, 4};
  uint16_t offset = (theta & 0x3FFF) >> 3;
  if (theta & 0x4000)
    offset = 2047 - offset;
  uint8_t section = offset / 256;
  uint16_t b = base[section];
  uint8_t m = slope[section];
  uint8_t secoffset8 = (uint8_t)(offset) / 2;
  uint16_t mx = m * secoffset8;
  int16_t y = mx + b;
  if (theta & 0x8000)
    y = -y;
  return y;
}


x86 assembly (clang, -O0):
<sin16_C>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3fff,%eax
sar    $0x3,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     1131 <sin16_C+0x31>
mov    $0x7ff,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
lea    0xeb6(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rcx
lea    0xec5(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     119b <sin16_C+0x9b>
xor    %eax,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sin16_C>:
mov    %edi,%eax
shr    $0x3,%eax
and    $0x7ff,%eax
mov    %eax,%ecx
xor    $0x7ff,%ecx
test   $0x4000,%edi
cmove  %eax,%ecx
mov    %ecx,%eax
shr    $0x8,%eax
lea    0xed9(%rip),%rdx
lea    0xef2(%rip),%rsi
shr    %ecx
imul   (%rsi,%rax,4),%ecx
add    (%rdx,%rax,4),%ecx
mov    %ecx,%eax
neg    %eax
test   $0x8000,%edi
cmove  %ecx,%eax
ret

LLVM IR (-O0):
@sin16_C.base = internal constant [8 x i32] [i32 0, i32 6393, i32 12539, i32 18204, i32 23170, i32 27245, i32 30273, i32 32137]
@sin16_C.slope = internal constant [8 x i32] [i32 49, i32 48, i32 44, i32 38, i32 31, i32 23, i32 14, i32 4]
define i32 @sin16_C(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
%10 = load i32, i32* %2
%11 = and i32 %10, 16383
%12 = ashr i32 %11, 3
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = and i32 %13, 16384
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i32, i32* %3
%18 = sub nsw i32 2047, %17
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %1
%20 = load i32, i32* %3
%21 = sdiv i32 %20, 256
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [8 x i32], [8 x i32]* @sin16_C.base, i64 0, i64 %23
%25 = load i32, i32* %24
store i32 %25, i32* %5
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [8 x i32], [8 x i32]* @sin16_C.slope, i64 0, i64 %27
%29 = load i32, i32* %28
store i32 %29, i32* %6
%30 = load i32, i32* %3
%31 = sdiv i32 %30, 2
store i32 %31, i32* %7
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = mul nsw i32 %32, %33
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = load i32, i32* %5
%37 = add nsw i32 %35, %36
store i32 %37, i32* %9
%38 = load i32, i32* %2
%39 = and i32 %38, 32768
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %19
%42 = load i32, i32* %9
%43 = sub nsw i32 0, %42
store i32 %43, i32* %9
br label %44
44: ; preds = %41, %19
%45 = load i32, i32* %9
ret i32 %45
}

LLVM IR (-O2):
@sin16_C.base = internal unnamed_addr constant [8 x i32] [i32 0, i32 6393, i32 12539, i32 18204, i32 23170, i32 27245, i32 30273, i32 32137]
@sin16_C.slope = internal unnamed_addr constant [8 x i32] [i32 49, i32 48, i32 44, i32 38, i32 31, i32 23, i32 14, i32 4]
define i32 @sin16_C(i32 %0) {
%2 = lshr i32 %0, 3
%3 = and i32 %2, 2047
%4 = and i32 %0, 16384
%5 = icmp eq i32 %4, 0
%6 = xor i32 %3, 2047
%7 = select i1 %5, i32 %3, i32 %6
%8 = lshr i32 %7, 8
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [8 x i32], [8 x i32]* @sin16_C.base, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = getelementptr inbounds [8 x i32], [8 x i32]* @sin16_C.slope, i64 0, i64 %9
%13 = load i32, i32* %12
%14 = lshr i32 %7, 1
%15 = mul nsw i32 %13, %14
%16 = add nsw i32 %15, %11
%17 = and i32 %0, 32768
%18 = icmp eq i32 %17, 0
%19 = sub nsw i32 0, %16
%20 = select i1 %18, i32 %16, i32 %19
ret i32 %20
}