#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 generate_sinewave_1(int, int);
int generate_sinewave_2(int, int);
int generate_DTMF(char button) {
  int output;
  int temp;
  int frequency1 = 0;
  int frequency2 = 0;
  switch (button) {
  case '1':
    frequency1 = 697;
    frequency2 = 1209;
    break;
  case '2':
    frequency1 = 697;
    frequency2 = 1336;
    break;
  case '3':
    frequency1 = 697;
    frequency2 = 1477;
    break;
  case '4':
    frequency1 = 770;
    frequency2 = 1209;
    break;
  case '5':
    frequency1 = 770;
    frequency2 = 1336;
    break;
  case '6':
    frequency1 = 770;
    frequency2 = 1477;
    break;
  case '7':
    frequency1 = 852;
    frequency2 = 1209;
    break;
  case '8':
    frequency1 = 852;
    frequency2 = 1336;
    break;
  case '9':
    frequency1 = 852;
    frequency2 = 1477;
    break;
  case '*':
    frequency1 = 941;
    frequency2 = 1209;
    break;
  case '0':
    frequency1 = 941;
    frequency2 = 1336;
    break;
  case '#':
    frequency1 = 941;
    frequency2 = 1477;
    break;
  default:
    frequency1 = 0;
    frequency2 = 0;
    break;
  }
  output = 0;
  if (frequency1 > 0) {
    output = generate_sinewave_1(frequency1, 8096);
  }
  if (frequency2 > 0) {
    temp = generate_sinewave_2(frequency2, 8096);
    output += temp;
  }
  return (output);
}


x86 assembly (clang, -O0):
<generate_DTMF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xffffffdd,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x16,%eax
ja     124a <generate_DTMF+0x12a>
mov    -0x20(%rbp),%rax
lea    0xea3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2b9,-0x10(%rbp)
movl   $0x4b9,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x2b9,-0x10(%rbp)
movl   $0x538,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x2b9,-0x10(%rbp)
movl   $0x5c5,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x302,-0x10(%rbp)
movl   $0x4b9,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x302,-0x10(%rbp)
movl   $0x538,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x302,-0x10(%rbp)
movl   $0x5c5,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x354,-0x10(%rbp)
movl   $0x4b9,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x354,-0x10(%rbp)
movl   $0x538,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x354,-0x10(%rbp)
movl   $0x5c5,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x3ad,-0x10(%rbp)
movl   $0x4b9,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x3ad,-0x10(%rbp)
movl   $0x538,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x3ad,-0x10(%rbp)
movl   $0x5c5,-0x14(%rbp)
jmp    1258 <generate_DTMF+0x138>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1279 <generate_DTMF+0x159>
mov    -0x10(%rbp),%edi
mov    $0x1fa0,%esi
call   1040 <generate_sinewave_1@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    129c <generate_DTMF+0x17c>
mov    -0x14(%rbp),%edi
mov    $0x1fa0,%esi
call   1030 <generate_sinewave_2@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_DTMF>:
add    $0xffffffdd,%edi
xor    %eax,%eax
cmp    $0x16,%edi
ja     116e <generate_DTMF+0x4e>
mov    $0x7fe081,%ecx
bt     %edi,%ecx
jae    116e <generate_DTMF+0x4e>
push   %rbp
push   %rbx
push   %rax
movslq %edi,%rax
lea    0xebf(%rip),%rcx
mov    (%rcx,%rax,4),%edi
lea    0xf11(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    $0x1fa0,%esi
call   1040 <generate_sinewave_1@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x1fa0,%esi
call   1030 <generate_sinewave_2@plt>
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @generate_DTMF(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
switch i32 %8, label %21 [
i32 49, label %9
i32 50, label %10
i32 51, label %11
i32 52, label %12
i32 53, label %13
i32 54, label %14
i32 55, label %15
i32 56, label %16
i32 57, label %17
i32 42, label %18
i32 48, label %19
i32 35, label %20
]
9: ; preds = %1
store i32 697, i32* %5
store i32 1209, i32* %6
br label %22
10: ; preds = %1
store i32 697, i32* %5
store i32 1336, i32* %6
br label %22
11: ; preds = %1
store i32 697, i32* %5
store i32 1477, i32* %6
br label %22
12: ; preds = %1
store i32 770, i32* %5
store i32 1209, i32* %6
br label %22
13: ; preds = %1
store i32 770, i32* %5
store i32 1336, i32* %6
br label %22
14: ; preds = %1
store i32 770, i32* %5
store i32 1477, i32* %6
br label %22
15: ; preds = %1
store i32 852, i32* %5
store i32 1209, i32* %6
br label %22
16: ; preds = %1
store i32 852, i32* %5
store i32 1336, i32* %6
br label %22
17: ; preds = %1
store i32 852, i32* %5
store i32 1477, i32* %6
br label %22
18: ; preds = %1
store i32 941, i32* %5
store i32 1209, i32* %6
br label %22
19: ; preds = %1
store i32 941, i32* %5
store i32 1336, i32* %6
br label %22
20: ; preds = %1
store i32 941, i32* %5
store i32 1477, i32* %6
br label %22
21: ; preds = %1
store i32 0, i32* %5
store i32 0, i32* %6
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9
store i32 0, i32* %3
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %5
%27 = call i32 @generate_sinewave_1(i32 %26, i32 8096)
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32, i32* %6
%33 = call i32 @generate_sinewave_2(i32 %32, i32 8096)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = load i32, i32* %3
%36 = add nsw i32 %35, %34
store i32 %36, i32* %3
br label %37
37: ; preds = %31, %28
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@switch.table.generate_DTMF = [23 x i32] [i32 941, i32 697, i32 697, i32 697, i32 697, i32 697, i32 697, i32 941, i32 697, i32 697, i32 697, i32 697, i32 697, i32 941, i32 697, i32 697, i32 697, i32 770, i32 770, i32 770, i32 852, i32 852, i32 852]
@switch.table.generate_DTMF.1 = [23 x i32] [i32 1477, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1209, i32 1336, i32 1209, i32 1336, i32 1477, i32 1209, i32 1336, i32 1477, i32 1209, i32 1336, i32 1477]
define i32 @generate_DTMF(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = add nsw i32 %2, -35
%4 = icmp ult i32 %3, 23
br i1 %4, label %5, label %19
5: ; preds = %1
%6 = lshr i32 8380545, %3
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %5
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds [23 x i32], [23 x i32]* @switch.table.generate_DTMF, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = sext i32 %3 to i64
%14 = getelementptr inbounds [23 x i32], [23 x i32]* @switch.table.generate_DTMF.1, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = tail call i32 @generate_sinewave_1(i32 %12, i32 8096)
%17 = tail call i32 @generate_sinewave_2(i32 %15, i32 8096)
%18 = add nsw i32 %17, %16
br label %19
19: ; preds = %5, %1, %9
%20 = phi i32 [ %18, %9 ], [ 0, %1 ], [ 0, %5 ]
ret i32 %20
}