#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 */
scalar_t__ fabs(double);
void COMDIV(double ar, double ai, double br, double bi, double *cr,
            double *ci) {
  double tmp;
  if (fabs(br) > fabs(bi)) {
    tmp = bi / br;
    br = tmp * bi + br;
    *cr = (ar + tmp * ai) / br;
    *ci = (ai - tmp * ar) / br;
  } else {
    tmp = br / bi;
    bi = tmp * br + bi;
    *cr = (tmp * ar + ai) / bi;
    *ci = (tmp * ai - ar) / bi;
  }
}


x86 assembly (clang, -O0):
<COMDIV>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jle    11eb <COMDIV+0xdb>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1275 <COMDIV+0x165>
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<COMDIV>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movsd  %xmm3,(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm0
call   1030 <fabs@plt>
mov    %rax,%rbx
movsd  (%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%rbx
jle    119a <COMDIV+0x8a>
movsd  (%rsp),%xmm4
movapd %xmm4,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0x10(%rsp),%xmm3
addsd  %xmm3,%xmm1
divsd  %xmm4,%xmm1
movsd  %xmm1,(%r15)
mulsd  %xmm3,%xmm0
subsd  %xmm0,%xmm2
divsd  %xmm4,%xmm2
jmp    11e6 <COMDIV+0xd6>
movsd  0x8(%rsp),%xmm4
movapd %xmm4,%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm3
mulsd  %xmm3,%xmm1
movsd  0x18(%rsp),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm4,%xmm1
movsd  %xmm1,(%r15)
mulsd  %xmm2,%xmm0
subsd  %xmm3,%xmm0
divsd  %xmm4,%xmm0
movapd %xmm0,%xmm2
movsd  %xmm2,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @COMDIV(double %0, double %1, double %2, double %3, double* %4, double* %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double* %4, double** %11
store double* %5, double** %12
%14 = load double, double* %9
%15 = call i64 @fabs(double %14)
%16 = load double, double* %10
%17 = call i64 @fabs(double %16)
%18 = icmp sgt i64 %15, %17
br i1 %18, label %19, label %42
19: ; preds = %6
%20 = load double, double* %10
%21 = load double, double* %9
%22 = fdiv double %20, %21
store double %22, double* %13
%23 = load double, double* %13
%24 = load double, double* %10
%25 = load double, double* %9
%26 = call double @llvm.fmuladd.f64(double %23, double %24, double %25)
store double %26, double* %9
%27 = load double, double* %7
%28 = load double, double* %13
%29 = load double, double* %8
%30 = call double @llvm.fmuladd.f64(double %28, double %29, double %27)
%31 = load double, double* %9
%32 = fdiv double %30, %31
%33 = load double*, double** %11
store double %32, double* %33
%34 = load double, double* %8
%35 = load double, double* %13
%36 = load double, double* %7
%37 = fneg double %35
%38 = call double @llvm.fmuladd.f64(double %37, double %36, double %34)
%39 = load double, double* %9
%40 = fdiv double %38, %39
%41 = load double*, double** %12
store double %40, double* %41
br label %65
42: ; preds = %6
%43 = load double, double* %9
%44 = load double, double* %10
%45 = fdiv double %43, %44
store double %45, double* %13
%46 = load double, double* %13
%47 = load double, double* %9
%48 = load double, double* %10
%49 = call double @llvm.fmuladd.f64(double %46, double %47, double %48)
store double %49, double* %10
%50 = load double, double* %13
%51 = load double, double* %7
%52 = load double, double* %8
%53 = call double @llvm.fmuladd.f64(double %50, double %51, double %52)
%54 = load double, double* %10
%55 = fdiv double %53, %54
%56 = load double*, double** %11
store double %55, double* %56
%57 = load double, double* %13
%58 = load double, double* %8
%59 = load double, double* %7
%60 = fneg double %59
%61 = call double @llvm.fmuladd.f64(double %57, double %58, double %60)
%62 = load double, double* %10
%63 = fdiv double %61, %62
%64 = load double*, double** %12
store double %63, double* %64
br label %65
65: ; preds = %42, %19
ret void
}

LLVM IR (-O2):
define void @COMDIV(double %0, double %1, double %2, double %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = tail call i64 @fabs(double %2)
%8 = tail call i64 @fabs(double %3)
%9 = icmp sgt i64 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = fdiv double %3, %2
%12 = tail call double @llvm.fmuladd.f64(double %11, double %3, double %2)
%13 = tail call double @llvm.fmuladd.f64(double %11, double %1, double %0)
%14 = fdiv double %13, %12
store double %14, double* %4
%15 = fneg double %11
%16 = tail call double @llvm.fmuladd.f64(double %15, double %0, double %1)
%17 = fdiv double %16, %12
br label %26
18: ; preds = %6
%19 = fdiv double %2, %3
%20 = tail call double @llvm.fmuladd.f64(double %19, double %2, double %3)
%21 = tail call double @llvm.fmuladd.f64(double %19, double %0, double %1)
%22 = fdiv double %21, %20
store double %22, double* %4
%23 = fneg double %0
%24 = tail call double @llvm.fmuladd.f64(double %19, double %1, double %23)
%25 = fdiv double %24, %20
br label %26
26: ; preds = %18, %10
%27 = phi double [ %25, %18 ], [ %17, %10 ]
store double %27, double* %5
ret void
}