#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 */
float fmax(float, float);
int vector_max(float *r, float *a, int n) {
  *r = *a;
  for (int i = 1; i < n; i++)
    *r = fmax(*r, a[i]);
  return 1;
}


x86 assembly (clang, -O0):
<vector_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1176 <vector_max+0x66>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
call   1030 <fmax@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <vector_max+0x2a>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_max>:
movss  (%rsi),%xmm1
movss  %xmm1,(%rdi)
cmp    $0x2,%edx
jl     11bc <vector_max+0xbc>
mov    %edx,%r8d
add    $0xffffffffffffffff,%r8
mov    $0x1,%ecx
cmp    $0x2,%edx
jne    1127 <vector_max+0x27>
movaps %xmm1,%xmm0
jmp    1195 <vector_max+0x95>
mov    %r8,%rdx
and    $0xfffffffffffffffe,%rdx
neg    %rdx
mov    $0x1,%ecx
movaps %xmm1,%xmm0
nopl   0x0(%rax)
movss  (%rsi,%rcx,4),%xmm2
cmpunordss %xmm0,%xmm0
movaps %xmm0,%xmm3
andps  %xmm2,%xmm3
maxss  %xmm1,%xmm2
andnps %xmm2,%xmm0
orps   %xmm3,%xmm0
movss  %xmm0,(%rdi)
movss  0x4(%rsi,%rcx,4),%xmm1
movaps %xmm1,%xmm2
maxss  %xmm0,%xmm2
cmpunordss %xmm0,%xmm0
movaps %xmm0,%xmm3
andnps %xmm2,%xmm3
andps  %xmm1,%xmm0
orps   %xmm3,%xmm0
movss  %xmm0,(%rdi)
lea    (%rdx,%rcx,1),%rax
add    $0x2,%rax
add    $0x2,%rcx
movaps %xmm0,%xmm1
cmp    $0x1,%rax
jne    1140 <vector_max+0x40>
test   $0x1,%r8b
je     11bc <vector_max+0xbc>
movss  (%rsi,%rcx,4),%xmm1
movaps %xmm0,%xmm2
cmpunordss %xmm0,%xmm2
movaps %xmm2,%xmm3
andps  %xmm1,%xmm3
maxss  %xmm0,%xmm1
andnps %xmm1,%xmm2
orps   %xmm3,%xmm2
movss  %xmm2,(%rdi)
mov    $0x1,%eax
ret

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

LLVM IR (-O2):
define i32 @vector_max(float* nocapture %0, float* nocapture %1, i32 %2) {
%4 = load float, float* %1
store float %4, float* %0
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = zext i32 %2 to i64
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 1
%10 = icmp eq i32 %2, 2
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = and i64 %8, -2
br label %22
13: ; preds = %22, %6
%14 = phi float [ %4, %6 ], [ %32, %22 ]
%15 = phi i64 [ 1, %6 ], [ %33, %22 ]
%16 = icmp eq i64 %9, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = getelementptr inbounds float, float* %1, i64 %15
%19 = load float, float* %18
%20 = tail call nsz float @llvm.maxnum.f32(float %14, float %19)
store float %20, float* %0
br label %21
21: ; preds = %17, %13, %3
ret i32 1
22: ; preds = %22, %11
%23 = phi float [ %4, %11 ], [ %32, %22 ]
%24 = phi i64 [ 1, %11 ], [ %33, %22 ]
%25 = phi i64 [ 0, %11 ], [ %34, %22 ]
%26 = getelementptr inbounds float, float* %1, i64 %24
%27 = load float, float* %26
%28 = tail call nsz float @llvm.maxnum.f32(float %23, float %27)
store float %28, float* %0
%29 = add nuw nsw i64 %24, 1
%30 = getelementptr inbounds float, float* %1, i64 %29
%31 = load float, float* %30
%32 = tail call nsz float @llvm.maxnum.f32(float %28, float %31)
store float %32, float* %0
%33 = add nuw nsw i64 %24, 2
%34 = add i64 %25, 2
%35 = icmp eq i64 %34, %12
br i1 %35, label %13, label %22
}