#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 */
float exp(float);
void ricker_wavelet(float *source, int nsteps, float dt, float freq) {
  float shift = -1.5594f / freq;
  for (int i = 0; i < nsteps; i++) {
    float time = i * dt + shift;
    float pi_freq_t = 3.141517f * freq * time;
    float sqr_pi_freq_t = pi_freq_t * pi_freq_t;
    source[i] = 1e5f * (1.f - 2 * sqr_pi_freq_t) * exp(-sqr_pi_freq_t);
  }
}


x86 assembly (clang, -O0):
<ricker_wavelet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  %xmm0,-0x10(%rbp)
movss  %xmm1,-0x14(%rbp)
movss  0xecf(%rip),%xmm0
divss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f4 <ricker_wavelet+0xe4>
cvtsi2ssl -0x1c(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xe9a(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
addss  %xmm0,%xmm0
movss  0xe67(%rip),%xmm1
subss  %xmm0,%xmm1
movss  0xe57(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x28(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1142 <ricker_wavelet+0x32>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ricker_wavelet>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11c2 <ricker_wavelet+0xb2>
movaps %xmm0,%xmm2
mov    %rdi,%r14
movss  0xed1(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rsp)
mulss  0xec4(%rip),%xmm1
movss  %xmm1,0x8(%rsp)
mov    %esi,%r15d
xor    %ebx,%ebx
movss  %xmm2,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm2,%xmm0
addss  (%rsp),%xmm0
mulss  0x8(%rsp),%xmm0
mulss  %xmm0,%xmm0
movaps %xmm0,%xmm1
addss  %xmm0,%xmm1
movss  0xe7f(%rip),%xmm2
subss  %xmm1,%xmm2
mulss  0xe77(%rip),%xmm2
movss  %xmm2,0xc(%rsp)
xorps  0xe6e(%rip),%xmm0
call   1030 <exp@plt>
movss  0x4(%rsp),%xmm2
mulss  0xc(%rsp),%xmm0
movss  %xmm0,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <ricker_wavelet+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @ricker_wavelet(float* %0, i32 %1, float %2, float %3) {
%5 = alloca float*
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca float
%12 = alloca float
%13 = alloca float
store float* %0, float** %5
store i32 %1, i32* %6
store float %2, float* %7
store float %3, float* %8
%14 = load float, float* %8
%15 = fdiv float 0xBFF8F34D60000000, %14
store float %15, float* %9
store i32 0, i32* %10
br label %16
16: ; preds = %44, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load i32, i32* %10
%22 = sitofp i32 %21 to float
%23 = load float, float* %7
%24 = load float, float* %9
%25 = call float @llvm.fmuladd.f32(float %22, float %23, float %24)
store float %25, float* %11
%26 = load float, float* %8
%27 = fmul float 0x400921D3A0000000, %26
%28 = load float, float* %11
%29 = fmul float %27, %28
store float %29, float* %12
%30 = load float, float* %12
%31 = load float, float* %12
%32 = fmul float %30, %31
store float %32, float* %13
%33 = load float, float* %13
%34 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %33, float 1.000000e+00)
%35 = fmul float 1.000000e+05, %34
%36 = load float, float* %13
%37 = fneg float %36
%38 = call float @exp(float %37)
%39 = fmul float %35, %38
%40 = load float*, float** %5
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds float, float* %40, i64 %42
store float %39, float* %43
br label %44
44: ; preds = %20
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %16
47: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @ricker_wavelet(float* nocapture writeonly %0, i32 %1, float %2, float %3) {
%5 = fdiv float 0xBFF8F34D60000000, %3
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = fmul float %3, 0x400921D3A0000000
%9 = zext i32 %1 to i64
br label %11
10: ; preds = %11, %4
ret void
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %24, %11 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to float
%15 = tail call float @llvm.fmuladd.f32(float %14, float %2, float %5)
%16 = fmul float %8, %15
%17 = fmul float %16, %16
%18 = tail call float @llvm.fmuladd.f32(float %17, float -2.000000e+00, float 1.000000e+00)
%19 = fmul float %18, 1.000000e+05
%20 = fneg float %17
%21 = tail call float @exp(float %20)
%22 = fmul float %19, %21
%23 = getelementptr inbounds float, float* %0, i64 %12
store float %22, float* %23
%24 = add nuw nsw i64 %12, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %10, label %11
}