#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 calculate_shift(float *, float *, float *, float *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
float randf();
void test_shift(int shift) {
  int i, n = 512;
  float *re = (float *)malloc(sizeof(*re) * n * 2);
  float *im = (float *)malloc(sizeof(*im) * n * 2);
  float *re_shifted = (float *)malloc(sizeof(*re) * n * 2);
  float *im_shifted = (float *)malloc(sizeof(*im) * n * 2);
  for (i = 0; i < n; i++) {
    re[i] = randf();
    im[i] = 0.0f;
    re[i + n] = 0.0f;
    im[i + n] = 0.0f;
  }
  for (i = 0; i < n; i++) {
    int j = (i - shift + n) % n;
    re_shifted[i] = re[j];
    im_shifted[i] = im[j];
    re_shifted[i + n] = 0.0f;
    im_shifted[i + n] = 0.0f;
  }
  int calculated_shift = calculate_shift(re, im, re_shifted, im_shifted, n * 2);
  if (shift != calculated_shift) {
    printf("ERROR: Expected shift %i, but got %i\n", shift, calculated_shift);
    exit(-1);
  }
  free(re);
  free(im);
  free(re_shifted);
  free(im_shifted);
}


x86 assembly (clang, -O0):
<test_shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x200,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123d <test_shift+0xdd>
mov    $0x0,%al
call   1070 <randf@plt>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d5 <test_shift+0x75>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12cc <test_shift+0x16c>
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1244 <test_shift+0xe4>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0xc(%rbp),%r8d
shl    $0x1,%r8d
call   1050 <calculate_shift@plt>
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     1314 <test_shift+0x1b4>
mov    -0x4(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    0xcfb(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_shift>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x200,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <randf@plt>
movss  %xmm0,-0x800(%r13,%rbx,4)
f8 ff ff
movl   $0x0,-0x800(%rbp,%rbx,4)
movl   $0x0,0x0(%r13,%rbx,4)
movl   $0x0,0x0(%rbp,%rbx,4)
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    11b0 <test_shift+0x50>
mov    %r14d,%eax
neg    %eax
mov    $0x200,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edx
add    %ecx,%edx
lea    0x1ff(%rax,%rcx,1),%esi
cmovns %edx,%esi
and    $0xfffffe00,%esi
sub    %esi,%edx
movslq %edx,%rdx
movss  0x0(%r13,%rdx,4),%xmm0
movss  %xmm0,-0x800(%r15,%rcx,4)
f8 ff ff
movss  0x0(%rbp,%rdx,4),%xmm0
movss  %xmm0,-0x800(%r12,%rcx,4)
f8 ff ff
movl   $0x0,(%r15,%rcx,4)
movl   $0x0,(%r12,%rcx,4)
add    $0x1,%rcx
cmp    $0x400,%rcx
jne    1200 <test_shift+0xa0>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0x400,%r8d
call   1050 <calculate_shift@plt>
cmp    %r14d,%eax
jne    12a1 <test_shift+0x141>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xd58(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"ERROR: Expected shift %i, but got %i\0A\00"
define void @test_shift(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float*
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %2
store i32 512, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 4, %12
%14 = mul i64 %13, 2
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to float*
store float* %17, float** %5
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = mul i64 4, %19
%21 = mul i64 %20, 2
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to float*
store float* %24, float** %6
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = mul i64 4, %26
%28 = mul i64 %27, 2
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to float*
store float* %31, float** %7
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = mul i64 4, %33
%35 = mul i64 %34, 2
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to float*
store float* %38, float** %8
store i32 0, i32* %3
br label %39
39: ; preds = %65, %1
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %68
43: ; preds = %39
%44 = call float (...) @randf()
%45 = load float*, float** %5
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %45, i64 %47
store float %44, float* %48
%49 = load float*, float** %6
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float, float* %49, i64 %51
store float 0.000000e+00, float* %52
%53 = load float*, float** %5
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = add nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds float, float* %53, i64 %57
store float 0.000000e+00, float* %58
%59 = load float*, float** %6
%60 = load i32, i32* %3
%61 = load i32, i32* %4
%62 = add nsw i32 %60, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds float, float* %59, i64 %63
store float 0.000000e+00, float* %64
br label %65
65: ; preds = %43
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
br label %39
68: ; preds = %39
store i32 0, i32* %3
br label %69
69: ; preds = %111, %68
%70 = load i32, i32* %3
%71 = load i32, i32* %4
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %114
73: ; preds = %69
%74 = load i32, i32* %3
%75 = load i32, i32* %2
%76 = sub nsw i32 %74, %75
%77 = load i32, i32* %4
%78 = add nsw i32 %76, %77
%79 = load i32, i32* %4
%80 = srem i32 %78, %79
store i32 %80, i32* %9
%81 = load float*, float** %5
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds float, float* %81, i64 %83
%85 = load float, float* %84
%86 = load float*, float** %7
%87 = load i32, i32* %3
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds float, float* %86, i64 %88
store float %85, float* %89
%90 = load float*, float** %6
%91 = load i32, i32* %9
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds float, float* %90, i64 %92
%94 = load float, float* %93
%95 = load float*, float** %8
%96 = load i32, i32* %3
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds float, float* %95, i64 %97
store float %94, float* %98
%99 = load float*, float** %7
%100 = load i32, i32* %3
%101 = load i32, i32* %4
%102 = add nsw i32 %100, %101
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds float, float* %99, i64 %103
store float 0.000000e+00, float* %104
%105 = load float*, float** %8
%106 = load i32, i32* %3
%107 = load i32, i32* %4
%108 = add nsw i32 %106, %107
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds float, float* %105, i64 %109
store float 0.000000e+00, float* %110
br label %111
111: ; preds = %73
%112 = load i32, i32* %3
%113 = add nsw i32 %112, 1
store i32 %113, i32* %3
br label %69
114: ; preds = %69
%115 = load float*, float** %5
%116 = load float*, float** %6
%117 = load float*, float** %7
%118 = load float*, float** %8
%119 = load i32, i32* %4
%120 = mul nsw i32 %119, 2
%121 = call i32 @calculate_shift(float* %115, float* %116, float* %117, float* %118, i32 %120)
store i32 %121, i32* %10
%122 = load i32, i32* %2
%123 = load i32, i32* %10
%124 = icmp ne i32 %122, %123
br i1 %124, label %125, label %130
125: ; preds = %114
%126 = load i32, i32* %2
%127 = load i32, i32* %10
%128 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %126, i32 %127)
%129 = call i32 @exit(i32 -1)
unreachable
130: ; preds = %114
%131 = load float*, float** %5
%132 = call i32 @free(float* %131)
%133 = load float*, float** %6
%134 = call i32 @free(float* %133)
%135 = load float*, float** %7
%136 = call i32 @free(float* %135)
%137 = load float*, float** %8
%138 = call i32 @free(float* %137)
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"ERROR: Expected shift %i, but got %i\0A\00"
define void @test_shift(i32 %0) {
%2 = tail call i64 @malloc(i32 4096)
%3 = inttoptr i64 %2 to float*
%4 = tail call i64 @malloc(i32 4096)
%5 = inttoptr i64 %4 to float*
%6 = tail call i64 @malloc(i32 4096)
%7 = tail call i64 @malloc(i32 4096)
br label %12
8: ; preds = %12
%9 = inttoptr i64 %6 to float*
%10 = inttoptr i64 %7 to float*
%11 = sub i32 512, %0
br label %22
12: ; preds = %1, %12
%13 = phi i64 [ 0, %1 ], [ %20, %12 ]
%14 = tail call float (...) @randf()
%15 = getelementptr inbounds float, float* %3, i64 %13
store float %14, float* %15
%16 = getelementptr inbounds float, float* %5, i64 %13
store float 0.000000e+00, float* %16
%17 = add nuw nsw i64 %13, 512
%18 = getelementptr inbounds float, float* %3, i64 %17
store float 0.000000e+00, float* %18
%19 = getelementptr inbounds float, float* %5, i64 %17
store float 0.000000e+00, float* %19
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, 512
br i1 %21, label %8, label %12
22: ; preds = %8, %22
%23 = phi i64 [ 0, %8 ], [ %37, %22 ]
%24 = trunc i64 %23 to i32
%25 = add i32 %11, %24
%26 = srem i32 %25, 512
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float, float* %3, i64 %27
%29 = load float, float* %28
%30 = getelementptr inbounds float, float* %9, i64 %23
store float %29, float* %30
%31 = getelementptr inbounds float, float* %5, i64 %27
%32 = load float, float* %31
%33 = getelementptr inbounds float, float* %10, i64 %23
store float %32, float* %33
%34 = add nuw nsw i64 %23, 512
%35 = getelementptr inbounds float, float* %9, i64 %34
store float 0.000000e+00, float* %35
%36 = getelementptr inbounds float, float* %10, i64 %34
store float 0.000000e+00, float* %36
%37 = add nuw nsw i64 %23, 1
%38 = icmp eq i64 %37, 512
br i1 %38, label %39, label %22
39: ; preds = %22
%40 = tail call i32 @calculate_shift(float* %3, float* %5, float* %9, float* %10, i32 1024)
%41 = icmp eq i32 %40, %0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %40)
%44 = tail call i32 @exit(i32 -1)
unreachable
45: ; preds = %39
%46 = tail call i32 @free(float* %3)
%47 = tail call i32 @free(float* %5)
%48 = tail call i32 @free(float* %9)
%49 = tail call i32 @free(float* %10)
ret void
}