#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*/ delay(int);
int /*<<< orphan*/ noTone(int);
int /*<<< orphan*/ tone(int, int);
void SpeakerBeep(int speaker, int b[], int c) {
  for (int i = 0; i < c; i++) {
    tone(speaker, 220 * b[i]);
    delay(100);
  }
  for (int i = c; i >= 0; i--) {
    delay(100);
    tone(speaker, 440 * b[i]);
    delay(100);
  }
  noTone(speaker);
}


x86 assembly (clang, -O0):
<SpeakerBeep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1184 <SpeakerBeep+0x54>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0xdc,(%rax,%rcx,4),%esi
call   1040 <tone@plt>
mov    $0x64,%edi
call   1030 <delay@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <SpeakerBeep+0x19>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11cd <SpeakerBeep+0x9d>
mov    $0x64,%edi
call   1030 <delay@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x1b8,(%rax,%rcx,4),%esi
call   1040 <tone@plt>
mov    $0x64,%edi
call   1030 <delay@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    118a <SpeakerBeep+0x5a>
mov    -0x4(%rbp),%edi
call   1050 <noTone@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SpeakerBeep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%r12d
mov    %edx,%ebp
test   %edx,%edx
jle    1173 <SpeakerBeep+0x43>
xor    %ebx,%ebx
nopl   0x0(%rax)
imul   $0xdc,(%r14,%rbx,4),%esi
mov    %r12d,%edi
call   1040 <tone@plt>
mov    $0x64,%edi
call   1030 <delay@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <SpeakerBeep+0x20>
test   %r15d,%r15d
js     11aa <SpeakerBeep+0x7a>
nopl   0x0(%rax,%rax,1)
mov    $0x64,%edi
call   1030 <delay@plt>
imul   $0x1b8,(%r14,%rbp,4),%esi
mov    %r12d,%edi
call   1040 <tone@plt>
mov    $0x64,%edi
call   1030 <delay@plt>
add    $0xffffffffffffffff,%rbp
jb     1180 <SpeakerBeep+0x50>
mov    %r12d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <noTone@plt>

LLVM IR (-O0):
define void @SpeakerBeep(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = mul nsw i32 220, %19
%21 = call i32 @tone(i32 %14, i32 %20)
%22 = call i32 @delay(i32 100)
br label %23
23: ; preds = %13
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %9
26: ; preds = %9
%27 = load i32, i32* %6
store i32 %27, i32* %8
br label %28
28: ; preds = %42, %26
%29 = load i32, i32* %8
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = call i32 @delay(i32 100)
%33 = load i32, i32* %4
%34 = load i32*, i32** %5
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = mul nsw i32 440, %38
%40 = call i32 @tone(i32 %33, i32 %39)
%41 = call i32 @delay(i32 100)
br label %42
42: ; preds = %31
%43 = load i32, i32* %8
%44 = add nsw i32 %43, -1
store i32 %44, i32* %8
br label %28
45: ; preds = %28
%46 = load i32, i32* %4
%47 = call i32 @noTone(i32 %46)
ret void
}

LLVM IR (-O2):
define void @SpeakerBeep(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %11
7: ; preds = %11, %3
%8 = icmp sgt i32 %2, -1
br i1 %8, label %9, label %20
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %22
11: ; preds = %5, %11
%12 = phi i64 [ 0, %5 ], [ %18, %11 ]
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, 220
%16 = tail call i32 @tone(i32 %0, i32 %15)
%17 = tail call i32 @delay(i32 100)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %7, label %11
20: ; preds = %22, %7
%21 = tail call i32 @noTone(i32 %0)
ret void
22: ; preds = %9, %22
%23 = phi i64 [ %10, %9 ], [ %30, %22 ]
%24 = tail call i32 @delay(i32 100)
%25 = getelementptr inbounds i32, i32* %1, i64 %23
%26 = load i32, i32* %25
%27 = mul nsw i32 %26, 440
%28 = tail call i32 @tone(i32 %0, i32 %27)
%29 = tail call i32 @delay(i32 100)
%30 = add nsw i64 %23, -1
%31 = icmp eq i64 %23, 0
br i1 %31, label %20, label %22
}