; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/sglib_dllist (dllist)

; 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.sglib_dllist_iterator = type { ptr, ptr, ptr, ptr, ptr }
%struct.dllist = type { i32, ptr, ptr }

@array = external dso_local global [100 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @sglib_dllist_add(ptr noundef, ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_get_first(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_get_last(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @sglib_dllist_sort(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_it_next(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_it_init(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_sg_dllist() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.sglib_dllist_iterator, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store volatile i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store ptr null, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %19, %0
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 100
  br i1 %9, label %10, label %22

10:                                               ; preds = %7
  %11 = call ptr @malloc_beebs(i64 noundef 24)
  store ptr %11, ptr %2, align 8, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x i32], ptr @array, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.dllist, ptr %16, i32 0, i32 0
  store i32 %15, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  call void @sglib_dllist_add(ptr noundef %4, ptr noundef %18)
  br label %19

19:                                               ; preds = %10
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %6, align 4, !tbaa !5
  br label %7, !llvm.loop !13

22:                                               ; preds = %7
  call void @sglib_dllist_sort(ptr noundef %4)
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = call ptr @sglib_dllist_get_first(ptr noundef %23)
  store ptr %24, ptr %3, align 8, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = call ptr @sglib_dllist_get_first(ptr noundef %25)
  store ptr %26, ptr %2, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %37, %22
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %41

30:                                               ; preds = %27
  %31 = load ptr, ptr %3, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.dllist, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %2, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.dllist, ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 8, !tbaa !11
  %36 = load ptr, ptr %2, align 8, !tbaa !9
  store ptr %36, ptr %3, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %30
  %38 = load ptr, ptr %2, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.dllist, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  store ptr %40, ptr %2, align 8, !tbaa !9
  br label %27, !llvm.loop !16

41:                                               ; preds = %27
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = call ptr @sglib_dllist_get_last(ptr noundef %42)
  store ptr %43, ptr %2, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %54, %41
  %45 = load ptr, ptr %2, align 8, !tbaa !9
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %58

47:                                               ; preds = %44
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.dllist, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %2, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.dllist, ptr %51, i32 0, i32 0
  store i32 %50, ptr %52, align 8, !tbaa !11
  %53 = load ptr, ptr %2, align 8, !tbaa !9
  store ptr %53, ptr %3, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %47
  %55 = load ptr, ptr %2, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.dllist, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  store ptr %57, ptr %2, align 8, !tbaa !9
  br label %44, !llvm.loop !18

58:                                               ; preds = %44
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = call ptr @sglib_dllist_it_init(ptr noundef %5, ptr noundef %59)
  store ptr %60, ptr %2, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %71, %58
  %62 = load ptr, ptr %2, align 8, !tbaa !9
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %73

64:                                               ; preds = %61
  %65 = load ptr, ptr %2, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.dllist, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !11
  %68 = load volatile i32, ptr %1, align 4, !tbaa !5
  %69 = add nsw i32 %68, %67
  store volatile i32 %69, ptr %1, align 4, !tbaa !5
  %70 = load ptr, ptr %2, align 8, !tbaa !9
  call void @free_beebs(ptr noundef %70)
  br label %71

71:                                               ; preds = %64
  %72 = call ptr @sglib_dllist_it_next(ptr noundef %5)
  store ptr %72, ptr %2, align 8, !tbaa !9
  br label %61, !llvm.loop !19

73:                                               ; preds = %61
  %74 = load volatile i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 40, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 %74
}

; Function Attrs: nounwind uwtable
declare hidden ptr @malloc_beebs(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @free_beebs(ptr noundef) #0

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 = !{!"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 = !{!12, !6, i64 0}
!12 = !{!"dllist", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 8}
!16 = distinct !{!16, !14}
!17 = !{!12, !10, i64 16}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


; 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.sglib_dllist_iterator = type { ptr, ptr, ptr, ptr, ptr }

@array = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @sglib_dllist_add(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_get_first(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_get_last(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @sglib_dllist_sort(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_it_next(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_dllist_it_init(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_sg_dllist() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.sglib_dllist_iterator, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1)
  store volatile i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #2
  store ptr null, ptr %2, align 8, !tbaa !9
  br label %4

4:                                                ; preds = %0, %4
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %4 ]
  %5 = call ptr @malloc_beebs(i64 noundef 24)
  %6 = getelementptr inbounds [100 x i32], ptr @array, i64 0, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %7, ptr %5, align 8, !tbaa !11
  call void @sglib_dllist_add(ptr noundef nonnull %2, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond.not, label %8, label %4, !llvm.loop !13

8:                                                ; preds = %4
  call void @sglib_dllist_sort(ptr noundef nonnull %2)
  %9 = load ptr, ptr %2, align 8, !tbaa !9
  %10 = call ptr @sglib_dllist_get_first(ptr noundef %9)
  %11 = load ptr, ptr %2, align 8, !tbaa !9
  %12 = call ptr @sglib_dllist_get_first(ptr noundef %11)
  %.not25 = icmp eq ptr %12, null
  br i1 %.not25, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %8
  %.pre = load i32, ptr %10, align 8, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.02026 = phi ptr [ %14, %.lr.ph ], [ %12, %.lr.ph.preheader ]
  store i32 %.pre, ptr %.02026, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %.02026, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %8
  %.019.lcssa = phi ptr [ %10, %8 ], [ %.02026, %.lr.ph ]
  %15 = load ptr, ptr %2, align 8, !tbaa !9
  %16 = call ptr @sglib_dllist_get_last(ptr noundef %15)
  %.not2228 = icmp eq ptr %16, null
  br i1 %.not2228, label %._crit_edge33, label %.lr.ph32.preheader

.lr.ph32.preheader:                               ; preds = %._crit_edge
  %.pre40 = load i32, ptr %.019.lcssa, align 8, !tbaa !11
  br label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %.12129 = phi ptr [ %18, %.lr.ph32 ], [ %16, %.lr.ph32.preheader ]
  store i32 %.pre40, ptr %.12129, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %.12129, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %.not22 = icmp eq ptr %18, null
  br i1 %.not22, label %._crit_edge33, label %.lr.ph32, !llvm.loop !18

._crit_edge33:                                    ; preds = %.lr.ph32, %._crit_edge
  %19 = load ptr, ptr %2, align 8, !tbaa !9
  %20 = call ptr @sglib_dllist_it_init(ptr noundef nonnull %3, ptr noundef %19)
  %.not2334 = icmp eq ptr %20, null
  br i1 %.not2334, label %._crit_edge38, label %.lr.ph37

.lr.ph37:                                         ; preds = %._crit_edge33, %.lr.ph37
  %.235 = phi ptr [ %23, %.lr.ph37 ], [ %20, %._crit_edge33 ]
  %21 = load i32, ptr %.235, align 8, !tbaa !11
  %.0..0..0..0.17 = load volatile i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %.0..0..0..0.17, %21
  store volatile i32 %22, ptr %1, align 4, !tbaa !5
  call void @free_beebs(ptr noundef nonnull %.235)
  %23 = call ptr @sglib_dllist_it_next(ptr noundef nonnull %3)
  %.not23 = icmp eq ptr %23, null
  br i1 %.not23, label %._crit_edge38, label %.lr.ph37, !llvm.loop !19

._crit_edge38:                                    ; preds = %.lr.ph37, %._crit_edge33
  %.0..0..0..0.18 = load volatile i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1)
  ret i32 %.0..0..0..0.18
}

; Function Attrs: nounwind uwtable
declare hidden ptr @malloc_beebs(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @free_beebs(ptr noundef) local_unnamed_addr #0

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 = { mustprogress 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 = !{!"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 = !{!12, !6, i64 0}
!12 = !{!"dllist", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 8}
!16 = distinct !{!16, !14}
!17 = !{!12, !10, i64 16}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


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