#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*/ envelope(double *, double *, int, double, double, double,
                            int /*<<< orphan*/);
int int_pow(int, int);
int /*<<< orphan*/ load_line(double *, int, char *);
scalar_t__ malloc(int);
scalar_t__ power_two(int, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ write_file(double *, int, char *);
int /*<<< orphan*/ zero_padding(double *, double *, int, int, int);
int main(int argc, char *argv[]) {
  int len = 8445, pad_len = 0;
  int powd;
  double *sig = NULL, *pad = NULL, *env = NULL;
  int i = 0;
  sig = (double *)malloc(len * sizeof(double));
  if (power_two(len, &powd)) {
    powd++;
  }
  pad_len = int_pow(2, powd);
  printf("pad_len = %i\n", pad_len);
  pad = (double *)malloc(pad_len * sizeof(double));
  env = (double *)malloc(pad_len * sizeof(double));
  double f = 125000000.0;
  load_line(sig, len, "line.txt");
  zero_padding(sig, pad, len, pad_len, 1);
  write_file(pad, pad_len, "zero_pad.txt");
  envelope(pad, env, pad_len, f, 500000.0, 5500000.0, 0);
  write_file(env, pad_len, "env.txt");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x20fd,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <power_two@plt>
cmp    $0x0,%rax
je     11f5 <main+0x75>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x2,%edi
call   1040 <int_pow@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movsd  0xdce(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdd1(%rip),%rdx
call   10a0 <load_line@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    $0x1,%r8d
call   1070 <zero_padding@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    0xdae(%rip),%rdx
call   1060 <write_file@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
movsd  -0x48(%rbp),%xmm0
movsd  0xd62(%rip),%xmm1
movsd  0xd62(%rip),%xmm2
xor    %ecx,%ecx
call   1090 <envelope@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    0xd81(%rip),%rdx
call   1060 <write_file@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x107e8,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rsi
mov    $0x20fd,%edi
call   1030 <power_two@plt>
mov    0xc(%rsp),%esi
test   %rax,%rax
je     11b8 <main+0x38>
add    $0x1,%esi
mov    %esi,0xc(%rsp)
mov    $0x2,%edi
call   1040 <int_pow@plt>
mov    %eax,%ebx
lea    0xe4d(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
lea    0x0(,%rbx,8),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe32(%rip),%rdx
mov    %r14,%rdi
mov    $0x20fd,%esi
call   10a0 <load_line@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x20fd,%edx
mov    %ebx,%ecx
mov    $0x1,%r8d
call   1070 <zero_padding@plt>
lea    0xe0f(%rip),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <write_file@plt>
movsd  0xdce(%rip),%xmm0
movsd  0xdce(%rip),%xmm1
movsd  0xdce(%rip),%xmm2
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1090 <envelope@plt>
lea    0xde4(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
call   1060 <write_file@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"pad_len = %i\0A\00"
@.str.1 = [9 x i8] c"line.txt\00"
@.str.2 = [13 x i8] c"zero_pad.txt\00"
@.str.3 = [8 x i8] c"env.txt\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 i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8445, i32* %6
store i32 0, i32* %7
store double* null, double** %9
store double* null, double** %10
store double* null, double** %11
store i32 0, i32* %12
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %9
%20 = load i32, i32* %6
%21 = call i64 @power_two(i32 %20, i32* %8)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %26
26: ; preds = %23, %2
%27 = load i32, i32* %8
%28 = call i32 @int_pow(i32 2, i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 8
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to double*
store double* %36, double** %10
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 8
%40 = trunc i64 %39 to i32
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to double*
store double* %42, double** %11
store double 1.250000e+08, double* %13
%43 = load double*, double** %9
%44 = load i32, i32* %6
%45 = call i32 @load_line(double* %43, i32 %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%46 = load double*, double** %9
%47 = load double*, double** %10
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = call i32 @zero_padding(double* %46, double* %47, i32 %48, i32 %49, i32 1)
%51 = load double*, double** %10
%52 = load i32, i32* %7
%53 = call i32 @write_file(double* %51, i32 %52, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%54 = load double*, double** %10
%55 = load double*, double** %11
%56 = load i32, i32* %7
%57 = load double, double* %13
%58 = call i32 @envelope(double* %54, double* %55, i32 %56, double %57, double 5.000000e+05, double 5.500000e+06, i32 0)
%59 = load double*, double** %11
%60 = load i32, i32* %7
%61 = call i32 @write_file(double* %59, i32 %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"pad_len = %i\0A\00"
@.str.1 = [9 x i8] c"line.txt\00"
@.str.2 = [13 x i8] c"zero_pad.txt\00"
@.str.3 = [8 x i8] c"env.txt\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @malloc(i32 67560)
%6 = inttoptr i64 %5 to double*
%7 = call i64 @power_two(i32 8445, i32* %3)
%8 = icmp eq i64 %7, 0
%9 = load i32, i32* %3
br i1 %8, label %12, label %10
10: ; preds = %2
%11 = add nsw i32 %9, 1
store i32 %11, i32* %3
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ %11, %10 ], [ %9, %2 ]
%14 = call i32 @int_pow(i32 2, i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = shl i32 %14, 3
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
%19 = call i64 @malloc(i32 %16)
%20 = inttoptr i64 %19 to double*
%21 = call i32 @load_line(double* %6, i32 8445, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @zero_padding(double* %6, double* %18, i32 8445, i32 %14, i32 1)
%23 = call i32 @write_file(double* %18, i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @envelope(double* %18, double* %20, i32 %14, double 1.250000e+08, double 5.000000e+05, double 5.500000e+06, i32 0)
%25 = call i32 @write_file(double* %20, i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}