; LLVM IR from LingDong-/skeleton-tracing :: swig (trace_skeleton)

; 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._polyline_t = type { ptr, ptr, ptr, ptr, i32 }
%struct._point_t = type { i32, i32, 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: nounwind uwtable
define dso_local void @reverse_polyline(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %15

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._polyline_t, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %15, label %16

15:                                               ; preds = %10, %1
  br label %68

16:                                               ; preds = %10
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._polyline_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._polyline_t, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct._point_t, ptr %22, i32 0, i32 2
  store ptr %19, ptr %23, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._polyline_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  store ptr %26, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._point_t, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  store ptr %29, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._point_t, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  store ptr %32, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !16
  br label %33

33:                                               ; preds = %49, %16
  %34 = load i32, ptr %6, align 4, !tbaa !16
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._polyline_t, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = icmp slt i32 %34, %38
  br i1 %39, label %40, label %52

40:                                               ; preds = %33
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._point_t, ptr %42, i32 0, i32 2
  store ptr %41, ptr %43, align 8, !tbaa !14
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %44, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %45, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._point_t, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  store ptr %48, ptr %5, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %40
  %50 = load i32, ptr %6, align 4, !tbaa !16
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %6, align 4, !tbaa !16
  br label %33, !llvm.loop !17

52:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._polyline_t, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  store ptr %55, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._polyline_t, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._polyline_t, ptr %59, i32 0, i32 0
  store ptr %58, ptr %60, align 8, !tbaa !12
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._polyline_t, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !13
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._polyline_t, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  %67 = getelementptr inbounds %struct._point_t, ptr %66, i32 0, i32 2
  store ptr null, ptr %67, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %68

68:                                               ; preds = %52, %15
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !11, i64 32}
!10 = !{!"_polyline_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !6, i64 8}
!15 = !{!"_point_t", !11, i64 0, !11, i64 4, !6, i64 8}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 void @reverse_polyline(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %15, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i32 %4, 2
  br i1 %5, label %15, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %6 = load ptr, ptr %0, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %6, ptr %9, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %6, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = add nsw i32 %4, -2
  %13 = add nsw i32 %4, -1
  %xtraiter = and i32 %13, 7
  %14 = icmp ult i32 %12, 7
  br i1 %14, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %13, -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.026 = phi ptr [ %6, %.lr.ph.preheader.new ], [ %.021.6, %.lr.ph ]
  %.02224 = phi ptr [ %11, %.lr.ph.preheader.new ], [ %.021.7, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %.021.in = getelementptr inbounds i8, ptr %.02224, i64 8
  %.021 = load ptr, ptr %.021.in, align 8, !tbaa !13
  store ptr %.026, ptr %.021.in, align 8, !tbaa !13
  %.021.in.1 = getelementptr inbounds i8, ptr %.021, i64 8
  %.021.1 = load ptr, ptr %.021.in.1, align 8, !tbaa !13
  store ptr %.02224, ptr %.021.in.1, align 8, !tbaa !13
  %.021.in.2 = getelementptr inbounds i8, ptr %.021.1, i64 8
  %.021.2 = load ptr, ptr %.021.in.2, align 8, !tbaa !13
  store ptr %.021, ptr %.021.in.2, align 8, !tbaa !13
  %.021.in.3 = getelementptr inbounds i8, ptr %.021.2, i64 8
  %.021.3 = load ptr, ptr %.021.in.3, align 8, !tbaa !13
  store ptr %.021.1, ptr %.021.in.3, align 8, !tbaa !13
  %.021.in.4 = getelementptr inbounds i8, ptr %.021.3, i64 8
  %.021.4 = load ptr, ptr %.021.in.4, align 8, !tbaa !13
  store ptr %.021.2, ptr %.021.in.4, align 8, !tbaa !13
  %.021.in.5 = getelementptr inbounds i8, ptr %.021.4, i64 8
  %.021.5 = load ptr, ptr %.021.in.5, align 8, !tbaa !13
  store ptr %.021.3, ptr %.021.in.5, align 8, !tbaa !13
  %.021.in.6 = getelementptr inbounds i8, ptr %.021.5, i64 8
  %.021.6 = load ptr, ptr %.021.in.6, align 8, !tbaa !13
  store ptr %.021.4, ptr %.021.in.6, align 8, !tbaa !13
  %.021.in.7 = getelementptr inbounds i8, ptr %.021.6, i64 8
  %.021.7 = load ptr, ptr %.021.in.7, align 8, !tbaa !13
  store ptr %.021.5, ptr %.021.in.7, align 8, !tbaa !13
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !15

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.026.unr = phi ptr [ %6, %.lr.ph.preheader ], [ %.021.6, %.lr.ph ]
  %.02224.unr = phi ptr [ %11, %.lr.ph.preheader ], [ %.021.7, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.026.epil = phi ptr [ %.02224.epil, %.lr.ph.epil ], [ %.026.unr, %._crit_edge.unr-lcssa ]
  %.02224.epil = phi ptr [ %.021.epil, %.lr.ph.epil ], [ %.02224.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %.021.in.epil = getelementptr inbounds i8, ptr %.02224.epil, i64 8
  %.021.epil = load ptr, ptr %.021.in.epil, align 8, !tbaa !13
  store ptr %.026.epil, ptr %.021.in.epil, align 8, !tbaa !13
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  store ptr %8, ptr %0, align 8, !tbaa !11
  store ptr %6, ptr %7, align 8, !tbaa !12
  store ptr null, ptr %10, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %1, %2, %._crit_edge
  ret void
}

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" }

!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 32}
!6 = !{!"_polyline_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !7, i64 8}
!14 = !{!"_point_t", !10, i64 0, !10, i64 4, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass