#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mark(int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, char *);
int voiceFactory(int, int, int, int);
int makeTone(int freq) {
  char *filename = "test_tone.raw";
  int hvox = voiceFactory(freq, 64, 128, 44100);
  FILE *out = fopen(filename, "w");
  mark(hvox, 1 * 44100, out);
  fclose(out);
  printf("Test tone of %d Hz created in %s\n", freq, filename);
  return 0;
}


x86 assembly (clang, -O0):
<makeTone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x40,%esi
mov    $0x80,%edx
mov    $0xac44,%ecx
call   1030 <voiceFactory@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    $0xac44,%esi
call   1060 <mark@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeTone>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x40,%esi
mov    $0x80,%edx
mov    $0xac44,%ecx
call   1030 <voiceFactory@plt>
mov    %eax,%ebp
lea    0xe89(%rip),%r14
lea    0xe8e(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    $0xac44,%esi
mov    %rax,%rdx
call   1060 <mark@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe67(%rip),%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"test_tone.raw\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [34 x i8] c"Test tone of %d Hz created in %s\0A\00"
define i32 @makeTone(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i32 %0, i32* %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i32, i32* %2
%7 = call i32 @voiceFactory(i32 %6, i32 64, i32 128, i32 44100)
store i32 %7, i32* %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32, i32* %4
%11 = load i32*, i32** %5
%12 = call i32 @mark(i32 %10, i32 44100, i32* %11)
%13 = load i32*, i32** %5
%14 = call i32 @fclose(i32* %13)
%15 = load i32, i32* %2
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"test_tone.raw\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [34 x i8] c"Test tone of %d Hz created in %s\0A\00"
define i32 @makeTone(i32 %0) {
%2 = tail call i32 @voiceFactory(i32 %0, i32 64, i32 128, i32 44100)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @mark(i32 %2, i32 44100, i32* %3)
%5 = tail call i32 @fclose(i32* %3)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
ret i32 0
}