#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 /*<<< orphan*/ allroots(int, double *, int, double *);
double d_abs(double);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  static double A[] = {4.1, -3.9, -1.0, 1.0};
  int N = 3;
  int J;
  printf("DEBUG: %g %g\n", 2.69065 * 2.69065 * 2.69065, 2.69065 * 2.69065);
  printf("==============================================================\n");
  printf("Find all roots of\n");
  for (J = N; J > 0; J--) {
    printf("%g", d_abs(A[J]));
    if (A[J - 1] < 0)
      printf("x**%d - ", J);
    else
      printf("x**%d + ", J);
  }
  printf("%g\n", d_abs(A[0]));
  printf("using NEWTON method.\n");
  printf("==============================================================\n");
  allroots(N, A, N, A);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
lea    0xec3(%rip),%rdi
movsd  0xeab(%rip),%xmm0
movsd  0xeab(%rip),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    120b <main+0xdb>
movslq -0xc(%rbp),%rcx
lea    0x2ea5(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
call   1030 <d_abs@plt>
lea    0xec5(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
xorps  %xmm0,%xmm0
lea    0x2e7a(%rip),%rax
ucomisd (%rax,%rcx,8),%xmm0
jbe    11e7 <main+0xb7>
mov    -0xc(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <main+0xc8>
mov    -0xc(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <main+0xcd>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1186 <main+0x56>
movsd  0x2e2d(%rip),%xmm0
call   1030 <d_abs@plt>
lea    0xdfb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%edx
lea    0x2df1(%rip),%rcx
mov    %rcx,%rsi
call   1050 <allroots@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xec8(%rip),%rdi
movsd  0xea8(%rip),%xmm0
movsd  0xea8(%rip),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
lea    0xef4(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
lea    0x2ec7(%rip),%r15
movsd  0x2ed7(%rip),%xmm0
call   1030 <d_abs@plt>
lea    0xe89(%rip),%r12
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorpd  %xmm0,%xmm0
ucomisd 0x2ead(%rip),%xmm0
lea    0xe6f(%rip),%r13
lea    0xe71(%rip),%rbx
mov    %rbx,%rdi
cmova  %r13,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x2e84(%rip),%xmm0
call   1030 <d_abs@plt>
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorpd  %xmm0,%xmm0
ucomisd 0x2e61(%rip),%xmm0
mov    %rbx,%rdi
cmova  %r13,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x2e46(%rip),%xmm0
call   1030 <d_abs@plt>
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorpd  %xmm0,%xmm0
ucomisd 0x2e23(%rip),%xmm0
cmova  %r13,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x2e08(%rip),%xmm0
call   1030 <d_abs@plt>
lea    0xdce(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xdeb(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0x3,%edi
mov    %r15,%rsi
mov    $0x3,%edx
mov    %r15,%rcx
call   1060 <allroots@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.A = internal global [4 x double] [double 4.100000e+00, double -3.900000e+00, double -1.000000e+00, double 1.000000e+00]
@.str = [14 x i8] c"DEBUG: %g %g\0A\00"
@.str.1 = [64 x i8] c"==============================================================\0A\00"
@.str.2 = [19 x i8] c"Find all roots of\0A\00"
@.str.3 = [3 x i8] c"%g\00"
@.str.4 = [9 x i8] c"x**%d - \00"
@.str.5 = [9 x i8] c"x**%d + \00"
@.str.6 = [4 x i8] c"%g\0A\00"
@.str.7 = [22 x i8] c"using NEWTON method.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 3, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double 0x40337AAE58825399, double 0x401CF55906D75FA4)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* %2
store i32 %7, i32* %3
br label %8
8: ; preds = %31, %0
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x double], [4 x double]* @main.A, i64 0, i64 %13
%15 = load double, double* %14
%16 = call double @d_abs(double %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %16)
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x double], [4 x double]* @main.A, i64 0, i64 %20
%22 = load double, double* %21
%23 = fcmp olt double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %11
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %11
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = add nsw i32 %32, -1
store i32 %33, i32* %3
br label %8
34: ; preds = %8
%35 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0)
%36 = call double @d_abs(double %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* %2
%41 = load i32, i32* %2
%42 = call i32 @allroots(i32 %40, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0), i32 %41, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@main.A = internal global [4 x double] [double 4.100000e+00, double -3.900000e+00, double -1.000000e+00, double 1.000000e+00]
@.str = [14 x i8] c"DEBUG: %g %g\0A\00"
@.str.3 = [3 x i8] c"%g\00"
@.str.4 = [9 x i8] c"x**%d - \00"
@.str.5 = [9 x i8] c"x**%d + \00"
@.str.6 = [4 x i8] c"%g\0A\00"
@str.8 = [18 x i8] c"Find all roots of\00"
@str.9 = [21 x i8] c"using NEWTON method.\00"
@str.10 = [63 x i8] c"==============================================================\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double 0x40337AAE58825399, double 0x401CF55906D75FA4)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.10, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
%4 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 3)
%5 = tail call double @d_abs(double %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %5)
%7 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 2)
%8 = fcmp olt double %7, 0.000000e+00
%9 = select i1 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %9, i32 3)
%11 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 2)
%12 = tail call double @d_abs(double %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %12)
%14 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 1)
%15 = fcmp olt double %14, 0.000000e+00
%16 = select i1 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %16, i32 2)
%18 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 1)
%19 = tail call double @d_abs(double %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %19)
%21 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0)
%22 = fcmp olt double %21, 0.000000e+00
%23 = select i1 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %23, i32 1)
%25 = load double, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0)
%26 = tail call double @d_abs(double %25)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %26)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.10, i64 0, i64 0))
%30 = tail call i32 @allroots(i32 3, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0), i32 3, double* getelementptr inbounds ([4 x double], [4 x double]* @main.A, i64 0, i64 0))
ret i32 0
}