; LLVM IR from drohmer/cgp :: library/cgp/11_mesh/mesh/mesh.ll (ZN3cgp4mesh17flip_connectivityEv)

; 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.cgp::numarray_stack.16" = type { i32, i32, i32 }
%"struct.cgp::mesh" = type { %"struct.cgp::numarray", %"struct.cgp::numarray", %"struct.cgp::numarray", %"struct.cgp::numarray.0", %"struct.cgp::numarray.6" }
%"struct.cgp::numarray" = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<cgp::numarray_stack<float, 3>, std::allocator<cgp::numarray_stack<float, 3>>>::_Vector_impl" }
%"struct.std::_Vector_base<cgp::numarray_stack<float, 3>, std::allocator<cgp::numarray_stack<float, 3>>>::_Vector_impl" = type { %"struct.std::_Vector_base<cgp::numarray_stack<float, 3>, std::allocator<cgp::numarray_stack<float, 3>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<cgp::numarray_stack<float, 3>, std::allocator<cgp::numarray_stack<float, 3>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.cgp::numarray.0" = type { %"class.std::vector.1" }
%"class.std::vector.1" = type { %"struct.std::_Vector_base.2" }
%"struct.std::_Vector_base.2" = type { %"struct.std::_Vector_base<cgp::numarray_stack<float, 2>, std::allocator<cgp::numarray_stack<float, 2>>>::_Vector_impl" }
%"struct.std::_Vector_base<cgp::numarray_stack<float, 2>, std::allocator<cgp::numarray_stack<float, 2>>>::_Vector_impl" = type { %"struct.std::_Vector_base<cgp::numarray_stack<float, 2>, std::allocator<cgp::numarray_stack<float, 2>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<cgp::numarray_stack<float, 2>, std::allocator<cgp::numarray_stack<float, 2>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.cgp::numarray.6" = type { %"class.std::vector.7" }
%"class.std::vector.7" = type { %"struct.std::_Vector_base.8" }
%"struct.std::_Vector_base.8" = type { %"struct.std::_Vector_base<cgp::numarray_stack<unsigned int, 3>, std::allocator<cgp::numarray_stack<unsigned int, 3>>>::_Vector_impl" }
%"struct.std::_Vector_base<cgp::numarray_stack<unsigned int, 3>, std::allocator<cgp::numarray_stack<unsigned int, 3>>>::_Vector_impl" = type { %"struct.std::_Vector_base<cgp::numarray_stack<unsigned int, 3>, std::allocator<cgp::numarray_stack<unsigned int, 3>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<cgp::numarray_stack<unsigned int, 3>, std::allocator<cgp::numarray_stack<unsigned int, 3>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3cgp8numarrayINS_14numarray_stackIjLi3EEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3cgp14numarray_stackIjLi3EEC2ERKjS3_S3_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(120) ptr @_ZN3cgp4mesh17flip_connectivityEv(ptr noundef nonnull align 8 dereferenceable(120) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %"struct.cgp::numarray_stack.16", align 4
  %6 = alloca %"struct.cgp::numarray_stack.16", align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %8 = getelementptr inbounds %"struct.cgp::mesh", ptr %7, i32 0, i32 4
  %9 = call noundef i32 @_ZNK3cgp8numarrayINS_14numarray_stackIjLi3EEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = sext i32 %9 to i64
  store i64 %10, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %28, %1
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %31

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #4
  %17 = getelementptr inbounds %"struct.cgp::mesh", ptr %7, i32 0, i32 4
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = trunc i64 %18 to i32
  %20 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3cgp8numarrayINS_14numarray_stackIjLi3EEEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %17, i32 noundef %19)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %20, i64 12, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #4
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef 1)
  %22 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef 0)
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef 2)
  call void @_ZN3cgp14numarray_stackIjLi3EEC2ERKjS3_S3_(ptr noundef nonnull align 4 dereferenceable(12) %6, ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %22, ptr noundef nonnull align 4 dereferenceable(4) %23)
  %24 = getelementptr inbounds %"struct.cgp::mesh", ptr %7, i32 0, i32 4
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = trunc i64 %25 to i32
  %27 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3cgp8numarrayINS_14numarray_stackIjLi3EEEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %24, i32 noundef %26)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %27, ptr align 4 %6, i64 12, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #4
  br label %28

28:                                               ; preds = %16
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = add i64 %29, 1
  store i64 %30, ptr %4, align 8, !tbaa !9
  br label %11, !llvm.loop !14

31:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %7
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN3cgp8numarrayINS_14numarray_stackIjLi3EEEEixEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%"struct.cgp::numarray_stack.16" = type { i32, i32, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3cgp8numarrayINS_14numarray_stackIjLi3EEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3cgp14numarray_stackIjLi3EEC2ERKjS3_S3_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(120) ptr @_ZN3cgp4mesh17flip_connectivityEv(ptr noundef nonnull returned align 8 dereferenceable(120) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %"struct.cgp::numarray_stack.16", align 4
  %3 = alloca %"struct.cgp::numarray_stack.16", align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = tail call noundef i32 @_ZNK3cgp8numarrayINS_14numarray_stackIjLi3EEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = sext i32 %5 to i64
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret ptr %0

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.05 = phi i64 [ %13, %.lr.ph ], [ 0, %1 ]
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %2) #4
  %7 = trunc i64 %.05 to i32
  %8 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3cgp8numarrayINS_14numarray_stackIjLi3EEEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %4, i32 noundef %7)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %2, ptr noundef nonnull align 4 dereferenceable(12) %8, i64 12, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #4
  %9 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %2, i32 noundef 1)
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %2, i32 noundef 0)
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3cgp14numarray_stackIjLi3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %2, i32 noundef 2)
  call void @_ZN3cgp14numarray_stackIjLi3EEC2ERKjS3_S3_(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %12 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3cgp8numarrayINS_14numarray_stackIjLi3EEEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %4, i32 noundef %7)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %12, ptr noundef nonnull align 4 dereferenceable(12) %3, i64 12, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %2) #4
  %13 = add nuw i64 %.05, 1
  %exitcond.not = icmp eq i64 %13, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN3cgp8numarrayINS_14numarray_stackIjLi3EEEEixEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 #4 = { 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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass