#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 */
scalar_t__ fabs(double);
int economize(int n, double eps, double err, double c[]) {
  int k;
  double r;
  r = err;
  for (k = n; k >= 1; --k) {
    r += fabs(c[k]);
    if (r >= eps)
      break;
  }
  return (k);
}


x86 assembly (clang, -O0):
<economize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     118c <economize+0x7c>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1179 <economize+0x69>
jmp    118c <economize+0x7c>
jmp    117e <economize+0x6e>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1139 <economize+0x29>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<economize>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %edi,%ebx
test   %edi,%edi
jle    1166 <economize+0x56>
mov    %rsi,%r14
mov    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
movsd  (%r14,%rbx,8),%xmm0
call   1030 <fabs@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  0x10(%rsp),%xmm1
ucomisd 0x8(%rsp),%xmm1
jae    1166 <economize+0x56>
lea    -0x1(%rbx),%rax
cmp    $0x1,%rbx
mov    %rax,%rbx
jg     1130 <economize+0x20>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @economize(i32 %0, double %1, double %2, double* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
store i32 %0, i32* %5
store double %1, double* %6
store double %2, double* %7
store double* %3, double** %8
%11 = load double, double* %7
store double %11, double* %10
%12 = load i32, i32* %5
store i32 %12, i32* %9
br label %13
13: ; preds = %31, %4
%14 = load i32, i32* %9
%15 = icmp sge i32 %14, 1
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load double*, double** %8
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = call i64 @fabs(double %21)
%23 = sitofp i64 %22 to double
%24 = load double, double* %10
%25 = fadd double %24, %23
store double %25, double* %10
%26 = load double, double* %10
%27 = load double, double* %6
%28 = fcmp oge double %26, %27
br i1 %28, label %29, label %30
29: ; preds = %16
br label %34
30: ; preds = %16
br label %31
31: ; preds = %30
%32 = load i32, i32* %9
%33 = add nsw i32 %32, -1
store i32 %33, i32* %9
br label %13
34: ; preds = %29, %13
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
define i32 @economize(i32 %0, double %1, double %2, double* nocapture %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %22
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %17
%9 = phi i64 [ %7, %6 ], [ %18, %17 ]
%10 = phi double [ %2, %6 ], [ %15, %17 ]
%11 = getelementptr inbounds double, double* %3, i64 %9
%12 = load double, double* %11
%13 = tail call i64 @fabs(double %12)
%14 = sitofp i64 %13 to double
%15 = fadd double %10, %14
%16 = fcmp ult double %15, %1
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = add nsw i64 %9, -1
%19 = icmp sgt i64 %9, 1
br i1 %19, label %8, label %22
20: ; preds = %8
%21 = trunc i64 %9 to i32
br label %22
22: ; preds = %17, %20, %4
%23 = phi i32 [ %0, %4 ], [ %21, %20 ], [ 0, %17 ]
ret i32 %23
}