#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 pow(double const, int);
int /*<<< orphan*/ usleep(int);
void fitfun(double const *x, int N, double *res) {
  int i;
  double f = 0.0;
  for (i = 0; i < N - 1; i++)
    f = f + 100.0 * pow((x[i + 1] - x[i] * x[i]), 2) + pow((x[i] - 1.0), 2);
  usleep(100);
  *res = f;
  return;
}


x86 assembly (clang, -O0):
<fitfun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    120e <fitfun+0xee>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  -0x38(%rbp),%xmm1
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe1f(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1142 <fitfun+0x22>
mov    $0x64,%edi
call   1040 <usleep@plt>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fitfun>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
xorpd  %xmm0,%xmm0
cmp    $0x2,%esi
jl     1291 <fitfun+0x171>
mov    %esi,%r15d
mov    %rdi,%r13
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
jne    1156 <fitfun+0x36>
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1236 <fitfun+0x116>
mov    %r15d,%r12d
and    $0xfffffffe,%r12d
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,(%rsp)
movsd  0x0(%r13,%rbp,8),%xmm1
movsd  0x8(%r13,%rbp,8),%xmm0
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movapd %xmm0,%xmm1
movsd  0xe5f(%rip),%xmm0
mulsd  %xmm0,%xmm1
addsd  (%rsp),%xmm1
movsd  %xmm1,(%rsp)
movsd  0x0(%r13,%rbp,8),%xmm0
movsd  0xe4a(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0x2(%rbp),%rbx
movsd  0x8(%r13,%rbp,8),%xmm1
movsd  0x10(%r13,%rbp,8),%xmm0
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mulsd  0xdfe(%rip),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%r13,%rbp,8),%xmm0
addsd  0xded(%rip),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  (%rsp),%xmm0
mov    %rbx,%rbp
cmp    %rbx,%r12
jne    1170 <fitfun+0x50>
test   $0x1,%r15b
je     1291 <fitfun+0x171>
movsd  0x0(%r13,%rbx,8),%xmm1
movsd  %xmm0,(%rsp)
movsd  0x8(%r13,%rbx,8),%xmm0
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mulsd  0xd97(%rip),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x0(%r13,%rbx,8),%xmm0
addsd  0xd86(%rip),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x64,%edi
call   1040 <usleep@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fitfun(double* %0, i32 %1, double* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double* %2, double** %6
store double 0.000000e+00, double* %8
store i32 0, i32* %7
br label %9
9: ; preds = %44, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %47
14: ; preds = %9
%15 = load double, double* %8
%16 = load double*, double** %4
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %16, i64 %19
%21 = load double, double* %20
%22 = load double*, double** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fneg double %26
%33 = call double @llvm.fmuladd.f64(double %32, double %31, double %21)
%34 = call double @pow(double %33, i32 2)
%35 = call double @llvm.fmuladd.f64(double 1.000000e+02, double %34, double %15)
%36 = load double*, double** %4
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = fsub double %40, 1.000000e+00
%42 = call double @pow(double %41, i32 2)
%43 = fadd double %35, %42
store double %43, double* %8
br label %44
44: ; preds = %14
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %9
47: ; preds = %9
%48 = call i32 @usleep(i32 100)
%49 = load double, double* %8
%50 = load double*, double** %6
store double %49, double* %50
ret void
}

LLVM IR (-O2):
define void @fitfun(double* nocapture %0, i32 %1, double* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %63
5: ; preds = %3
%6 = add nsw i32 %1, -1
%7 = zext i32 %6 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %6, 1
br i1 %9, label %44, label %10
10: ; preds = %5
%11 = and i64 %7, 4294967294
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ 0, %10 ], [ %29, %12 ]
%14 = phi double [ 0.000000e+00, %10 ], [ %41, %12 ]
%15 = phi i64 [ 0, %10 ], [ %42, %12 ]
%16 = or i64 %13, 1
%17 = getelementptr inbounds double, double* %0, i64 %16
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %0, i64 %13
%20 = load double, double* %19
%21 = fneg double %20
%22 = tail call double @llvm.fmuladd.f64(double %21, double %20, double %18)
%23 = tail call double @pow(double %22, i32 2)
%24 = tail call double @llvm.fmuladd.f64(double %23, double 1.000000e+02, double %14)
%25 = load double, double* %19
%26 = fadd double %25, -1.000000e+00
%27 = tail call double @pow(double %26, i32 2)
%28 = fadd double %24, %27
%29 = add nuw nsw i64 %13, 2
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %0, i64 %16
%33 = load double, double* %32
%34 = fneg double %33
%35 = tail call double @llvm.fmuladd.f64(double %34, double %33, double %31)
%36 = tail call double @pow(double %35, i32 2)
%37 = tail call double @llvm.fmuladd.f64(double %36, double 1.000000e+02, double %28)
%38 = load double, double* %32
%39 = fadd double %38, -1.000000e+00
%40 = tail call double @pow(double %39, i32 2)
%41 = fadd double %37, %40
%42 = add i64 %15, 2
%43 = icmp eq i64 %42, %11
br i1 %43, label %44, label %12
44: ; preds = %12, %5
%45 = phi double [ undef, %5 ], [ %41, %12 ]
%46 = phi i64 [ 0, %5 ], [ %29, %12 ]
%47 = phi double [ 0.000000e+00, %5 ], [ %41, %12 ]
%48 = icmp eq i64 %8, 0
br i1 %48, label %63, label %49
49: ; preds = %44
%50 = add nuw nsw i64 %46, 1
%51 = getelementptr inbounds double, double* %0, i64 %50
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %0, i64 %46
%54 = load double, double* %53
%55 = fneg double %54
%56 = tail call double @llvm.fmuladd.f64(double %55, double %54, double %52)
%57 = tail call double @pow(double %56, i32 2)
%58 = tail call double @llvm.fmuladd.f64(double %57, double 1.000000e+02, double %47)
%59 = load double, double* %53
%60 = fadd double %59, -1.000000e+00
%61 = tail call double @pow(double %60, i32 2)
%62 = fadd double %58, %61
br label %63
63: ; preds = %49, %44, %3
%64 = phi double [ 0.000000e+00, %3 ], [ %45, %44 ], [ %62, %49 ]
%65 = tail call i32 @usleep(i32 100)
store double %64, double* %2
ret void
}