void get_test_sample(long int sample_rate, int sample_size,
                     unsigned char *sample) {
  const unsigned char waveform[] = {
      128, 127, 126, 125, 124, 122, 120, 118, 116, 113, 111, 108, 105, 102, 99,
      96,  93,  90,  87,  83,  80,  77,  74,  70,  67,  64,  61,  58,  55,  52,
      49,  47,  44,  42,  40,  37,  36,  34,  32,  31,  29,  28,  27,  26,  26,
      25,  25,  25,  25,  25,  25,  26,  26,  27,  28,  29,  30,  31,  33,  34,
      36,  37,  39,  41,  42,  44,  46,  48,  50,  52,  54,  56,  58,  60,  62,
      64,  66,  68,  69,  71,  73,  74,  76,  77,  79,  80,  81,  82,  83,  84,
      85,  86,  86,  87,  87,  88,  88,  88,  88,  88,  88,  88,  87,  87,  86,
      86,  85,  85,  84,  83,  82,  81,  80,  79,  78,  77,  76,  75,  74,  72,
      71,  70,  69,  68,  66,  65,  64,  63,  62,  61,  60,  59,  58,  57,  56,
      55,  54,  54,  53,  52,  52,  51,  51,  50,  50,  50,  50,  50,  50,  50,
      50,  50,  50,  50,  50,  51,  51,  51,  52,  52,  53,  54,  54,  55,  55,
      56,  57,  57,  58,  59,  60,  60,  61,  62,  63,  63,  64,  65,  65,  66,
      67,  67,  68,  68,  69,  69,  70,  70,  71,  71,  71,  72,  72,  72,  72,
      73,  73,  73,  73,  73,  73,  73,  73,  72,  72,  72,  72,  72,  71,  71,
      71,  70,  70,  70,  69,  69,  68,  68,  68,  67,  67,  66,  66,  65,  65,
      64,  64,  64,  63,  63,  62,  62,  62,  61,  61,  61,  60,  60,  60,  60,
      59,  59,  59,  59,  59,  59,  59,  59,  59,  59,  59,  59,  59,  59,  59,
      59,  59,  59,  60,  60,  60,  60,  60,  61,  61,  61,  61,  62,  62,  62,
      62,  63,  63,  63,  63,  64,  64,  64,  65,  65,  65,  65,  65,  66,  66,
      66,  66,  66,  66,  67,  67,  67,  67,  67,  67,  67,  67,  67,  67,  67,
      67,  67,  67,  67,  67,  67,  67,  67,  67,  67,  66,  66,  66,  66,  66,
      66,  66,  65,  65,  65,  65,  65,  65,  64,  64,  64,  64,  64,  64,  64,
      63,  63,  63,  63,  63,  63,  63,  63,  62,  62,  62,  62,  62,  62,  62,
      62,  62,  62,  62,  62,  62,  62,  62,  62,  62,  62,  62,  62,  62,  62,
      63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  64,  64,  64,  64,
      64,  64,  64,  64,  64,  64,  64,  65,  65,  65,  65,  65,  65,  65,  65,
      65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,
      65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  65,  64,  64,
      64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
      64,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,
      63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  63,  64,  64,  64,  64,
      64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64};
  long int sample_pt = 0;
  int sample_sign = 1;
  while (sample_size-- > 0) {
    if (sample_sign > 0)
      *sample++ = waveform[sample_pt / 20] + 127;
    else
      *sample++ = 128 - waveform[sample_pt / 20];
    sample_pt += (10000000L / sample_rate);
    while (sample_pt >= (20 * (sizeof(waveform) / sizeof(unsigned char)))) {
      sample_pt -= (20 * (sizeof(waveform) / sizeof(unsigned char)));
      sample_sign = -sample_sign;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<get_test_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x200(%rbp),%rdi
lea    0xecc(%rip),%rsi
mov    $0x1e0,%edx
call   1030 <memcpy@plt>
movq   $0x0,-0x208(%rbp)
movl   $0x1,-0x20c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1231 <get_test_sample+0x121>
cmpl   $0x0,-0x20c(%rbp)
jle    11a8 <get_test_sample+0x98>
mov    -0x208(%rbp),%rax
mov    $0x14,%ecx
cqto
idiv   %rcx
movzbl -0x200(%rbp,%rax,1),%eax
ff
add    $0x7f,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11db <get_test_sample+0xcb>
mov    -0x208(%rbp),%rax
mov    $0x14,%ecx
cqto
idiv   %rcx
movzbl -0x200(%rbp,%rax,1),%ecx
ff
mov    $0x80,%eax
sub    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    $0x989680,%eax
cqto
idivq  -0x8(%rbp)
add    -0x208(%rbp),%rax
mov    %rax,-0x208(%rbp)
cmpq   $0x2580,-0x208(%rbp)
jb     122c <get_test_sample+0x11c>
mov    -0x208(%rbp),%rax
sub    $0x2580,%rax
mov    %rax,-0x208(%rbp)
xor    %eax,%eax
sub    -0x20c(%rbp),%eax
mov    %eax,-0x20c(%rbp)
jmp    11f4 <get_test_sample+0xe4>
jmp    1153 <get_test_sample+0x43>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_test_sample>:
push   %r14
push   %rbx
test   %esi,%esi
jle    1205 <get_test_sample+0x105>
mov    %rdx,%r10
mov    %rdi,%rax
shr    $0x20,%rax
je     1126 <get_test_sample+0x26>
mov    $0x989680,%eax
xor    %edx,%edx
idiv   %rdi
mov    %rax,%r8
jmp    1132 <get_test_sample+0x32>
mov    $0x989680,%eax
xor    %edx,%edx
div    %edi
mov    %eax,%r8d
lea    -0x2580(%r8),%r9
mov    $0x1,%ecx
xor    %ebx,%ebx
lea    0xeb9(%rip),%r11
movabs $0x6d3a06d3a06d3a07,%r14
06 3a 6d
jmp    1175 <get_test_sample+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%rsi),%eax
add    $0x1,%r10
mov    %rdi,%rbx
cmp    $0x2,%esi
mov    %eax,%esi
jl     1205 <get_test_sample+0x105>
movzwl %bx,%eax
imul   $0xcccd,%eax,%eax
shr    $0x14,%eax
mov    (%rax,%r11,1),%al
mov    $0x80,%dl
sub    %al,%dl
add    $0x7f,%al
test   %ecx,%ecx
movzbl %al,%eax
movzbl %dl,%edx
cmovg  %eax,%edx
mov    %dl,(%r10)
lea    (%r8,%rbx,1),%rdi
cmp    $0x2580,%rdi
jb     1160 <get_test_sample+0x60>
add    %r9,%rbx
mov    %rbx,%rax
mul    %r14
shr    $0xc,%edx
add    $0x1,%edx
and    $0x7,%rdx
je     11e0 <get_test_sample+0xe0>
imul   $0x2580,%rdx,%rdx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
neg    %ecx
add    $0x2580,%rax
cmp    %rax,%rdx
jne    11d0 <get_test_sample+0xd0>
sub    %rax,%rdi
cmp    $0x10680,%rbx
jb     1160 <get_test_sample+0x60>
nopl   (%rax)
add    $0xfffffffffffed400,%rdi
cmp    $0x257f,%rdi
ja     11f0 <get_test_sample+0xf0>
jmp    1160 <get_test_sample+0x60>
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.get_test_sample.waveform = [480 x i8] c"\80\7F~}|zxvtqolifc`]ZWSPMJFC@=:741/,*(%$\22 \1F\1D\1C\1B\1A\1A\19\19\19\19\19\19\1A\1A\1B\1C\1D\1E\1F!\22$%')*,.02468:<>@BDEGIJLMOPQRSTUVVWWXXXXXXXWWVVUUTSRQPONMLKJHGFEDBA@?>=<;:98766544332222222222223334456677899:;<<=>??@AABCCDDEEFFGGGHHHHIIIIIIIIHHHHHGGGFFFEEDDDCCBBAA@@@??>>>===<<<<;;;;;;;;;;;;;;;;;;<<<<<====>>>>????@@@AAAAABBBBBBCCCCCCCCCCCCCCCCCCCCCBBBBBBBAAAAAA@@@@@@@????????>>>>>>>>>>>>>>>>>>>>>>???????????@@@@@@@@@@@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@@@@@@@@@@@@@@@@@@?????????????????????????@@@@@@@@@@@@@@@@@@@"
define void @get_test_sample(i64 %0, i32 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [480 x i8]
%8 = alloca i64
%9 = alloca i32
store i64 %0, i64* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = bitcast [480 x i8]* %7 to i8*
store i64 0, i64* %8
store i32 1, i32* %9
br label %11
11: ; preds = %51, %3
%12 = load i32, i32* %5
%13 = add nsw i32 %12, -1
store i32 %13, i32* %5
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %52
15: ; preds = %11
%16 = load i32, i32* %9
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i64, i64* %8
%20 = sdiv i64 %19, 20
%21 = getelementptr inbounds [480 x i8], [480 x i8]* %7, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = add nsw i32 %23, 127
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
store i8 %25, i8* %26
br label %38
28: ; preds = %15
%29 = load i64, i64* %8
%30 = sdiv i64 %29, 20
%31 = getelementptr inbounds [480 x i8], [480 x i8]* %7, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = sub nsw i32 128, %33
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %6
store i8 %35, i8* %36
br label %38
38: ; preds = %28, %18
%39 = load i64, i64* %4
%40 = sdiv i64 10000000, %39
%41 = load i64, i64* %8
%42 = add nsw i64 %41, %40
store i64 %42, i64* %8
br label %43
43: ; preds = %46, %38
%44 = load i64, i64* %8
%45 = icmp uge i64 %44, 9600
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i64, i64* %8
%48 = sub i64 %47, 9600
store i64 %48, i64* %8
%49 = load i32, i32* %9
%50 = sub nsw i32 0, %49
store i32 %50, i32* %9
br label %43
51: ; preds = %43
br label %11
52: ; preds = %11
ret void
}

LLVM IR (-O2):
@__const.get_test_sample.waveform = [480 x i8] c"\80\7F~}|zxvtqolifc`]ZWSPMJFC@=:741/,*(%$\22 \1F\1D\1C\1B\1A\1A\19\19\19\19\19\19\1A\1A\1B\1C\1D\1E\1F!\22$%')*,.02468:<>@BDEGIJLMOPQRSTUVVWWXXXXXXXWWVVUUTSRQPONMLKJHGFEDBA@?>=<;:98766544332222222222223334456677899:;<<=>??@AABCCDDEEFFGGGHHHHIIIIIIIIHHHHHGGGFFFEEDDDCCBBAA@@@??>>>===<<<<;;;;;;;;;;;;;;;;;;<<<<<====>>>>????@@@AAAAABBBBBBCCCCCCCCCCCCCCCCCCCCCBBBBBBBAAAAAA@@@@@@@????????>>>>>>>>>>>>>>>>>>>>>>???????????@@@@@@@@@@@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@@@@@@@@@@@@@@@@@@?????????????????????????@@@@@@@@@@@@@@@@@@@"
define void @get_test_sample(i64 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %54
5: ; preds = %3
%6 = sdiv i64 10000000, %0
%7 = add nsw i64 %6, -9600
br label %12
8: ; preds = %44, %50, %12
%9 = phi i64 [ %28, %12 ], [ %47, %44 ], [ %52, %50 ]
%10 = phi i32 [ %14, %12 ], [ %48, %44 ], [ %45, %50 ]
%11 = icmp sgt i32 %13, 1
br i1 %11, label %12, label %54
12: ; preds = %5, %8
%13 = phi i32 [ %1, %5 ], [ %17, %8 ]
%14 = phi i32 [ 1, %5 ], [ %10, %8 ]
%15 = phi i64 [ 0, %5 ], [ %9, %8 ]
%16 = phi i8* [ %2, %5 ], [ %27, %8 ]
%17 = add nsw i32 %13, -1
%18 = icmp sgt i32 %14, 0
%19 = trunc i64 %15 to i16
%20 = udiv i16 %19, 20
%21 = zext i16 %20 to i64
%22 = getelementptr inbounds [480 x i8], [480 x i8]* @__const.get_test_sample.waveform, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sub i8 -128, %23
%25 = add i8 %23, 127
%26 = select i1 %18, i8 %25, i8 %24
%27 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %26, i8* %16
%28 = add nsw i64 %6, %15
%29 = icmp ugt i64 %28, 9599
br i1 %29, label %30, label %8
30: ; preds = %12
%31 = add i64 %7, %15
%32 = udiv i64 %31, 9600
%33 = add nuw nsw i64 %32, 1
%34 = and i64 %33, 7
%35 = icmp eq i64 %34, 0
br i1 %35, label %44, label %36
36: ; preds = %30, %36
%37 = phi i32 [ %41, %36 ], [ %14, %30 ]
%38 = phi i64 [ %40, %36 ], [ %28, %30 ]
%39 = phi i64 [ %42, %36 ], [ 0, %30 ]
%40 = add i64 %38, -9600
%41 = sub nsw i32 0, %37
%42 = add i64 %39, 1
%43 = icmp eq i64 %42, %34
br i1 %43, label %44, label %36
44: ; preds = %36, %30
%45 = phi i32 [ %14, %30 ], [ %41, %36 ]
%46 = phi i64 [ %28, %30 ], [ %40, %36 ]
%47 = phi i64 [ undef, %30 ], [ %40, %36 ]
%48 = phi i32 [ undef, %30 ], [ %41, %36 ]
%49 = icmp ult i64 %31, 67200
br i1 %49, label %8, label %50
50: ; preds = %44, %50
%51 = phi i64 [ %52, %50 ], [ %46, %44 ]
%52 = add i64 %51, -76800
%53 = icmp ugt i64 %52, 9599
br i1 %53, label %50, label %8
54: ; preds = %8, %3
ret void
}