#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 */
int fabs(double);
double pow(double, double);
int /*<<< orphan*/ printf(char *, ...);
void zerofind(double *root, int *iterStep, double v, double p, double c,
              double x0) {
  double x, f, fprime, p1 = p - 1, pp;
  int step = 0;
  if (v == 0) {
    *root = 0;
    *iterStep = 0;
    return;
  }
  if (c == 0) {
    *root = v;
    *iterStep = 0;
    return;
  }
  if ((x0 < v) && (x0 > 0))
    x = x0;
  else
    x = v;
  pp = pow(x, p1);
  f = x + c * pp - v;
  while (1) {
    step++;
    fprime = 1 + c * p1 * pp / x;
    x = x - f / fprime;
    if (p > 2) {
      if (x > v) {
        x = v;
      }
    } else {
      if ((x < 0) || (x > v)) {
        x = 1e-30;
        f = x + c * pow(x, p1) - v;
        if (f > 0) {
          *root = x;
          *iterStep = step;
          break;
        }
      }
    }
    pp = pow(x, p1);
    f = x + c * pp - v;
    if (fabs(f) <= 1e-8) {
      *root = x;
      *iterStep = step;
      break;
    }
    if (step >= 1000) {
      printf("\n The number of steps exceed %d, in finding the root for f(x)= "
             "x + c x^{p-1} - v, 0< x< v.",
             1000);
      printf("\n If you meet with this problem, please contact Jun Liu "
             "(j.liu@asu.edu). Thanks!");
      return;
    }
  }
}


