#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*/ fabs(float);
float sin(float);
float raw_waveform(float phase, int type) {
  float value;
  switch (type) {
  case 0:
    value = sin(phase);
    break;
  case 1:
    value = (2.0 * phase / (3.141592653589 * 2.0)) - 1.0;
    break;
  case 2:
    if (phase < (3.141592653589)) {
      value = 1.0;
    } else {
      value = -1.0;
    }
    break;
  case 3:
    value = -1.0 + (2.0 * phase / (3.141592653589 * 2.0));
    value = 2.0 * (fabs(value) - 0.5);
    break;
  default:
    value = 0;
    break;
  }
  return value;
}


x86 assembly (clang, -O0):
<raw_waveform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     124d <raw_waveform+0x12d>
mov    -0x18(%rbp),%rax
lea    0xeec(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x4(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0xc(%rbp)
jmp    1255 <raw_waveform+0x135>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe86(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe92(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe96(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1255 <raw_waveform+0x135>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d1 <raw_waveform+0xb1>
movss  0xe6d(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    11de <raw_waveform+0xbe>
movss  0xe57(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1255 <raw_waveform+0x135>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe0c(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe18(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe04(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdd9(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xdc5(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1255 <raw_waveform+0x135>
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw_waveform>:
push   %rax
cmp    $0x3,%edi
ja     113e <raw_waveform+0x1e>
mov    %edi,%eax
lea    0xef9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
pop    %rax
jmp    1040 <sin@plt>
xorps  %xmm0,%xmm0
pop    %rax
ret
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
divsd  0xead(%rip),%xmm0
addsd  0xead(%rip),%xmm0
jmp    11b4 <raw_waveform+0x94>
cvtss2sd %xmm0,%xmm0
movsd  0xeaf(%rip),%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
lea    0xea7(%rip),%rcx
movss  (%rcx,%rax,4),%xmm0
pop    %rax
ret
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
divsd  0xe70(%rip),%xmm0
addsd  0xe70(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xe60(%rip),%xmm0
addsd  %xmm0,%xmm0
cvtsd2ss %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @raw_waveform(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca float
store float %0, float* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %37 [
i32 0, label %7
i32 1, label %10
i32 2, label %17
i32 3, label %24
]
7: ; preds = %2
%8 = load float, float* %3
%9 = call float @sin(float %8)
store float %9, float* %5
br label %38
10: ; preds = %2
%11 = load float, float* %3
%12 = fpext float %11 to double
%13 = fmul double 2.000000e+00, %12
%14 = fdiv double %13, 0x401921FB5444261E
%15 = fsub double %14, 1.000000e+00
%16 = fptrunc double %15 to float
store float %16, float* %5
br label %38
17: ; preds = %2
%18 = load float, float* %3
%19 = fpext float %18 to double
%20 = fcmp olt double %19, 0x400921FB5444261E
br i1 %20, label %21, label %22
21: ; preds = %17
store float 1.000000e+00, float* %5
br label %23
22: ; preds = %17
store float -1.000000e+00, float* %5
br label %23
23: ; preds = %22, %21
br label %38
24: ; preds = %2
%25 = load float, float* %3
%26 = fpext float %25 to double
%27 = fmul double 2.000000e+00, %26
%28 = fdiv double %27, 0x401921FB5444261E
%29 = fadd double -1.000000e+00, %28
%30 = fptrunc double %29 to float
store float %30, float* %5
%31 = load float, float* %5
%32 = call i32 @fabs(float %31)
%33 = sitofp i32 %32 to double
%34 = fsub double %33, 5.000000e-01
%35 = fmul double 2.000000e+00, %34
%36 = fptrunc double %35 to float
store float %36, float* %5
br label %38
37: ; preds = %2
store float 0.000000e+00, float* %5
br label %38
38: ; preds = %37, %24, %23, %10, %7
%39 = load float, float* %5
ret float %39
}

LLVM IR (-O2):
define float @raw_waveform(float %0, i32 %1) {
switch i32 %1, label %26 [
i32 0, label %3
i32 1, label %5
i32 2, label %11
i32 3, label %15
]
3: ; preds = %2
%4 = tail call float @sin(float %0)
br label %26
5: ; preds = %2
%6 = fpext float %0 to double
%7 = fmul double %6, 2.000000e+00
%8 = fdiv double %7, 0x401921FB5444261E
%9 = fadd double %8, -1.000000e+00
%10 = fptrunc double %9 to float
br label %26
11: ; preds = %2
%12 = fpext float %0 to double
%13 = fcmp olt double %12, 0x400921FB5444261E
%14 = select i1 %13, float 1.000000e+00, float -1.000000e+00
br label %26
15: ; preds = %2
%16 = fpext float %0 to double
%17 = fmul double %16, 2.000000e+00
%18 = fdiv double %17, 0x401921FB5444261E
%19 = fadd double %18, -1.000000e+00
%20 = fptrunc double %19 to float
%21 = tail call i32 @fabs(float %20)
%22 = sitofp i32 %21 to double
%23 = fadd double %22, -5.000000e-01
%24 = fmul double %23, 2.000000e+00
%25 = fptrunc double %24 to float
br label %26
26: ; preds = %2, %11, %15, %5, %3
%27 = phi float [ %25, %15 ], [ %10, %5 ], [ %4, %3 ], [ %14, %11 ], [ 0.000000e+00, %2 ]
ret float %27
}