#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*/ fabs(double);
double fmax(int /*<<< orphan*/, double);
double infinity_norm(double *error, int size) {
  double out = 0;
  int i;
  for (i = 0; i < size; ++i) {
    out = fmax(fabs(error[i]), out);
  }
  return out;
}


x86 assembly (clang, -O0):
<infinity_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117b <infinity_norm+0x5b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
movsd  -0x18(%rbp),%xmm0
call   1040 <fmax@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <infinity_norm+0x1e>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<infinity_norm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    114d <infinity_norm+0x2d>
mov    %rdi,%r12
mov    %esi,%r15d
lea    -0x1(%r15),%rax
mov    %r15d,%r14d
and    $0x3,%r14d
cmp    $0x3,%rax
jae    1155 <infinity_norm+0x35>
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    11dc <infinity_norm+0xbc>
xorps  %xmm0,%xmm0
jmp    1215 <infinity_norm+0xf5>
and    $0xfffffffc,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
xchg   %ax,%ax
movsd  %xmm0,(%rsp)
movsd  (%r12,%rbx,8),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
movsd  (%rsp),%xmm0
call   1040 <fmax@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%r12,%rbx,8),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
movsd  (%rsp),%xmm0
call   1040 <fmax@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%r12,%rbx,8),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
movsd  (%rsp),%xmm0
call   1040 <fmax@plt>
movsd  %xmm0,(%rsp)
movsd  0x18(%r12,%rbx,8),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
movsd  (%rsp),%xmm0
call   1040 <fmax@plt>
add    $0x4,%rbx
cmp    %rbx,%r15
jne    1160 <infinity_norm+0x40>
test   %r14,%r14
je     1215 <infinity_norm+0xf5>
lea    (%r12,%rbx,8),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%r15,%rbx,8),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
movsd  (%rsp),%xmm0
call   1040 <fmax@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11f0 <infinity_norm+0xd0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @infinity_norm(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %20, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load double*, double** %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %12, i64 %14
%16 = load double, double* %15
%17 = call i32 @fabs(double %16)
%18 = load double, double* %5
%19 = call double @fmax(i32 %17, double %18)
store double %19, double* %5
br label %20
20: ; preds = %11
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %7
23: ; preds = %7
%24 = load double, double* %5
ret double %24
}

LLVM IR (-O2):
define double @infinity_norm(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %53
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = add nsw i64 %5, -1
%7 = and i64 %5, 3
%8 = icmp ult i64 %6, 3
br i1 %8, label %37, label %9
9: ; preds = %4
%10 = and i64 %5, 4294967292
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %34, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %33, %11 ]
%14 = phi i64 [ 0, %9 ], [ %35, %11 ]
%15 = getelementptr inbounds double, double* %0, i64 %12
%16 = load double, double* %15
%17 = tail call i32 @fabs(double %16)
%18 = tail call double @fmax(i32 %17, double %13)
%19 = or i64 %12, 1
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = tail call i32 @fabs(double %21)
%23 = tail call double @fmax(i32 %22, double %18)
%24 = or i64 %12, 2
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = tail call i32 @fabs(double %26)
%28 = tail call double @fmax(i32 %27, double %23)
%29 = or i64 %12, 3
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
%32 = tail call i32 @fabs(double %31)
%33 = tail call double @fmax(i32 %32, double %28)
%34 = add nuw nsw i64 %12, 4
%35 = add i64 %14, 4
%36 = icmp eq i64 %35, %10
br i1 %36, label %37, label %11
37: ; preds = %11, %4
%38 = phi double [ undef, %4 ], [ %33, %11 ]
%39 = phi i64 [ 0, %4 ], [ %34, %11 ]
%40 = phi double [ 0.000000e+00, %4 ], [ %33, %11 ]
%41 = icmp eq i64 %7, 0
br i1 %41, label %53, label %42
42: ; preds = %37, %42
%43 = phi i64 [ %50, %42 ], [ %39, %37 ]
%44 = phi double [ %49, %42 ], [ %40, %37 ]
%45 = phi i64 [ %51, %42 ], [ 0, %37 ]
%46 = getelementptr inbounds double, double* %0, i64 %43
%47 = load double, double* %46
%48 = tail call i32 @fabs(double %47)
%49 = tail call double @fmax(i32 %48, double %44)
%50 = add nuw nsw i64 %43, 1
%51 = add i64 %45, 1
%52 = icmp eq i64 %51, %7
br i1 %52, label %53, label %42
53: ; preds = %37, %42, %2
%54 = phi double [ 0.000000e+00, %2 ], [ %38, %37 ], [ %49, %42 ]
ret double %54
}