#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 c_invnewton(double, double *, int, int, int, int, int, double *);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ print_conv(int, double *);
int /*<<< orphan*/ printf(char *, int, double);
int main() {
  double y = 0.25;
  double x;
  int itermax = 12;
  double *conv = malloc(itermax * sizeof(double));
  int success = c_invnewton(y, &x, 1e-13, 1e-10, 2, itermax, 1, conv);
  printf("success=%d, x=%12.5f\n", success, x);
  print_conv(itermax, conv);
  free(conv);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0xc,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x1c(%rbp),%r8d
mov    -0x28(%rbp),%rax
lea    -0x18(%rbp),%rdi
xor    %edx,%edx
mov    $0x2,%ecx
mov    $0x1,%r9d
mov    %edx,%esi
mov    %rax,(%rsp)
call   1050 <c_invnewton@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <print_conv@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x60,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
movsd  0xe92(%rip),%xmm0
lea    0x8(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x2,%ecx
mov    $0xc,%r8d
mov    $0x1,%r9d
call   1050 <c_invnewton@plt>
movsd  0x8(%rsp),%xmm0
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0xc,%edi
mov    %rbx,%rsi
call   1070 <print_conv@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"success=%d, x=%12.5f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
store i32 0, i32* %1
store double 2.500000e-01, double* %2
store i32 12, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call double* @malloc(i32 %10)
store double* %11, double** %5
%12 = load double, double* %2
%13 = load i32, i32* %4
%14 = load double*, double** %5
%15 = call i32 @c_invnewton(double %12, double* %3, i32 0, i32 0, i32 2, i32 %13, i32 1, double* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = load double, double* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %16, double %17)
%19 = load i32, i32* %4
%20 = load double*, double** %5
%21 = call i32 @print_conv(i32 %19, double* %20)
%22 = load double*, double** %5
%23 = call i32 @free(double* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"success=%d, x=%12.5f\0A\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call double* @malloc(i32 96)
%4 = call i32 @c_invnewton(double 2.500000e-01, double* %1, i32 0, i32 0, i32 2, i32 12, i32 1, double* %3)
%5 = load double, double* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %4, double %5)
%7 = call i32 @print_conv(i32 12, double* %3)
%8 = call i32 @free(double* %3)
ret i32 0
}