x86 assembly (clang, -O0):
<zerofind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x5c(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a3 <zerofind+0x73>
jp     11a3 <zerofind+0x73>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1413 <zerofind+0x2e3>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d7 <zerofind+0xa7>
jp     11d7 <zerofind+0xa7>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1413 <zerofind+0x2e3>
movsd  -0x30(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120c <zerofind+0xdc>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120c <zerofind+0xdc>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1216 <zerofind+0xe6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1050 <pow@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
movsd  -0x28(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
divsd  -0x38(%rbp),%xmm1
movsd  0xd90(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xd6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c7 <zerofind+0x197>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    12c2 <zerofind+0x192>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    136b <zerofind+0x23b>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
ja     12e5 <zerofind+0x1b5>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1366 <zerofind+0x236>
movsd  0xd23(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1050 <pow@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1361 <zerofind+0x231>
movsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x5c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1413 <zerofind+0x2e3>
jmp    1366 <zerofind+0x236>
jmp    136b <zerofind+0x23b>
movsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1050 <pow@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xc62(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     13db <zerofind+0x2ab>
movsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x5c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1413 <zerofind+0x2e3>
cmpl   $0x3e8,-0x5c(%rbp)
jl     140e <zerofind+0x2de>
lea    0xc31(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1413 <zerofind+0x2e3>
jmp    124b <zerofind+0x11b>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zerofind>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
movapd %xmm0,%xmm4
mov    %rsi,%r14
mov    %rdi,%rbx
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm4
jne    1161 <zerofind+0x31>
jp     1161 <zerofind+0x31>
movq   $0x0,(%rbx)
movl   $0x0,(%r14)
jmp    1356 <zerofind+0x226>
ucomisd %xmm0,%xmm2
jne    1179 <zerofind+0x49>
jp     1179 <zerofind+0x49>
movsd  %xmm4,(%rbx)
movl   $0x0,(%r14)
jmp    1356 <zerofind+0x226>
movsd  0xe7f(%rip),%xmm0
movsd  %xmm1,0x38(%rsp)
addsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movsd  %xmm2,0x8(%rsp)
xorpd  %xmm0,%xmm0
cmpltsd %xmm3,%xmm0
movapd %xmm0,%xmm2
andpd  %xmm3,%xmm2
andnpd %xmm4,%xmm0
orpd   %xmm2,%xmm0
cmpltsd %xmm4,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm4,%xmm3
orpd   %xmm0,%xmm3
movapd %xmm3,0x10(%rsp)
movapd %xmm3,%xmm0
movapd %xmm4,0x20(%rsp)
call   1050 <pow@plt>
movapd 0x10(%rsp),%xmm3
movapd 0x20(%rsp),%xmm2
movapd %xmm0,%xmm1
movapd %xmm0,%xmm4
movsd  0x8(%rsp),%xmm5
mulsd  %xmm5,%xmm4
addsd  %xmm3,%xmm4
subsd  %xmm2,%xmm4
movsd  (%rsp),%xmm0
mulsd  %xmm5,%xmm0
movsd  %xmm0,0x30(%rsp)
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulsd  0x30(%rsp),%xmm1
movsd  0x38(%rsp),%xmm0
ucomisd 0xdd4(%rip),%xmm0
divsd  %xmm3,%xmm1
addsd  0xdd0(%rip),%xmm1
divsd  %xmm1,%xmm4
subsd  %xmm4,%xmm3
jbe    1260 <zerofind+0x130>
ucomisd %xmm2,%xmm3
jbe    12ac <zerofind+0x17c>
movapd %xmm2,%xmm3
jmp    12ac <zerofind+0x17c>
cs nopw 0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
ja     1270 <zerofind+0x140>
ucomisd %xmm2,%xmm3
jbe    12ac <zerofind+0x17c>
movsd  0xda0(%rip),%xmm0
movsd  (%rsp),%xmm1
call   1050 <pow@plt>
movapd 0x20(%rsp),%xmm2
mulsd  0x8(%rsp),%xmm0
movsd  0xd82(%rip),%xmm3
addsd  %xmm3,%xmm0
subsd  %xmm2,%xmm0
ucomisd 0xd7a(%rip),%xmm0
ja     1347 <zerofind+0x217>
movapd %xmm3,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  (%rsp),%xmm1
call   1050 <pow@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x48(%rsp)
mulsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
subsd  0x20(%rsp),%xmm1
movsd  %xmm1,0x40(%rsp)
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    133f <zerofind+0x20f>
add    $0x1,%ebp
cmp    $0x3e9,%ebp
movapd 0x20(%rsp),%xmm2
movapd 0x10(%rsp),%xmm3
movsd  0x48(%rsp),%xmm1
movsd  0x40(%rsp),%xmm4
jne    1220 <zerofind+0xf0>
lea    0xd0b(%rip),%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd53(%rip),%rdi
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>
movapd 0x10(%rsp),%xmm0
jmp    134f <zerofind+0x21f>
movsd  0xcc9(%rip),%xmm0
movsd  %xmm0,(%rbx)
mov    %ebp,(%r14)
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [91 x i8] c"\0A The number of steps exceed %d, in finding the root for f(x)= x + c x^{p-1} - v, 0< x< v.\00"
@.str.1 = [81 x i8] c"\0A If you meet with this problem, please contact Jun Liu (j.liu@asu.edu). Thanks!\00"
define void @zerofind(double* %0, i32* %1, double %2, double %3, double %4, double %5) {
%7 = alloca double*
%8 = alloca i32*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
store double* %0, double** %7
store i32* %1, i32** %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store double %5, double* %12
%19 = load double, double* %10
%20 = fsub double %19, 1.000000e+00
store double %20, double* %16
store i32 0, i32* %18
%21 = load double, double* %9
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %6
%24 = load double*, double** %7
store double 0.000000e+00, double* %24
%25 = load i32*, i32** %8
store i32 0, i32* %25
br label %130
26: ; preds = %6
%27 = load double, double* %11
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load double, double* %9
%31 = load double*, double** %7
store double %30, double* %31
%32 = load i32*, i32** %8
store i32 0, i32* %32
br label %130
33: ; preds = %26
%34 = load double, double* %12
%35 = load double, double* %9
%36 = fcmp olt double %34, %35
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load double, double* %12
%39 = fcmp ogt double %38, 0.000000e+00
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = load double, double* %12
store double %41, double* %13
br label %44
42: ; preds = %37, %33
%43 = load double, double* %9
store double %43, double* %13
br label %44
44: ; preds = %42, %40
%45 = load double, double* %13
%46 = load double, double* %16
%47 = call double @pow(double %45, double %46)
store double %47, double* %17
%48 = load double, double* %13
%49 = load double, double* %11
%50 = load double, double* %17
%51 = call double @llvm.fmuladd.f64(double %49, double %50, double %48)
%52 = load double, double* %9
%53 = fsub double %51, %52
store double %53, double* %14
br label %54
54: ; preds = %44, %129
%55 = load i32, i32* %18
%56 = add nsw i32 %55, 1
store i32 %56, i32* %18
%57 = load double, double* %11
%58 = load double, double* %16
%59 = fmul double %57, %58
%60 = load double, double* %17
%61 = fmul double %59, %60
%62 = load double, double* %13
%63 = fdiv double %61, %62
%64 = fadd double 1.000000e+00, %63
store double %64, double* %15
%65 = load double, double* %13
%66 = load double, double* %14
%67 = load double, double* %15
%68 = fdiv double %66, %67
%69 = fsub double %65, %68
store double %69, double* %13
%70 = load double, double* %10
%71 = fcmp ogt double %70, 2.000000e+00
br i1 %71, label %72, label %79
72: ; preds = %54
%73 = load double, double* %13
%74 = load double, double* %9
%75 = fcmp ogt double %73, %74
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = load double, double* %9
store double %77, double* %13
br label %78
78: ; preds = %76, %72
br label %104
79: ; preds = %54
%80 = load double, double* %13
%81 = fcmp olt double %80, 0.000000e+00
br i1 %81, label %86, label %82
82: ; preds = %79
%83 = load double, double* %13
%84 = load double, double* %9
%85 = fcmp ogt double %83, %84
br i1 %85, label %86, label %103
86: ; preds = %82, %79
store double 1.000000e-30, double* %13
%87 = load double, double* %13
%88 = load double, double* %11
%89 = load double, double* %13
%90 = load double, double* %16
%91 = call double @pow(double %89, double %90)
%92 = call double @llvm.fmuladd.f64(double %88, double %91, double %87)
%93 = load double, double* %9
%94 = fsub double %92, %93
store double %94, double* %14
%95 = load double, double* %14
%96 = fcmp ogt double %95, 0.000000e+00
br i1 %96, label %97, label %102
97: ; preds = %86
%98 = load double, double* %13
%99 = load double*, double** %7
store double %98, double* %99
%100 = load i32, i32* %18
%101 = load i32*, i32** %8
store i32 %100, i32* %101
br label %130
102: ; preds = %86
br label %103
103: ; preds = %102, %82
br label %104
104: ; preds = %103, %78
%105 = load double, double* %13
%106 = load double, double* %16
%107 = call double @pow(double %105, double %106)
store double %107, double* %17
%108 = load double, double* %13
%109 = load double, double* %11
%110 = load double, double* %17
%111 = call double @llvm.fmuladd.f64(double %109, double %110, double %108)
%112 = load double, double* %9
%113 = fsub double %111, %112
store double %113, double* %14
%114 = load double, double* %14
%115 = call i32 @fabs(double %114)
%116 = sitofp i32 %115 to double
%117 = fcmp ole double %116, 1.000000e-08
br i1 %117, label %118, label %123
118: ; preds = %104
%119 = load double, double* %13
%120 = load double*, double** %7
store double %119, double* %120
%121 = load i32, i32* %18
%122 = load i32*, i32** %8
store i32 %121, i32* %122
br label %130
123: ; preds = %104
%124 = load i32, i32* %18
%125 = icmp sge i32 %124, 1000
br i1 %125, label %126, label %129
126: ; preds = %123
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 1000)
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
br label %130
129: ; preds = %123
br label %54
130: ; preds = %23, %29, %126, %118, %97
ret void
}

LLVM IR (-O2):
@.str = [91 x i8] c"\0A The number of steps exceed %d, in finding the root for f(x)= x + c x^{p-1} - v, 0< x< v.\00"
@.str.1 = [81 x i8] c"\0A If you meet with this problem, please contact Jun Liu (j.liu@asu.edu). Thanks!\00"
define void @zerofind(double* nocapture writeonly %0, i32* nocapture writeonly %1, double %2, double %3, double %4, double %5) {
%7 = fadd double %3, -1.000000e+00
%8 = fcmp oeq double %2, 0.000000e+00
br i1 %8, label %9, label %10
9: ; preds = %6
store double 0.000000e+00, double* %0
store i32 0, i32* %1
br label %60
10: ; preds = %6
%11 = fcmp oeq double %4, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %10
store double %2, double* %0
store i32 0, i32* %1
br label %60
13: ; preds = %10
%14 = fcmp olt double %5, %2
%15 = fcmp ogt double %5, 0.000000e+00
%16 = and i1 %14, %15
%17 = select i1 %16, double %5, double %2
%18 = tail call double @pow(double %17, double %7)
%19 = tail call double @llvm.fmuladd.f64(double %4, double %18, double %17)
%20 = fsub double %19, %2
%21 = fmul double %7, %4
%22 = fcmp ogt double %3, 2.000000e+00
br label %23
23: ; preds = %53, %13
%24 = phi double [ %20, %13 ], [ %50, %53 ]
%25 = phi double [ %17, %13 ], [ %47, %53 ]
%26 = phi double [ %18, %13 ], [ %48, %53 ]
%27 = phi i32 [ 0, %13 ], [ %28, %53 ]
%28 = add nuw nsw i32 %27, 1
%29 = fmul double %21, %26
%30 = fdiv double %29, %25
%31 = fadd double %30, 1.000000e+00
%32 = fdiv double %24, %31
%33 = fsub double %25, %32
br i1 %22, label %34, label %37
34: ; preds = %23
%35 = fcmp ogt double %33, %2
br i1 %35, label %36, label %46
36: ; preds = %34
br label %46
37: ; preds = %23
%38 = fcmp olt double %33, 0.000000e+00
%39 = fcmp ogt double %33, %2
%40 = or i1 %38, %39
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = tail call double @pow(double 1.000000e-30, double %7)
%43 = tail call double @llvm.fmuladd.f64(double %4, double %42, double 1.000000e-30)
%44 = fsub double %43, %2
%45 = fcmp ogt double %44, 0.000000e+00
br i1 %45, label %58, label %46
46: ; preds = %37, %41, %34, %36
%47 = phi double [ %2, %36 ], [ %33, %34 ], [ 1.000000e-30, %41 ], [ %33, %37 ]
%48 = tail call double @pow(double %47, double %7)
%49 = tail call double @llvm.fmuladd.f64(double %4, double %48, double %47)
%50 = fsub double %49, %2
%51 = tail call i32 @fabs(double %50)
%52 = icmp slt i32 %51, 1
br i1 %52, label %58, label %53
53: ; preds = %46
%54 = icmp eq i32 %28, 1000
br i1 %54, label %55, label %23
55: ; preds = %53
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 1000)
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
br label %60
58: ; preds = %46, %41
%59 = phi double [ 1.000000e-30, %41 ], [ %47, %46 ]
store double %59, double* %0
store i32 %28, i32* %1
br label %60
60: ; preds = %58, %55, %12, %9
ret void
}