#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 int_pow(int, int);
scalar_t__ malloc(int);
scalar_t__ power_two(int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ zero_padding(double *, double *, int, int);
int main(int argc, char *argv[]) {
  int len = 24, pad_len = 0;
  int pow;
  double *sig = NULL, *pad = NULL;
  int i = 0;
  sig = (double *)malloc(len * sizeof(double));
  if (power_two(len, &pow)) {
    pow++;
  }
  pad_len = int_pow(2, pow);
  printf("pad_len = %i\n", pad_len);
  pad = (double *)malloc(int_pow(2, pow) * sizeof(double));
  for (i = 0; i < len; i++) {
    sig[i] = 1;
  }
  zero_padding(sig, pad, len, pad_len);
  printf("sig pad = \n");
  for (i = 0; i < pad_len; i++) {
    printf("%f ", pad[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x18,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <power_two@plt>
cmp    $0x0,%rax
je     11bd <main+0x6d>
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    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    $0x2,%edi
call   1040 <int_pow@plt>
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1232 <main+0xe2>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  0xde1(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1203 <main+0xb3>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <zero_padding@plt>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    128f <main+0x13f>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xda8(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    125a <main+0x10a>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xc0,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%rsi
mov    $0x18,%edi
call   1030 <power_two@plt>
mov    0x4(%rsp),%esi
test   %rax,%rax
je     11a3 <main+0x33>
add    $0x1,%esi
mov    %esi,0x4(%rsp)
mov    $0x2,%edi
call   1060 <int_pow@plt>
mov    %eax,%r14d
lea    0xe59(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%esi
mov    $0x2,%edi
call   1060 <int_pow@plt>
lea    0x0(,%rax,8),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
movaps 0xe1c(%rip),%xmm0
movups %xmm0,(%rbx)
movups %xmm0,0x10(%rbx)
movups %xmm0,0x20(%rbx)
movups %xmm0,0x30(%rbx)
movups %xmm0,0x40(%rbx)
movups %xmm0,0x50(%rbx)
movups %xmm0,0x60(%rbx)
movups %xmm0,0x70(%rbx)
movups %xmm0,0x80(%rbx)
movups %xmm0,0x90(%rbx)
movups %xmm0,0xa0(%rbx)
movups %xmm0,0xb0(%rbx)
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x18,%edx
mov    %r14d,%ecx
call   1080 <zero_padding@plt>
lea    0xde9(%rip),%rdi
call   1050 <puts@plt>
test   %r14d,%r14d
jle    1269 <main+0xf9>
mov    %r14d,%ebx
xor    %ebp,%ebp
lea    0xdcf(%rip),%r14
nop
movsd  (%r15,%rbp,8),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1250 <main+0xe0>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"pad_len = %i\0A\00"
@.str.1 = [12 x i8] c"sig pad = \0A\00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [2 x i8] c"\0A\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 24, i32* %6
store i32 0, i32* %7
store double* null, double** %9
store double* null, double** %10
store i32 0, i32* %11
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
store double* %17, double** %9
%18 = load i32, i32* %6
%19 = call i64 @power_two(i32 %18, i32* %8)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %24
24: ; preds = %21, %2
%25 = load i32, i32* %8
%26 = call i32 @int_pow(i32 2, i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %8
%30 = call i32 @int_pow(i32 2, i32 %29)
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to double*
store double* %35, double** %10
store i32 0, i32* %11
br label %36
36: ; preds = %45, %24
%37 = load i32, i32* %11
%38 = load i32, i32* %6
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = load double*, double** %9
%42 = load i32, i32* %11
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double 1.000000e+00, double* %44
br label %45
45: ; preds = %40
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
br label %36
48: ; preds = %36
%49 = load double*, double** %9
%50 = load double*, double** %10
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = call i32 @zero_padding(double* %49, double* %50, i32 %51, i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %11
br label %55
55: ; preds = %66, %48
%56 = load i32, i32* %11
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %69
59: ; preds = %55
%60 = load double*, double** %10
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %64)
br label %66
66: ; preds = %59
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %55
69: ; preds = %55
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 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.2 = [4 x i8] c"%f \00"
@str = [11 x i8] c"sig pad = \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 192)
%6 = inttoptr i64 %5 to double*
%7 = call i64 @power_two(i32 24, 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @int_pow(i32 2, i32 %16)
%18 = shl i32 %17, 3
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %5 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %20
%21 = getelementptr inbounds double, double* %6, i64 2
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %22
%23 = getelementptr inbounds double, double* %6, i64 4
%24 = bitcast double* %23 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %24
%25 = getelementptr inbounds double, double* %6, i64 6
%26 = bitcast double* %25 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %26
%27 = getelementptr inbounds double, double* %6, i64 8
%28 = bitcast double* %27 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %28
%29 = getelementptr inbounds double, double* %6, i64 10
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %30
%31 = getelementptr inbounds double, double* %6, i64 12
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %32
%33 = getelementptr inbounds double, double* %6, i64 14
%34 = bitcast double* %33 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %34
%35 = getelementptr inbounds double, double* %6, i64 16
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %36
%37 = getelementptr inbounds double, double* %6, i64 18
%38 = bitcast double* %37 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %38
%39 = getelementptr inbounds double, double* %6, i64 20
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %40
%41 = getelementptr inbounds double, double* %6, i64 22
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %42
%43 = inttoptr i64 %19 to double*
%44 = call i32 @zero_padding(double* %6, double* %43, i32 24, i32 %14)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%46 = icmp sgt i32 %14, 0
br i1 %46, label %47, label %56
47: ; preds = %12
%48 = zext i32 %14 to i64
br label %49
49: ; preds = %47, %49
%50 = phi i64 [ 0, %47 ], [ %54, %49 ]
%51 = getelementptr inbounds double, double* %43, i64 %50
%52 = load double, double* %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %52)
%54 = add nuw nsw i64 %50, 1
%55 = icmp eq i64 %54, %48
br i1 %55, label %56, label %49
56: ; preds = %49, %12
%57 = call i32 @putchar(i32 10)
ret i32 0
}