#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 fmax(double, double);
double fmin(double, double);
double prox_scalar(double v, double rho, double (*oracle)(double), double l,
                   double u, double x0) {
  int MAX_ITER = 1000;
  double tol = 1e-8;
  double g;
  double x = fmax(l, fmin(x0, u));
  int iter;
  for (iter = 0; iter < MAX_ITER && u - l > tol; iter++) {
    g = -1 / x + rho * (x - v);
    if (g > 0) {
      l = fmax(l, x - g / rho);
      u = x;
    } else if (g < 0) {
      l = x;
      u = fmin(u, x - g / rho);
    }
    x = (l + u) / 2;
  }
  return x;
}


x86 assembly (clang, -O0):
<prox_scalar>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movl   $0x3e8,-0x34(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm3
movsd  -0x30(%rbp),%xmm4
movsd  -0x28(%rbp),%xmm1
movaps %xmm1,%xmm5
movaps %xmm4,%xmm2
cmpunordsd %xmm2,%xmm2
movaps %xmm2,%xmm0
pand   %xmm5,%xmm0
minsd  %xmm4,%xmm1
pandn  %xmm1,%xmm2
por    %xmm0,%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%ecx
xor    %eax,%eax
cmp    -0x34(%rbp),%ecx
mov    %al,-0x55(%rbp)
jge    11b2 <prox_scalar+0xb2>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
seta   %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    11c2 <prox_scalar+0xc2>
jmp    12c8 <prox_scalar+0x1c8>
movsd  0xe3e(%rip),%xmm1
divsd  -0x50(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
subsd  -0x8(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1247 <prox_scalar+0x147>
movsd  -0x20(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
subsd  %xmm0,%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    129f <prox_scalar+0x19f>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    129a <prox_scalar+0x19a>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
subsd  %xmm0,%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
minsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    129f <prox_scalar+0x19f>
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  0xd5f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    118c <prox_scalar+0x8c>
movsd  -0x50(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<prox_scalar>:
movapd %xmm3,%xmm5
minsd  %xmm4,%xmm5
cmpunordsd %xmm4,%xmm4
movapd %xmm4,%xmm6
andpd  %xmm3,%xmm6
andnpd %xmm5,%xmm4
orpd   %xmm6,%xmm4
movapd %xmm2,%xmm7
cmpunordsd %xmm2,%xmm7
movapd %xmm7,%xmm5
andpd  %xmm4,%xmm5
maxsd  %xmm2,%xmm4
andnpd %xmm4,%xmm7
orpd   %xmm5,%xmm7
movapd %xmm3,%xmm4
subsd  %xmm2,%xmm4
ucomisd 0xeb6(%rip),%xmm4
jbe    1241 <prox_scalar+0x141>
xor    %eax,%eax
movsd  0xead(%rip),%xmm8
xorpd  %xmm6,%xmm6
movsd  0xea8(%rip),%xmm10
movsd  0xe8f(%rip),%xmm9
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm8,%xmm4
divsd  %xmm7,%xmm4
movapd %xmm7,%xmm5
subsd  %xmm0,%xmm5
mulsd  %xmm1,%xmm5
addsd  %xmm4,%xmm5
ucomisd %xmm6,%xmm5
jbe    11e0 <prox_scalar+0xe0>
divsd  %xmm1,%xmm5
movapd %xmm7,%xmm3
subsd  %xmm5,%xmm3
movapd %xmm2,%xmm4
cmpunordsd %xmm2,%xmm4
movapd %xmm4,%xmm5
andpd  %xmm3,%xmm5
maxsd  %xmm2,%xmm3
andnpd %xmm3,%xmm4
orpd   %xmm5,%xmm4
movapd %xmm7,%xmm3
movapd %xmm4,%xmm2
jmp    1217 <prox_scalar+0x117>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
ucomisd %xmm5,%xmm6
jbe    1217 <prox_scalar+0x117>
divsd  %xmm1,%xmm5
movapd %xmm7,%xmm2
subsd  %xmm5,%xmm2
movapd %xmm3,%xmm4
cmpunordsd %xmm3,%xmm4
movapd %xmm4,%xmm5
andpd  %xmm2,%xmm5
minsd  %xmm3,%xmm2
andnpd %xmm2,%xmm4
orpd   %xmm5,%xmm4
movapd %xmm4,%xmm3
movapd %xmm7,%xmm2
movapd %xmm3,%xmm7
addsd  %xmm2,%xmm7
mulsd  %xmm10,%xmm7
cmp    $0x3e6,%eax
ja     1241 <prox_scalar+0x141>
add    $0x1,%eax
movapd %xmm3,%xmm4
subsd  %xmm2,%xmm4
ucomisd %xmm9,%xmm4
ja     1180 <prox_scalar+0x80>
movapd %xmm7,%xmm0
ret

LLVM IR (-O0):
define double @prox_scalar(double %0, double %1, double (double)* %2, double %3, double %4, double %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double (double)*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
store double %0, double* %7
store double %1, double* %8
store double (double)* %2, double (double)** %9
store double %3, double* %10
store double %4, double* %11
store double %5, double* %12
store i32 1000, i32* %13
store double 1.000000e-08, double* %14
%18 = load double, double* %10
%19 = load double, double* %12
%20 = load double, double* %11
%21 = call double @llvm.minnum.f64(double %19, double %20)
%22 = call double @llvm.maxnum.f64(double %18, double %21)
store double %22, double* %16
store i32 0, i32* %17
br label %23
23: ; preds = %72, %6
%24 = load i32, i32* %17
%25 = load i32, i32* %13
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load double, double* %11
%29 = load double, double* %10
%30 = fsub double %28, %29
%31 = load double, double* %14
%32 = fcmp ogt double %30, %31
br label %33
33: ; preds = %27, %23
%34 = phi i1 [ false, %23 ], [ %32, %27 ]
br i1 %34, label %35, label %75
35: ; preds = %33
%36 = load double, double* %16
%37 = fdiv double -1.000000e+00, %36
%38 = load double, double* %8
%39 = load double, double* %16
%40 = load double, double* %7
%41 = fsub double %39, %40
%42 = call double @llvm.fmuladd.f64(double %38, double %41, double %37)
store double %42, double* %15
%43 = load double, double* %15
%44 = fcmp ogt double %43, 0.000000e+00
br i1 %44, label %45, label %54
45: ; preds = %35
%46 = load double, double* %10
%47 = load double, double* %16
%48 = load double, double* %15
%49 = load double, double* %8
%50 = fdiv double %48, %49
%51 = fsub double %47, %50
%52 = call double @llvm.maxnum.f64(double %46, double %51)
store double %52, double* %10
%53 = load double, double* %16
store double %53, double* %11
br label %67
54: ; preds = %35
%55 = load double, double* %15
%56 = fcmp olt double %55, 0.000000e+00
br i1 %56, label %57, label %66
57: ; preds = %54
%58 = load double, double* %16
store double %58, double* %10
%59 = load double, double* %11
%60 = load double, double* %16
%61 = load double, double* %15
%62 = load double, double* %8
%63 = fdiv double %61, %62
%64 = fsub double %60, %63
%65 = call double @llvm.minnum.f64(double %59, double %64)
store double %65, double* %11
br label %66
66: ; preds = %57, %54
br label %67
67: ; preds = %66, %45
%68 = load double, double* %10
%69 = load double, double* %11
%70 = fadd double %68, %69
%71 = fdiv double %70, 2.000000e+00
store double %71, double* %16
br label %72
72: ; preds = %67
%73 = load i32, i32* %17
%74 = add nsw i32 %73, 1
store i32 %74, i32* %17
br label %23
75: ; preds = %33
%76 = load double, double* %16
ret double %76
}

LLVM IR (-O2):
define double @prox_scalar(double %0, double %1, double (double)* nocapture readnone %2, double %3, double %4, double %5) {
%7 = tail call double @llvm.minnum.f64(double %5, double %4)
%8 = tail call double @llvm.maxnum.f64(double %3, double %7)
%9 = fsub double %4, %3
%10 = fcmp ogt double %9, 1.000000e-08
br i1 %10, label %11, label %40
11: ; preds = %6, %30
%12 = phi i32 [ %35, %30 ], [ 0, %6 ]
%13 = phi double [ %34, %30 ], [ %8, %6 ]
%14 = phi double [ %32, %30 ], [ %3, %6 ]
%15 = phi double [ %31, %30 ], [ %4, %6 ]
%16 = fdiv double -1.000000e+00, %13
%17 = fsub double %13, %0
%18 = tail call double @llvm.fmuladd.f64(double %1, double %17, double %16)
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = fdiv double %18, %1
%22 = fsub double %13, %21
%23 = tail call double @llvm.maxnum.f64(double %14, double %22)
br label %30
24: ; preds = %11
%25 = fcmp olt double %18, 0.000000e+00
br i1 %25, label %26, label %30
26: ; preds = %24
%27 = fdiv double %18, %1
%28 = fsub double %13, %27
%29 = tail call double @llvm.minnum.f64(double %15, double %28)
br label %30
30: ; preds = %24, %26, %20
%31 = phi double [ %13, %20 ], [ %29, %26 ], [ %15, %24 ]
%32 = phi double [ %23, %20 ], [ %13, %26 ], [ %14, %24 ]
%33 = fadd double %31, %32
%34 = fmul double %33, 5.000000e-01
%35 = add nuw nsw i32 %12, 1
%36 = icmp ult i32 %12, 999
%37 = fsub double %31, %32
%38 = fcmp ogt double %37, 1.000000e-08
%39 = select i1 %36, i1 %38, i1 false
br i1 %39, label %11, label %40
40: ; preds = %30, %6
%41 = phi double [ %8, %6 ], [ %34, %30 ]
ret double %41
}