#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 */
float atof(char *);
double cos(float);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *f;
  int i;
  float freq;
  short buf[8000];
  if (argc != 3) {
    printf("usage: mksine outputFile frequencyHz\n");
    exit(0);
  }
  f = fopen(argv[1], "wb");
  freq = atof(argv[2]);
  for (i = 0; i < 8000; i++)
    buf[i] = 1000.0 * cos(freq * i * (6.283185307 / 8000.0));
  fwrite(buf, sizeof(short), 8000, f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3ea0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1196 <main+0x36>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1f40,-0x1c(%rbp)
jge    1228 <main+0xc8>
movss  -0x20(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe12(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <cos@plt>
movsd  0xe05(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%cx
movslq -0x1c(%rbp),%rax
mov    %cx,-0x3ea0(%rbp,%rax,2)
ff
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c7 <main+0x67>
lea    -0x3ea0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1f40,%edx
call   1080 <fwrite@plt>
xor    %eax,%eax
add    $0x3ea0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e98,%rsp
cmp    $0x3,%edi
jne    1242 <main+0xe2>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   1040 <atof@plt>
movss  %xmm0,0xc(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe47(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <cos@plt>
movsd  0xe3a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,0x10(%rsp,%rbx,2)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mulss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe09(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <cos@plt>
mulsd  0xe00(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,0x12(%rsp,%rbx,2)
add    $0x2,%rbx
cmp    $0x1f40,%rbx
jne    11a0 <main+0x40>
lea    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1f40,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
xor    %eax,%eax
add    $0x3e98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"usage: mksine outputFile frequencyHz\0A\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca float
%9 = alloca [8000 x i16]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call float @atof(i8* %22)
store float %23, float* %8
store i32 0, i32* %7
br label %24
24: ; preds = %41, %15
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 8000
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = load float, float* %8
%29 = load i32, i32* %7
%30 = sitofp i32 %29 to float
%31 = fmul float %28, %30
%32 = fpext float %31 to double
%33 = fmul double %32, 0x3F49BC65B68848FA
%34 = fptrunc double %33 to float
%35 = call double @cos(float %34)
%36 = fmul double 1.000000e+03, %35
%37 = fptosi double %36 to i16
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [8000 x i16], [8000 x i16]* %9, i64 0, i64 %39
store i16 %37, i16* %40
br label %41
41: ; preds = %27
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %24
44: ; preds = %24
%45 = getelementptr inbounds [8000 x i16], [8000 x i16]* %9, i64 0, i64 0
%46 = load i32*, i32** %6
%47 = call i32 @fwrite(i16* %45, i32 2, i32 8000, i32* %46)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"wb\00"
@str = [37 x i8] c"usage: mksine outputFile frequencyHz\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8000 x i16]
%4 = bitcast [8000 x i16]* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call float @atof(i8* %14)
br label %16
16: ; preds = %16, %9
%17 = phi i64 [ 0, %9 ], [ %39, %16 ]
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to float
%20 = fmul float %15, %19
%21 = fpext float %20 to double
%22 = fmul double %21, 0x3F49BC65B68848FA
%23 = fptrunc double %22 to float
%24 = tail call double @cos(float %23)
%25 = fmul double %24, 1.000000e+03
%26 = fptosi double %25 to i16
%27 = getelementptr inbounds [8000 x i16], [8000 x i16]* %3, i64 0, i64 %17
store i16 %26, i16* %27
%28 = or i64 %17, 1
%29 = trunc i64 %28 to i32
%30 = sitofp i32 %29 to float
%31 = fmul float %15, %30
%32 = fpext float %31 to double
%33 = fmul double %32, 0x3F49BC65B68848FA
%34 = fptrunc double %33 to float
%35 = tail call double @cos(float %34)
%36 = fmul double %35, 1.000000e+03
%37 = fptosi double %36 to i16
%38 = getelementptr inbounds [8000 x i16], [8000 x i16]* %3, i64 0, i64 %28
store i16 %37, i16* %38
%39 = add nuw nsw i64 %17, 2
%40 = icmp eq i64 %39, 8000
br i1 %40, label %41, label %16
41: ; preds = %16
%42 = getelementptr inbounds [8000 x i16], [8000 x i16]* %3, i64 0, i64 0
%43 = call i32 @fwrite(i16* %42, i32 2, i32 8000, i32* %12)
ret i32 0
}