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

@W = external dso_local global i32, align 4
@polylines = external dso_local global ptr, align 8

; 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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @pop_point() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = load ptr, ptr @polylines, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %8, label %7

7:                                                ; preds = %0
  store i32 -1, ptr %1, align 4
  br label %50

8:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %9 = load ptr, ptr @polylines, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._polyline_t, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._point_t, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = load i32, ptr @W, align 4, !tbaa !14
  %16 = mul nsw i32 %14, %15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._point_t, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = add nsw i32 %16, %19
  store i32 %20, ptr %3, align 4, !tbaa !14
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._point_t, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %35

25:                                               ; preds = %8
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._point_t, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = load ptr, ptr @polylines, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._polyline_t, ptr %29, i32 0, i32 0
  store ptr %28, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr @polylines, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._polyline_t, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %32, align 8, !tbaa !17
  br label %47

35:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %36 = load ptr, ptr @polylines, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._polyline_t, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  store ptr %38, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._polyline_t, ptr %42, i32 0, i32 2
  store ptr null, ptr %43, align 8, !tbaa !19
  br label %44

44:                                               ; preds = %41, %35
  %45 = load ptr, ptr @polylines, align 8, !tbaa !5
  call void @free(ptr noundef %45) #3
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %46, ptr @polylines, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %47

47:                                               ; preds = %44, %25
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %48) #3
  %49 = load i32, ptr %3, align 4, !tbaa !14
  store i32 %49, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %50

50:                                               ; preds = %47, %7
  %51 = load i32, ptr %1, align 4
  ret i32 %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #3 = { 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, !6, i64 0}
!10 = !{!"_polyline_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"_point_t", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !11, i64 0}
!16 = !{!13, !6, i64 8}
!17 = !{!10, !11, i64 32}
!18 = !{!10, !6, i64 24}
!19 = !{!10, !6, i64 16}


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

@W = external dso_local local_unnamed_addr global i32, align 4
@polylines = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local i32 @pop_point() local_unnamed_addr #1 {
  %1 = load ptr, ptr @polylines, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %24, label %2

2:                                                ; preds = %0
  %3 = load ptr, ptr %1, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !12
  %6 = load i32, ptr @W, align 4, !tbaa !14
  %7 = mul nsw i32 %6, %5
  %8 = load i32, ptr %3, align 8, !tbaa !15
  %9 = add nsw i32 %7, %8
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %.not12 = icmp eq ptr %11, null
  br i1 %.not12, label %17, label %12

12:                                               ; preds = %2
  store ptr %11, ptr %1, align 8, !tbaa !9
  %13 = load ptr, ptr @polylines, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 32
  %15 = load i32, ptr %14, align 8, !tbaa !17
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %14, align 8, !tbaa !17
  br label %23

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %1, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %.not13 = icmp eq ptr %19, null
  br i1 %.not13, label %22, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %19, i64 16
  store ptr null, ptr %21, align 8, !tbaa !19
  br label %22

22:                                               ; preds = %20, %17
  tail call void @free(ptr noundef nonnull %1) #2
  store ptr %19, ptr @polylines, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %22, %12
  tail call void @free(ptr noundef nonnull %3) #2
  br label %24

24:                                               ; preds = %0, %23
  %.0 = phi i32 [ %9, %23 ], [ -1, %0 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn 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, !6, i64 0}
!10 = !{!"_polyline_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"_point_t", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !11, i64 0}
!16 = !{!13, !6, i64 8}
!17 = !{!10, !11, i64 32}
!18 = !{!10, !6, i64 24}
!19 = !{!10, !6, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass