double polygon_area(int N, const double pos[N][2]) {
  double sum = 0.;
  for (int i = 0; i < N; i++) {
    const double p[2][2] = {
        {pos[(i + 0) % N][0], pos[(i + 0) % N][1]},
        {pos[(i + 1) % N][0], pos[(i + 1) % N][1]},
    };
    sum += 0.5 * (p[0][0] * p[1][1] - p[1][0] * p[0][1]);
  }
  return sum;
}


x86 assembly (clang, -O0):
<polygon_area>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1227 <polygon_area+0x127>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x0,%eax
cltd
idivl  -0x4(%rbp)
mov    -0x60(%rbp),%rax
movslq %edx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x0,%eax
cltd
idivl  -0x4(%rbp)
mov    -0x58(%rbp),%rax
movslq %edx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x4(%rbp)
mov    -0x50(%rbp),%rax
movslq %edx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x4(%rbp)
mov    -0x48(%rbp),%rax
movslq %edx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xdf4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111a <polygon_area+0x1a>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<polygon_area>:
test   %edi,%edi
jle    1178 <polygon_area+0x78>
mov    %edi,%edi
lea    0x8(%rsi),%rcx
neg    %rdi
xorpd  %xmm0,%xmm0
mov    $0x1,%edx
xor    %r8d,%r8d
movsd  0xedf(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  -0x8(%rcx),%xmm2
movsd  (%rcx),%xmm3
mov    %rdi,%rax
add    %rdx,%rax
mov    %rdx,%rax
cmove  %r8,%rax
shl    $0x4,%rax
mulsd  (%rsi,%rax,1),%xmm3
mulsd  0x8(%rsi,%rax,1),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0x10,%rcx
lea    (%rdi,%rdx,1),%rax
add    $0x1,%rax
add    $0x1,%rdx
cmp    $0x1,%rax
jne    1130 <polygon_area+0x30>
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @polygon_area(i32 %0, [2 x double]* %1) {
%3 = alloca i32
%4 = alloca [2 x double]*
%5 = alloca double
%6 = alloca i32
%7 = alloca [2 x [2 x double]]
store i32 %0, i32* %3
store [2 x double]* %1, [2 x double]** %4
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %10
10: ; preds = %74, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %77
14: ; preds = %10
%15 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %7, i64 0, i64 0
%16 = getelementptr inbounds [2 x double], [2 x double]* %15, i64 0, i64 0
%17 = load [2 x double]*, [2 x double]** %4
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 0
%20 = load i32, i32* %3
%21 = srem i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [2 x double], [2 x double]* %17, i64 %22
%24 = getelementptr inbounds [2 x double], [2 x double]* %23, i64 0, i64 0
%25 = load double, double* %24
store double %25, double* %16
%26 = getelementptr inbounds double, double* %16, i64 1
%27 = load [2 x double]*, [2 x double]** %4
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 0
%30 = load i32, i32* %3
%31 = srem i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2 x double], [2 x double]* %27, i64 %32
%34 = getelementptr inbounds [2 x double], [2 x double]* %33, i64 0, i64 1
%35 = load double, double* %34
store double %35, double* %26
%36 = getelementptr inbounds [2 x double], [2 x double]* %15, i64 1
%37 = getelementptr inbounds [2 x double], [2 x double]* %36, i64 0, i64 0
%38 = load [2 x double]*, [2 x double]** %4
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %3
%42 = srem i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [2 x double], [2 x double]* %38, i64 %43
%45 = getelementptr inbounds [2 x double], [2 x double]* %44, i64 0, i64 0
%46 = load double, double* %45
store double %46, double* %37
%47 = getelementptr inbounds double, double* %37, i64 1
%48 = load [2 x double]*, [2 x double]** %4
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %3
%52 = srem i32 %50, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [2 x double], [2 x double]* %48, i64 %53
%55 = getelementptr inbounds [2 x double], [2 x double]* %54, i64 0, i64 1
%56 = load double, double* %55
store double %56, double* %47
%57 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %7, i64 0, i64 0
%58 = getelementptr inbounds [2 x double], [2 x double]* %57, i64 0, i64 0
%59 = load double, double* %58
%60 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %7, i64 0, i64 1
%61 = getelementptr inbounds [2 x double], [2 x double]* %60, i64 0, i64 1
%62 = load double, double* %61
%63 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %7, i64 0, i64 1
%64 = getelementptr inbounds [2 x double], [2 x double]* %63, i64 0, i64 0
%65 = load double, double* %64
%66 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %7, i64 0, i64 0
%67 = getelementptr inbounds [2 x double], [2 x double]* %66, i64 0, i64 1
%68 = load double, double* %67
%69 = fmul double %65, %68
%70 = fneg double %69
%71 = call double @llvm.fmuladd.f64(double %59, double %62, double %70)
%72 = load double, double* %5
%73 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %71, double %72)
store double %73, double* %5
br label %74
74: ; preds = %14
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %6
br label %10
77: ; preds = %10
%78 = load double, double* %5
ret double %78
}

LLVM IR (-O2):
define double @polygon_area(i32 %0, [2 x double]* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %8
6: ; preds = %8, %2
%7 = phi double [ 0.000000e+00, %2 ], [ %26, %8 ]
ret double %7
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %15, %8 ]
%10 = phi double [ 0.000000e+00, %4 ], [ %26, %8 ]
%11 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %9, i64 0
%12 = load double, double* %11
%13 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %9, i64 1
%14 = load double, double* %13
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %5
%17 = and i64 %15, 4294967295
%18 = select i1 %16, i64 0, i64 %17
%19 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %18, i64 0
%20 = load double, double* %19
%21 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %18, i64 1
%22 = load double, double* %21
%23 = fneg double %20
%24 = fmul double %14, %23
%25 = tail call double @llvm.fmuladd.f64(double %12, double %22, double %24)
%26 = tail call double @llvm.fmuladd.f64(double %25, double 5.000000e-01, double %10)
%27 = icmp eq i64 %15, %5
br i1 %27, label %6, label %8
}