#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 SpeakerBeep2(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--) {
    tone(speaker, 440 * b[i]);
    delay(100);
  }
  noTone(speaker);
}


x86 assembly (clang, -O0):
<SpeakerBeep2>:
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 <SpeakerBeep2+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 <SpeakerBeep2+0x19>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11c3 <SpeakerBeep2+0x93>
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 <SpeakerBeep2+0x5a>
mov    -0x4(%rbp),%edi
call   1050 <noTone@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SpeakerBeep2>:
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 <SpeakerBeep2+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 <SpeakerBeep2+0x20>
test   %r15d,%r15d
js     11a0 <SpeakerBeep2+0x70>
nopl   0x0(%rax,%rax,1)
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 <SpeakerBeep2+0x50>
mov    %r12d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <noTone@plt>

LLVM IR (-O0):
define void @SpeakerBeep2(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 = %41, %26
%29 = load i32, i32* %8
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i32, i32* %4
%33 = load i32*, i32** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = mul nsw i32 440, %37
%39 = call i32 @tone(i32 %32, i32 %38)
%40 = call i32 @delay(i32 100)
br label %41
41: ; preds = %31
%42 = load i32, i32* %8
%43 = add nsw i32 %42, -1
store i32 %43, i32* %8
br label %28
44: ; preds = %28
%45 = load i32, i32* %4
%46 = call i32 @noTone(i32 %45)
ret void
}

LLVM IR (-O2):
define void @SpeakerBeep2(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 ], [ %29, %22 ]
%24 = getelementptr inbounds i32, i32* %1, i64 %23
%25 = load i32, i32* %24
%26 = mul nsw i32 %25, 440
%27 = tail call i32 @tone(i32 %0, i32 %26)
%28 = tail call i32 @delay(i32 100)
%29 = add nsw i64 %23, -1
%30 = icmp eq i64 %23, 0
br i1 %30, label %20, label %22
}