#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 sqrt(float);
float converge(float vc, float vdac, float r1, float a, float b, int leg) {
  int i = 0;
  float vds = 0.0f;
  float vds1, vds2;
  float ids = 0.0f;
  for (i = 0; i < 10; i++) {
    if (leg)
      ids = (vc - vds) / r1;
    else
      ids = (vdac - vc - vds) / r1;
    if (ids < 0.0f)
      break;
    vds1 = (0.0f - b) + sqrt(b * b - 4.0f * a * (0.0f - ids));
    vds1 = vds1 / (2.0f * a);
    vds2 = (0.0f - b) - sqrt(b * b - 4.0f * a * (0.0f - ids));
    vds2 = vds1 / (2.0f * a);
    if (vds1 > 0) {
      vds = vds1;
    } else if (vds2 > 0) {
      vds = vds2;
    }
  }
  return vds;
}


x86 assembly (clang, -O0):
<converge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
mov    %edi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    12e9 <converge+0x1d9>
cmpl   $0x0,-0x18(%rbp)
je     117f <converge+0x6f>
movss  -0x4(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    1198 <converge+0x88>
movss  -0x8(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x2c(%rbp),%xmm0
jbe    11aa <converge+0x9a>
jmp    12e9 <converge+0x1d9>
xorps  %xmm0,%xmm0
subss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movss  0xe3b(%rip),%xmm1
mulss  -0x10(%rbp),%xmm1
xorps  %xmm3,%xmm3
subss  -0x2c(%rbp),%xmm3
mulss  %xmm3,%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  0xdee(%rip),%xmm1
mulss  -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
subss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movss  0xdc5(%rip),%xmm1
mulss  -0x10(%rbp),%xmm1
xorps  %xmm3,%xmm3
subss  -0x2c(%rbp),%xmm3
mulss  %xmm3,%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
movss  0xd78(%rip),%xmm1
mulss  -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    12b6 <converge+0x1a6>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    12d6 <converge+0x1c6>
movss  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    12d1 <converge+0x1c1>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    12d6 <converge+0x1c6>
jmp    12db <converge+0x1cb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <converge+0x42>
movss  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<converge>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm9
test   %edi,%edi
jne    1126 <converge+0x16>
subss  %xmm9,%xmm1
movaps %xmm1,%xmm9
xorps  %xmm1,%xmm1
xorps  %xmm8,%xmm8
subss  %xmm4,%xmm8
movss  0xec6(%rip),%xmm7
mulss  %xmm3,%xmm7
addss  %xmm3,%xmm3
mov    $0xa,%ebx
mulss  %xmm4,%xmm4
xorps  %xmm6,%xmm6
movss  %xmm3,0x18(%rsp)
movss  %xmm8,0xc(%rsp)
movss  %xmm4,0x1c(%rsp)
movss  %xmm2,0x14(%rsp)
movss  %xmm9,0x10(%rsp)
movss  %xmm7,0x8(%rsp)
jmp    118c <converge+0x7c>
cs nopw 0x0(%rax,%rax,1)
movaps %xmm0,%xmm6
add    $0xffffffff,%ebx
je     127e <converge+0x16e>
movaps %xmm9,%xmm0
subss  %xmm6,%xmm0
divss  %xmm2,%xmm0
ucomiss %xmm0,%xmm1
ja     127e <converge+0x16e>
xorps  %xmm5,%xmm5
subss  %xmm0,%xmm5
mulss  %xmm7,%xmm5
addss  %xmm4,%xmm5
ucomiss %xmm1,%xmm5
jb     11c0 <converge+0xb0>
xorps  %xmm0,%xmm0
sqrtss %xmm5,%xmm0
jmp    1207 <converge+0xf7>
xchg   %ax,%ax
movaps %xmm5,%xmm0
movss  %xmm6,0x4(%rsp)
movss  %xmm5,(%rsp)
call   1030 <sqrt@plt>
movss  (%rsp),%xmm5
movss  0x4(%rsp),%xmm6
movss  0x8(%rsp),%xmm7
movss  0xc(%rsp),%xmm8
xorps  %xmm1,%xmm1
movss  0x10(%rsp),%xmm9
movss  0x14(%rsp),%xmm2
movss  0x18(%rsp),%xmm3
movss  0x1c(%rsp),%xmm4
ucomiss %xmm5,%xmm1
ja     1230 <converge+0x120>
addss  %xmm8,%xmm0
divss  %xmm3,%xmm0
ucomiss %xmm1,%xmm0
ja     1180 <converge+0x70>
divss  %xmm3,%xmm0
ucomiss %xmm1,%xmm0
ja     1180 <converge+0x70>
jmp    1183 <converge+0x73>
ucomiss %xmm1,%xmm5
jae    120c <converge+0xfc>
movss  %xmm0,(%rsp)
movaps %xmm5,%xmm0
movss  %xmm6,0x4(%rsp)
call   1030 <sqrt@plt>
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm6
movss  0x8(%rsp),%xmm7
movss  0xc(%rsp),%xmm8
xorps  %xmm1,%xmm1
movss  0x10(%rsp),%xmm9
movss  0x14(%rsp),%xmm2
movss  0x18(%rsp),%xmm3
movss  0x1c(%rsp),%xmm4
jmp    120c <converge+0xfc>
movaps %xmm6,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @converge(float %0, float %1, float %2, float %3, float %4, i32 %5) {
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
store float %0, float* %7
store float %1, float* %8
store float %2, float* %9
store float %3, float* %10
store float %4, float* %11
store i32 %5, i32* %12
store i32 0, i32* %13
store float 0.000000e+00, float* %14
store float 0.000000e+00, float* %17
store i32 0, i32* %13
br label %18
18: ; preds = %88, %6
%19 = load i32, i32* %13
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %91
21: ; preds = %18
%22 = load i32, i32* %12
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load float, float* %7
%26 = load float, float* %14
%27 = fsub float %25, %26
%28 = load float, float* %9
%29 = fdiv float %27, %28
store float %29, float* %17
br label %38
30: ; preds = %21
%31 = load float, float* %8
%32 = load float, float* %7
%33 = fsub float %31, %32
%34 = load float, float* %14
%35 = fsub float %33, %34
%36 = load float, float* %9
%37 = fdiv float %35, %36
store float %37, float* %17
br label %38
38: ; preds = %30, %24
%39 = load float, float* %17
%40 = fcmp olt float %39, 0.000000e+00
br i1 %40, label %41, label %42
41: ; preds = %38
br label %91
42: ; preds = %38
%43 = load float, float* %11
%44 = fsub float 0.000000e+00, %43
%45 = load float, float* %11
%46 = load float, float* %11
%47 = load float, float* %10
%48 = fmul float 4.000000e+00, %47
%49 = load float, float* %17
%50 = fsub float 0.000000e+00, %49
%51 = fmul float %48, %50
%52 = fneg float %51
%53 = call float @llvm.fmuladd.f32(float %45, float %46, float %52)
%54 = call float @sqrt(float %53)
%55 = fadd float %44, %54
store float %55, float* %15
%56 = load float, float* %15
%57 = load float, float* %10
%58 = fmul float 2.000000e+00, %57
%59 = fdiv float %56, %58
store float %59, float* %15
%60 = load float, float* %11
%61 = fsub float 0.000000e+00, %60
%62 = load float, float* %11
%63 = load float, float* %11
%64 = load float, float* %10
%65 = fmul float 4.000000e+00, %64
%66 = load float, float* %17
%67 = fsub float 0.000000e+00, %66
%68 = fmul float %65, %67
%69 = fneg float %68
%70 = call float @llvm.fmuladd.f32(float %62, float %63, float %69)
%71 = call float @sqrt(float %70)
%72 = fsub float %61, %71
store float %72, float* %16
%73 = load float, float* %15
%74 = load float, float* %10
%75 = fmul float 2.000000e+00, %74
%76 = fdiv float %73, %75
store float %76, float* %16
%77 = load float, float* %15
%78 = fcmp ogt float %77, 0.000000e+00
br i1 %78, label %79, label %81
79: ; preds = %42
%80 = load float, float* %15
store float %80, float* %14
br label %87
81: ; preds = %42
%82 = load float, float* %16
%83 = fcmp ogt float %82, 0.000000e+00
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = load float, float* %16
store float %85, float* %14
br label %86
86: ; preds = %84, %81
br label %87
87: ; preds = %86, %79
br label %88
88: ; preds = %87
%89 = load i32, i32* %13
%90 = add nsw i32 %89, 1
store i32 %90, i32* %13
br label %18
91: ; preds = %41, %18
%92 = load float, float* %14
ret float %92
}

LLVM IR (-O2):
define float @converge(float %0, float %1, float %2, float %3, float %4, i32 %5) {
%7 = icmp eq i32 %5, 0
%8 = fsub float %1, %0
%9 = select i1 %7, float %8, float %0
%10 = fsub float 0.000000e+00, %4
%11 = fmul float %3, -4.000000e+00
%12 = fmul float %3, 2.000000e+00
br label %13
13: ; preds = %6, %35
%14 = phi float [ 0.000000e+00, %6 ], [ %36, %35 ]
%15 = phi i32 [ 0, %6 ], [ %37, %35 ]
%16 = fsub float %9, %14
%17 = fdiv float %16, %2
%18 = fcmp olt float %17, 0.000000e+00
br i1 %18, label %39, label %19
19: ; preds = %13
%20 = fsub float 0.000000e+00, %17
%21 = fmul float %11, %20
%22 = tail call float @llvm.fmuladd.f32(float %4, float %4, float %21)
%23 = tail call float @sqrt(float %22)
%24 = fadd float %10, %23
%25 = fdiv float %24, %12
%26 = fcmp olt float %22, 0.000000e+00
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = tail call float @sqrt(float %22)
br label %29
29: ; preds = %19, %27
%30 = fdiv float %25, %12
%31 = fcmp ogt float %25, 0.000000e+00
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = fcmp ogt float %30, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %32
br label %35
35: ; preds = %29, %34, %32
%36 = phi float [ %30, %34 ], [ %14, %32 ], [ %25, %29 ]
%37 = add nuw nsw i32 %15, 1
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %13
39: ; preds = %13, %35
%40 = phi float [ %14, %13 ], [ %36, %35 ]
ret float %40
}