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

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

; 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 i32 @not_empty(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %13 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %13, ptr %10, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %49, %4
  %15 = load i32, ptr %10, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  store i32 2, ptr %11, align 4
  br label %52

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %22 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %22, ptr %12, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %43, %21
  %24 = load i32, ptr %12, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = add nsw i32 %25, %26
  %28 = icmp slt i32 %24, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  store i32 5, ptr %11, align 4
  br label %46

30:                                               ; preds = %23
  %31 = load ptr, ptr @im, align 8, !tbaa !9
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = load i32, ptr @W, align 4, !tbaa !5
  %34 = mul nsw i32 %32, %33
  %35 = load i32, ptr %12, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %31, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %30
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %46

42:                                               ; preds = %30
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %12, align 4, !tbaa !5
  br label %23, !llvm.loop !12

46:                                               ; preds = %41, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %47 = load i32, ptr %11, align 4
  switch i32 %47, label %52 [
    i32 5, label %48
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !5
  br label %14, !llvm.loop !14

52:                                               ; preds = %46, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %53 = load i32, ptr %11, align 4
  switch i32 %53, label %57 [
    i32 2, label %54
    i32 1, label %55
  ]

54:                                               ; preds = %52
  store i32 0, ptr %5, align 4
  br label %55

55:                                               ; preds = %54, %52
  %56 = load i32, ptr %5, align 4
  ret i32 %56

57:                                               ; preds = %52
  unreachable
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

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

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @not_empty(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add nsw i32 %3, %1
  %.not2127 = icmp sgt i32 %3, 0
  br i1 %.not2127, label %.preheader.lr.ph, label %.thread

.preheader.lr.ph:                                 ; preds = %4
  %.not1925 = icmp sgt i32 %2, 0
  %6 = load ptr, ptr @im, align 8
  br i1 %.not1925, label %.preheader.us.preheader, label %.thread

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %7 = load i32, ptr @W, align 4
  %8 = add nsw i32 %2, %0
  %9 = sext i32 %0 to i64
  %10 = sext i32 %8 to i64
  %11 = sext i32 %1 to i64
  %12 = sext i32 %5 to i64
  %13 = sext i32 %7 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv35 = phi i64 [ %11, %.preheader.us.preheader ], [ %indvars.iv.next36, %._crit_edge.us ]
  %14 = mul nsw i64 %indvars.iv35, %13
  %15 = getelementptr i8, ptr %6, i64 %14
  br label %17

16:                                               ; preds = %17
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %.not19.us = icmp slt i64 %indvars.iv.next, %10
  br i1 %.not19.us, label %17, label %._crit_edge.us, !llvm.loop !5

17:                                               ; preds = %.preheader.us, %16
  %indvars.iv = phi i64 [ %9, %.preheader.us ], [ %indvars.iv.next, %16 ]
  %18 = getelementptr i8, ptr %15, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !7
  %.not.us = icmp eq i8 %19, 0
  br i1 %.not.us, label %16, label %.thread

._crit_edge.us:                                   ; preds = %16
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, 1
  %.not21.us = icmp slt i64 %indvars.iv.next36, %12
  br i1 %.not21.us, label %.preheader.us, label %.thread, !llvm.loop !10

.thread:                                          ; preds = %._crit_edge.us, %17, %.preheader.lr.ph, %4
  %.not2124 = phi i32 [ 0, %4 ], [ 0, %.preheader.lr.ph ], [ 1, %17 ], [ 0, %._crit_edge.us ]
  ret i32 %.not2124
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass