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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gen_noise(int *, int, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  int16_t noise[1024];
  int i;
  FILE *f = NULL;
  (void)gen_noise(noise, 1024, 8000, 100, -40);
  for (i = 0; i < 80; i++) {
    printf("%d, ", noise[i]);
    if ((i + 1) % 8 == 0)
      printf("\n");
  }
  f = fopen("/Users/tkorays/Code2017/SpeechSignalProcessing/tools/wave_tools/"
            "noise.pcm",
            "wb");
  fwrite(noise, sizeof(int16_t), 100 * 8, f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x1020(%rbp)
lea    -0x1010(%rbp),%rdi
mov    $0x400,%esi
mov    $0x1f40,%edx
mov    $0x64,%ecx
mov    $0xffffffd8,%r8d
call   1050 <gen_noise@plt>
movl   $0x0,-0x1014(%rbp)
cmpl   $0x50,-0x1014(%rbp)
jge    1209 <main+0xb9>
movslq -0x1014(%rbp),%rax
mov    -0x1010(%rbp,%rax,4),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11f0 <main+0xa0>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f5 <main+0xa5>
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    119f <main+0x4f>
lea    0xdf7(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1020(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1020(%rbp),%rcx
mov    $0x4,%esi
mov    $0x320,%edx
call   1070 <fwrite@plt>
mov    -0x1020(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
mov    $0x1f40,%edx
mov    $0x64,%ecx
mov    $0xffffffd8,%r8d
call   1060 <gen_noise@plt>
mov    $0x1,%ebx
lea    0xe6d(%rip),%r14
jmp    11aa <main+0x4a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    $0x51,%rbx
je     11c9 <main+0x69>
mov    -0x4(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x7,%bl
jne    11a0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x40>
lea    0xe35(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x320,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d, \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [74 x i8] c"/Users/tkorays/Code2017/SpeechSignalProcessing/tools/wave_tools/noise.pcm\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i32]
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %8
%9 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%10 = call i32 @gen_noise(i32* %9, i32 1024, i32 8000, i32 100, i32 -40)
store i32 0, i32* %7
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 80
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
%22 = srem i32 %21, 8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %11
30: ; preds = %11
%31 = call i32* @fopen(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %8
%32 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%33 = load i32*, i32** %8
%34 = call i32 @fwrite(i32* %32, i32 4, i32 800, i32* %33)
%35 = load i32*, i32** %8
%36 = call i32 @fclose(i32* %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d, \00"
@.str.2 = [74 x i8] c"/Users/tkorays/Code2017/SpeechSignalProcessing/tools/wave_tools/noise.pcm\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i32]
%4 = bitcast [1024 x i32]* %3 to i8*
%5 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
%6 = call i32 @gen_noise(i32* %5, i32 1024, i32 8000, i32 100, i32 -40)
br label %7
7: ; preds = %2, %17
%8 = phi i64 [ 0, %2 ], [ %12, %17 ]
%9 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = add nuw nsw i64 %8, 1
%13 = and i64 %12, 7
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 @putchar(i32 10)
br label %17
17: ; preds = %7, %15
%18 = icmp eq i64 %12, 80
br i1 %18, label %19, label %7
19: ; preds = %17
%20 = call i32* @fopen(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @fwrite(i32* %5, i32 4, i32 800, i32* %20)
%22 = call i32 @fclose(i32* %20)
ret i32 0
}