#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 */
double fabs(double);
int /*<<< orphan*/ printf(char *, double, double);
double calc_L1(double Q) {
  double x = 0.0;
  double M1 = 1.0 / (1 + Q);
  double M2 = Q / (1 + Q);
  double a1 = Q / (1 + Q);
  double a2 = 1.0 / (1 + Q);
  double xa = -a2;
  double xb = a1;
  double dx = 10.0;
  double f, df;
  int i = 0;
  while (fabs(dx) > 1.0e-12 && i < 100) {
    double d1 = x - a1;
    double d2 = x + a2;
    f = M1 / (d1 * d1) - M2 / (d2 * d2) + x;
    df = -2 * M1 / (d1 * d1 * d1) + 2 * M2 / (d2 * d2 * d2) + 1;
    if (f > 0.0)
      xb = x;
    if (f < 0.0)
      xa = x;
    dx = -f / df;
    if (x + dx <= xa || x + dx >= xb) {
      dx = 0.5 * (xa + xb) - x;
      x = 0.5 * (xa + xb);
    } else
      x += dx;
    i += 1;
  }
  printf("From M2: CM=%.6lf L1=%.6lf\n", a2, a2 + x);
  return x;
}


x86 assembly (clang, -O0):
<calc_L1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed8(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
movsd  0xecb(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb5(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe84(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
movsd  0xe77(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe33(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x5c(%rbp)
movsd  -0x48(%rbp),%xmm0
movaps 0xe4b(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
movsd  0xe1d(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x71(%rbp)
jbe    120a <calc_L1+0xfa>
cmpl   $0x64,-0x5c(%rbp)
setl   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    121a <calc_L1+0x10a>
jmp    13c1 <calc_L1+0x2b1>
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
mulsd  -0x70(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdac(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd84(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
mulsd  -0x70(%rbp),%xmm2
mulsd  -0x70(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  0xd50(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12dd <calc_L1+0x1cd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    12f5 <calc_L1+0x1e5>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm1
addsd  -0x48(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jae    1349 <calc_L1+0x239>
movsd  -0x10(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     13a4 <calc_L1+0x294>
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xcb1(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  0xc92(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    13b3 <calc_L1+0x2a3>
movsd  -0x48(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11d9 <calc_L1+0xc9>
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
addsd  -0x10(%rbp),%xmm1
lea    0xc69(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_L1>:
sub    $0x28,%rsp
movapd %xmm0,%xmm15
movsd  0xedf(%rip),%xmm1
addsd  %xmm0,%xmm1
shufpd $0x2,0xef1(%rip),%xmm15
unpcklpd %xmm1,%xmm1
divpd  %xmm1,%xmm15
movapd %xmm15,%xmm2
unpckhpd %xmm15,%xmm2
movapd %xmm2,0x10(%rsp)
xorpd  0xee0(%rip),%xmm2
movapd %xmm15,%xmm8
addpd  %xmm15,%xmm8
movapd %xmm15,%xmm3
shufpd $0x1,%xmm15,%xmm3
xor    %eax,%eax
xorpd  %xmm10,%xmm10
movsd  0xe8b(%rip),%xmm11
movapd 0xeb2(%rip),%xmm12
movapd 0xeb9(%rip),%xmm13
movsd  0xe80(%rip),%xmm14
xorpd  %xmm4,%xmm4
movapd %xmm15,%xmm5
movapd %xmm4,%xmm9
xchg   %ax,%ax
unpcklpd %xmm4,%xmm1
movapd %xmm4,%xmm7
addpd  %xmm3,%xmm7
subpd  %xmm3,%xmm1
movsd  %xmm7,%xmm1
movapd %xmm1,%xmm6
mulpd  %xmm1,%xmm6
movapd %xmm15,%xmm0
divpd  %xmm6,%xmm0
movapd %xmm0,%xmm7
unpckhpd %xmm0,%xmm7
subsd  %xmm0,%xmm7
addsd  %xmm4,%xmm7
mulpd  %xmm1,%xmm6
movapd %xmm8,%xmm0
divpd  %xmm6,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subsd  %xmm1,%xmm0
addsd  %xmm11,%xmm0
xorpd  %xmm6,%xmm6
cmpltsd %xmm7,%xmm6
movapd %xmm6,%xmm1
andpd  %xmm4,%xmm1
andnpd %xmm5,%xmm6
orpd   %xmm1,%xmm6
movapd %xmm7,%xmm5
cmpltsd %xmm10,%xmm5
movapd %xmm5,%xmm1
andpd  %xmm4,%xmm1
andnpd %xmm2,%xmm5
orpd   %xmm1,%xmm5
xorpd  %xmm12,%xmm7
divsd  %xmm0,%xmm7
addsd  %xmm7,%xmm9
ucomisd %xmm9,%xmm5
jae    1242 <calc_L1+0x132>
ucomisd %xmm6,%xmm9
jb     125e <calc_L1+0x14e>
movapd %xmm5,%xmm9
addsd  %xmm6,%xmm9
mulsd  0xdb3(%rip),%xmm9
movapd %xmm9,%xmm7
subsd  %xmm4,%xmm7
andpd  %xmm13,%xmm7
ucomisd %xmm14,%xmm7
jbe    1285 <calc_L1+0x175>
lea    0x1(%rax),%ecx
movapd %xmm9,%xmm4
movapd %xmm5,%xmm2
movapd %xmm6,%xmm5
cmp    $0x63,%eax
mov    %ecx,%eax
jb     11a0 <calc_L1+0x90>
movapd %xmm9,(%rsp)
movapd 0x10(%rsp),%xmm0
movapd %xmm0,%xmm1
addsd  %xmm9,%xmm1
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
movaps (%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"From M2: CM=%.6lf L1=%.6lf\0A\00"
define double @calc_L1(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double
%15 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %3
%16 = load double, double* %2
%17 = fadd double 1.000000e+00, %16
%18 = fdiv double 1.000000e+00, %17
store double %18, double* %4
%19 = load double, double* %2
%20 = load double, double* %2
%21 = fadd double 1.000000e+00, %20
%22 = fdiv double %19, %21
store double %22, double* %5
%23 = load double, double* %2
%24 = load double, double* %2
%25 = fadd double 1.000000e+00, %24
%26 = fdiv double %23, %25
store double %26, double* %6
%27 = load double, double* %2
%28 = fadd double 1.000000e+00, %27
%29 = fdiv double 1.000000e+00, %28
store double %29, double* %7
%30 = load double, double* %7
%31 = fneg double %30
store double %31, double* %8
%32 = load double, double* %6
store double %32, double* %9
store double 1.000000e+01, double* %10
store i32 0, i32* %13
br label %33
33: ; preds = %120, %1
%34 = load double, double* %10
%35 = call double @llvm.fabs.f64(double %34)
%36 = fcmp ogt double %35, 0x3D719799812DEA11
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* %13
%39 = icmp slt i32 %38, 100
br label %40
40: ; preds = %37, %33
%41 = phi i1 [ false, %33 ], [ %39, %37 ]
br i1 %41, label %42, label %123
42: ; preds = %40
%43 = load double, double* %3
%44 = load double, double* %6
%45 = fsub double %43, %44
store double %45, double* %14
%46 = load double, double* %3
%47 = load double, double* %7
%48 = fadd double %46, %47
store double %48, double* %15
%49 = load double, double* %4
%50 = load double, double* %14
%51 = load double, double* %14
%52 = fmul double %50, %51
%53 = fdiv double %49, %52
%54 = load double, double* %5
%55 = load double, double* %15
%56 = load double, double* %15
%57 = fmul double %55, %56
%58 = fdiv double %54, %57
%59 = fsub double %53, %58
%60 = load double, double* %3
%61 = fadd double %59, %60
store double %61, double* %11
%62 = load double, double* %4
%63 = fmul double -2.000000e+00, %62
%64 = load double, double* %14
%65 = load double, double* %14
%66 = fmul double %64, %65
%67 = load double, double* %14
%68 = fmul double %66, %67
%69 = fdiv double %63, %68
%70 = load double, double* %5
%71 = fmul double 2.000000e+00, %70
%72 = load double, double* %15
%73 = load double, double* %15
%74 = fmul double %72, %73
%75 = load double, double* %15
%76 = fmul double %74, %75
%77 = fdiv double %71, %76
%78 = fadd double %69, %77
%79 = fadd double %78, 1.000000e+00
store double %79, double* %12
%80 = load double, double* %11
%81 = fcmp ogt double %80, 0.000000e+00
br i1 %81, label %82, label %84
82: ; preds = %42
%83 = load double, double* %3
store double %83, double* %9
br label %84
84: ; preds = %82, %42
%85 = load double, double* %11
%86 = fcmp olt double %85, 0.000000e+00
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = load double, double* %3
store double %88, double* %8
br label %89
89: ; preds = %87, %84
%90 = load double, double* %11
%91 = fneg double %90
%92 = load double, double* %12
%93 = fdiv double %91, %92
store double %93, double* %10
%94 = load double, double* %3
%95 = load double, double* %10
%96 = fadd double %94, %95
%97 = load double, double* %8
%98 = fcmp ole double %96, %97
br i1 %98, label %105, label %99
99: ; preds = %89
%100 = load double, double* %3
%101 = load double, double* %10
%102 = fadd double %100, %101
%103 = load double, double* %9
%104 = fcmp oge double %102, %103
br i1 %104, label %105, label %116
105: ; preds = %99, %89
%106 = load double, double* %8
%107 = load double, double* %9
%108 = fadd double %106, %107
%109 = load double, double* %3
%110 = fneg double %109
%111 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %108, double %110)
store double %111, double* %10
%112 = load double, double* %8
%113 = load double, double* %9
%114 = fadd double %112, %113
%115 = fmul double 5.000000e-01, %114
store double %115, double* %3
br label %120
116: ; preds = %99
%117 = load double, double* %10
%118 = load double, double* %3
%119 = fadd double %118, %117
store double %119, double* %3
br label %120
120: ; preds = %116, %105
%121 = load i32, i32* %13
%122 = add nsw i32 %121, 1
store i32 %122, i32* %13
br label %33
123: ; preds = %40
%124 = load double, double* %7
%125 = load double, double* %7
%126 = load double, double* %3
%127 = fadd double %125, %126
%128 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %124, double %127)
%129 = load double, double* %3
ret double %129
}

LLVM IR (-O2):
@.str = [28 x i8] c"From M2: CM=%.6lf L1=%.6lf\0A\00"
define double @calc_L1(double %0) {
%2 = fadd double %0, 1.000000e+00
%3 = insertelement <2 x double> <double poison, double 1.000000e+00>, double %0, i64 0
%4 = insertelement <2 x double> poison, double %2, i64 0
%5 = shufflevector <2 x double> %4, <2 x double> poison, <2 x i32> zeroinitializer
%6 = fdiv <2 x double> %3, %5
%7 = extractelement <2 x double> %6, i64 1
%8 = fneg double %7
%9 = fmul <2 x double> %6, <double 2.000000e+00, double 2.000000e+00>
%10 = extractelement <2 x double> %6, i64 0
%11 = shufflevector <2 x double> %6, <2 x double> undef, <2 x i32> <i32 1, i32 0>
br label %12
12: ; preds = %1, %49
%13 = phi double [ 0.000000e+00, %1 ], [ %51, %49 ]
%14 = phi double [ %8, %1 ], [ %37, %49 ]
%15 = phi i32 [ 0, %1 ], [ %52, %49 ]
%16 = phi double [ %10, %1 ], [ %35, %49 ]
%17 = insertelement <2 x double> poison, double %13, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = fadd <2 x double> %18, %11
%20 = fsub <2 x double> %18, %11
%21 = shufflevector <2 x double> %19, <2 x double> %20, <2 x i32> <i32 0, i32 3>
%22 = fmul <2 x double> %21, %21
%23 = fdiv <2 x double> %6, %22
%24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%25 = fsub <2 x double> %24, %23
%26 = extractelement <2 x double> %25, i64 0
%27 = fadd double %13, %26
%28 = fmul <2 x double> %21, %22
%29 = fdiv <2 x double> %9, %28
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%31 = fsub <2 x double> %29, %30
%32 = extractelement <2 x double> %31, i64 0
%33 = fadd double %32, 1.000000e+00
%34 = fcmp ogt double %27, 0.000000e+00
%35 = select i1 %34, double %13, double %16
%36 = fcmp olt double %27, 0.000000e+00
%37 = select i1 %36, double %13, double %14
%38 = fneg double %27
%39 = fdiv double %38, %33
%40 = fadd double %13, %39
%41 = fcmp ugt double %40, %37
%42 = fcmp ult double %40, %35
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %49, label %44
44: ; preds = %12
%45 = fadd double %37, %35
%46 = fneg double %13
%47 = tail call double @llvm.fmuladd.f64(double %45, double 5.000000e-01, double %46)
%48 = fmul double %45, 5.000000e-01
br label %49
49: ; preds = %12, %44
%50 = phi double [ %47, %44 ], [ %39, %12 ]
%51 = phi double [ %48, %44 ], [ %40, %12 ]
%52 = add nuw nsw i32 %15, 1
%53 = tail call double @llvm.fabs.f64(double %50)
%54 = fcmp ogt double %53, 0x3D719799812DEA11
%55 = icmp ult i32 %15, 99
%56 = select i1 %54, i1 %55, i1 false
br i1 %56, label %12, label %57
57: ; preds = %49
%58 = fadd double %7, %51
%59 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %7, double %58)
ret double %51
}