#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 float complex;

/* Variables and functions */
float I;
double cimag(float);
double creal(float);
complex cmplx_square(complex z) {
  float real = creal(z) * creal(z) - cimag(z) * cimag(z);
  float imag = 2.0 * creal(z) * cimag(z);
  return real + I * imag;
}


x86 assembly (clang, -O0):
<cmplx_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <creal@plt>
movsd  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <creal@plt>
movsd  %xmm0,-0x28(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <cimag@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <cimag@plt>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <creal@plt>
movaps %xmm0,%xmm1
movsd  0xe49(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <cimag@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm1
mov    0x2dfd(%rip),%rax
movss  (%rax),%xmm0
movss  -0xc(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmplx_square>:
sub    $0x28,%rsp
movss  %xmm0,0xc(%rsp)
call   1030 <creal@plt>
movsd  %xmm0,0x18(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <creal@plt>
movsd  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cimag@plt>
movsd  %xmm0,0x20(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cimag@plt>
mulsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x18(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <creal@plt>
addsd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cimag@plt>
mulsd  0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    0x2e32(%rip),%rax
mulss  (%rax),%xmm0
addss  0x18(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@I = global float 0.000000e+00
define float @cmplx_square(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float %0, float* %2
%5 = load float, float* %2
%6 = call double @creal(float %5)
%7 = load float, float* %2
%8 = call double @creal(float %7)
%9 = load float, float* %2
%10 = call double @cimag(float %9)
%11 = load float, float* %2
%12 = call double @cimag(float %11)
%13 = fmul double %10, %12
%14 = fneg double %13
%15 = call double @llvm.fmuladd.f64(double %6, double %8, double %14)
%16 = fptrunc double %15 to float
store float %16, float* %3
%17 = load float, float* %2
%18 = call double @creal(float %17)
%19 = fmul double 2.000000e+00, %18
%20 = load float, float* %2
%21 = call double @cimag(float %20)
%22 = fmul double %19, %21
%23 = fptrunc double %22 to float
store float %23, float* %4
%24 = load float, float* %3
%25 = load float, float* @I
%26 = load float, float* %4
%27 = call float @llvm.fmuladd.f32(float %25, float %26, float %24)
ret float %27
}

LLVM IR (-O2):
@I = global float 0.000000e+00
define float @cmplx_square(float %0) {
%2 = tail call double @creal(float %0)
%3 = tail call double @creal(float %0)
%4 = tail call double @cimag(float %0)
%5 = tail call double @cimag(float %0)
%6 = fneg double %4
%7 = fmul double %5, %6
%8 = tail call double @llvm.fmuladd.f64(double %2, double %3, double %7)
%9 = fptrunc double %8 to float
%10 = tail call double @creal(float %0)
%11 = fmul double %10, 2.000000e+00
%12 = tail call double @cimag(float %0)
%13 = fmul double %11, %12
%14 = fptrunc double %13 to float
%15 = load float, float* @I
%16 = tail call float @llvm.fmuladd.f32(float %15, float %14, float %9)
ret float %16
}