; LLVM IR from NaokiHori/VerySimpleNSSolver :: src (exchange_halo)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.domain_t = type { double, double, i64, i64, double, double }

; Function Attrs: nounwind uwtable
define dso_local i32 @exchange_halo_x(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.domain_t, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %11, ptr %6, align 8, !tbaa !13
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.domain_t, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !14
  store i64 %14, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %47, %2
  %16 = load i64, ptr %8, align 8, !tbaa !13
  %17 = load i64, ptr %7, align 8, !tbaa !13
  %18 = add i64 %17, 1
  %19 = icmp ule i64 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %50

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i64, ptr %8, align 8, !tbaa !13
  %24 = getelementptr inbounds ptr, ptr %22, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !13
  %27 = getelementptr inbounds double, ptr %25, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %8, align 8, !tbaa !13
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 0
  store double %28, ptr %33, align 8, !tbaa !15
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %8, align 8, !tbaa !13
  %36 = getelementptr inbounds ptr, ptr %34, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %37, i64 1
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !13
  %42 = getelementptr inbounds ptr, ptr %40, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load i64, ptr %6, align 8, !tbaa !13
  %45 = add i64 %44, 1
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  store double %39, ptr %46, align 8, !tbaa !15
  br label %47

47:                                               ; preds = %21
  %48 = load i64, ptr %8, align 8, !tbaa !13
  %49 = add i64 %48, 1
  store i64 %49, ptr %8, align 8, !tbaa !13
  br label %15, !llvm.loop !16

50:                                               ; preds = %20
  store i32 0, ptr %3, align 4
  br label %52

51:                                               ; No predecessors!
  store i32 1, ptr %3, align 4
  br label %52

52:                                               ; preds = %51, %50
  %53 = load i32, ptr %3, align 4
  ret i32 %53
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 24}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @exchange_halo_x(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = add i64 %6, 2
  %umax = tail call i64 @llvm.umax.i64(i64 %7, i64 1)
  %xtraiter = and i64 %umax, 3
  %8 = icmp ult i64 %7, 4
  br i1 %8, label %.unr-lcssa, label %.new

.new:                                             ; preds = %2
  %unroll_iter = and i64 %umax, -4
  br label %17

.unr-lcssa:                                       ; preds = %17, %2
  %.015.unr = phi i64 [ 0, %2 ], [ %49, %17 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa, %.epil.preheader
  %.015.epil = phi i64 [ %16, %.epil.preheader ], [ %.015.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.unr-lcssa ]
  %9 = getelementptr inbounds ptr, ptr %1, i64 %.015.epil
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds double, ptr %10, i64 %4
  %12 = load double, ptr %11, align 8, !tbaa !14
  store double %12, ptr %10, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %10, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !14
  %15 = getelementptr i8, ptr %11, i64 8
  store double %14, ptr %15, align 8, !tbaa !14
  %16 = add nuw i64 %.015.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.epilog-lcssa, label %.epil.preheader, !llvm.loop !15

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  ret i32 0

17:                                               ; preds = %17, %.new
  %.015 = phi i64 [ 0, %.new ], [ %49, %17 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.3, %17 ]
  %18 = getelementptr inbounds ptr, ptr %1, i64 %.015
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds double, ptr %19, i64 %4
  %21 = load double, ptr %20, align 8, !tbaa !14
  store double %21, ptr %19, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %19, i64 8
  %23 = load double, ptr %22, align 8, !tbaa !14
  %24 = getelementptr i8, ptr %20, i64 8
  store double %23, ptr %24, align 8, !tbaa !14
  %25 = or disjoint i64 %.015, 1
  %26 = getelementptr inbounds ptr, ptr %1, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds double, ptr %27, i64 %4
  %29 = load double, ptr %28, align 8, !tbaa !14
  store double %29, ptr %27, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %27, i64 8
  %31 = load double, ptr %30, align 8, !tbaa !14
  %32 = getelementptr i8, ptr %28, i64 8
  store double %31, ptr %32, align 8, !tbaa !14
  %33 = or disjoint i64 %.015, 2
  %34 = getelementptr inbounds ptr, ptr %1, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = getelementptr inbounds double, ptr %35, i64 %4
  %37 = load double, ptr %36, align 8, !tbaa !14
  store double %37, ptr %35, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %35, i64 8
  %39 = load double, ptr %38, align 8, !tbaa !14
  %40 = getelementptr i8, ptr %36, i64 8
  store double %39, ptr %40, align 8, !tbaa !14
  %41 = or disjoint i64 %.015, 3
  %42 = getelementptr inbounds ptr, ptr %1, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = getelementptr inbounds double, ptr %43, i64 %4
  %45 = load double, ptr %44, align 8, !tbaa !14
  store double %45, ptr %43, align 8, !tbaa !14
  %46 = getelementptr inbounds i8, ptr %43, i64 8
  %47 = load double, ptr %46, align 8, !tbaa !14
  %48 = getelementptr i8, ptr %44, i64 8
  store double %47, ptr %48, align 8, !tbaa !14
  %49 = add nuw i64 %.015, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.unr-lcssa, label %17, !llvm.loop !17
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #1

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass