#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 advect_sample(double const *const, int const, double, double);
void C_apply_advection(double *d, const double *const d0,
                       const unsigned char *bound, int *advect_indexes,
                       double *advect_lerps, const int Nx, const int Ny) {
  int vyidx = Nx * Ny;
  int x, y, idx, iidx;
#pragma omp for schedule(auto)
  for (x = 0; x < Nx; ++x) {
    for (y = 0; y < Ny; ++y) {
      idx = y + x * Ny;
      if (!bound[idx]) {
        iidx = advect_indexes[vyidx + idx] + advect_indexes[idx] * Ny;
        d[0 + idx] = advect_sample(d0 + iidx, Ny, advect_lerps[idx],
                                   advect_lerps[vyidx + idx]);
      } else {
        d[0 + idx] *= 0.9;
      }
    }
  }
}


x86 assembly (clang, -O0):
<C_apply_advection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
imul   0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    123a <C_apply_advection+0x12a>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1227 <C_apply_advection+0x117>
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
imul   0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11f5 <C_apply_advection+0xe5>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x20(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
imul   0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    0x10(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1030 <advect_sample@plt>
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1214 <C_apply_advection+0x104>
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  0xdf6(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1219 <C_apply_advection+0x109>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1157 <C_apply_advection+0x47>
jmp    122c <C_apply_advection+0x11c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1144 <C_apply_advection+0x34>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<C_apply_advection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rsi,0x40(%rsp)
test   %r9d,%r9d
jle    1244 <C_apply_advection+0x134>
mov    %rdx,%r13
mov    %rdi,%rbx
mov    0x80(%rsp),%ecx
mov    %ecx,%eax
imul   %r9d,%eax
cltq
movslq %ecx,%rcx
mov    %r9d,%edx
mov    %rdx,0x30(%rsp)
mov    %ecx,%r12d
lea    0x0(,%rcx,8),%rdx
mov    %rdx,0x28(%rsp)
mov    %rcx,0x18(%rsp)
lea    0x0(,%rcx,4),%rcx
mov    %rcx,0x20(%rsp)
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rbp
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,8),%r14
xor    %edx,%edx
jmp    11c6 <C_apply_advection+0xb6>
xchg   %ax,%ax
mov    0x38(%rsp),%rdx
add    $0x1,%rdx
add    0x18(%rsp),%r13
mov    0x28(%rsp),%rax
add    %rax,%rbx
mov    0x20(%rsp),%rcx
add    %rcx,0x8(%rsp)
add    %rax,0x10(%rsp)
add    %rcx,%rbp
add    %rax,%r14
cmp    0x30(%rsp),%rdx
je     1244 <C_apply_advection+0x134>
mov    %rdx,0x38(%rsp)
cmpl   $0x0,0x80(%rsp)
jle    1190 <C_apply_advection+0x80>
xor    %r15d,%r15d
jmp    11fd <C_apply_advection+0xed>
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%r15,8),%xmm0
mulsd  0xe12(%rip),%xmm0
movsd  %xmm0,(%rbx,%r15,8)
add    $0x1,%r15
cmp    %r15,%r12
je     1190 <C_apply_advection+0x80>
cmpb   $0x0,0x0(%r13,%r15,1)
jne    11e0 <C_apply_advection+0xd0>
movslq 0x0(%rbp,%r15,4),%rax
mov    0x8(%rsp),%rcx
movslq (%rcx,%r15,4),%rcx
imul   0x18(%rsp),%rcx
add    %rax,%rcx
mov    0x40(%rsp),%rax
lea    (%rax,%rcx,8),%rdi
mov    0x10(%rsp),%rax
movsd  (%rax,%r15,8),%xmm0
movsd  (%r14,%r15,8),%xmm1
mov    0x80(%rsp),%esi
call   1030 <advect_sample@plt>
jmp    11ee <C_apply_advection+0xde>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @C_apply_advection(double* %0, double* %1, i8* %2, i32* %3, double* %4, i32 %5, i32 %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store double* %0, double** %8
store double* %1, double** %9
store i8* %2, i8** %10
store i32* %3, i32** %11
store double* %4, double** %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%20 = load i32, i32* %13
%21 = load i32, i32* %14
%22 = mul nsw i32 %20, %21
store i32 %22, i32* %15
store i32 0, i32* %16
br label %23
23: ; preds = %96, %7
%24 = load i32, i32* %16
%25 = load i32, i32* %13
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %99
27: ; preds = %23
store i32 0, i32* %17
br label %28
28: ; preds = %92, %27
%29 = load i32, i32* %17
%30 = load i32, i32* %14
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %95
32: ; preds = %28
%33 = load i32, i32* %17
%34 = load i32, i32* %16
%35 = load i32, i32* %14
%36 = mul nsw i32 %34, %35
%37 = add nsw i32 %33, %36
store i32 %37, i32* %18
%38 = load i8*, i8** %10
%39 = load i32, i32* %18
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %83, label %44
44: ; preds = %32
%45 = load i32*, i32** %11
%46 = load i32, i32* %15
%47 = load i32, i32* %18
%48 = add nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %45, i64 %49
%51 = load i32, i32* %50
%52 = load i32*, i32** %11
%53 = load i32, i32* %18
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = load i32, i32* %14
%58 = mul nsw i32 %56, %57
%59 = add nsw i32 %51, %58
store i32 %59, i32* %19
%60 = load double*, double** %9
%61 = load i32, i32* %19
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load i32, i32* %14
%65 = load double*, double** %12
%66 = load i32, i32* %18
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
%70 = load double*, double** %12
%71 = load i32, i32* %15
%72 = load i32, i32* %18
%73 = add nsw i32 %71, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %70, i64 %74
%76 = load double, double* %75
%77 = call double @advect_sample(double* %63, i32 %64, double %69, double %76)
%78 = load double*, double** %8
%79 = load i32, i32* %18
%80 = add nsw i32 0, %79
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %78, i64 %81
store double %77, double* %82
br label %91
83: ; preds = %32
%84 = load double*, double** %8
%85 = load i32, i32* %18
%86 = add nsw i32 0, %85
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %84, i64 %87
%89 = load double, double* %88
%90 = fmul double %89, 9.000000e-01
store double %90, double* %88
br label %91
91: ; preds = %83, %44
br label %92
92: ; preds = %91
%93 = load i32, i32* %17
%94 = add nsw i32 %93, 1
store i32 %94, i32* %17
br label %28
95: ; preds = %28
br label %96
96: ; preds = %95
%97 = load i32, i32* %16
%98 = add nsw i32 %97, 1
store i32 %98, i32* %16
br label %23
99: ; preds = %23
ret void
}

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