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

; 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.ilist = type { i32, ptr }
%struct.sglib_hashed_ilist_iterator = type { %struct.sglib_ilist_iterator, ptr, i32, ptr, ptr }
%struct.sglib_ilist_iterator = type { ptr, ptr, ptr, ptr }

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_hashed_ilist_find_member(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_hashed_ilist_it_next(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_hashed_ilist_it_init(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_sg_hashtable() #1 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.ilist, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.sglib_hashed_ilist_iterator, align 8
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 16, 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 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store volatile i32 0, ptr %7, align 4, !tbaa !5
  call void @sglib_hashed_ilist_init(ptr noundef @htab)
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %29, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 100
  br i1 %10, label %11, label %32

11:                                               ; preds = %8
  %12 = load i32, ptr %1, 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 = getelementptr inbounds %struct.ilist, ptr %2, i32 0, i32 0
  store i32 %15, ptr %16, align 8, !tbaa !9
  %17 = call ptr @sglib_hashed_ilist_find_member(ptr noundef @htab, ptr noundef %2)
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %28

19:                                               ; preds = %11
  %20 = call ptr @malloc_beebs(i64 noundef 16)
  store ptr %20, ptr %3, align 8, !tbaa !12
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i32], ptr @array, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !12
  %26 = getelementptr inbounds %struct.ilist, ptr %25, i32 0, i32 0
  store i32 %24, ptr %26, align 8, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !12
  call void @sglib_hashed_ilist_add(ptr noundef @htab, ptr noundef %27)
  br label %28

28:                                               ; preds = %19, %11
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !13

32:                                               ; preds = %8
  %33 = call ptr @sglib_hashed_ilist_it_init(ptr noundef %6, ptr noundef @htab)
  store ptr %33, ptr %5, align 8, !tbaa !12
  %34 = call ptr @sglib_hashed_ilist_it_init(ptr noundef %6, ptr noundef @htab)
  store ptr %34, ptr %4, align 8, !tbaa !12
  br label %35

35:                                               ; preds = %45, %32
  %36 = load ptr, ptr %4, align 8, !tbaa !12
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %47

38:                                               ; preds = %35
  %39 = load ptr, ptr %5, align 8, !tbaa !12
  %40 = getelementptr inbounds %struct.ilist, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !12
  %43 = getelementptr inbounds %struct.ilist, ptr %42, i32 0, i32 0
  store i32 %41, ptr %43, align 8, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !12
  store ptr %44, ptr %5, align 8, !tbaa !12
  br label %45

45:                                               ; preds = %38
  %46 = call ptr @sglib_hashed_ilist_it_next(ptr noundef %6)
  store ptr %46, ptr %4, align 8, !tbaa !12
  br label %35, !llvm.loop !15

47:                                               ; preds = %35
  %48 = call ptr @sglib_hashed_ilist_it_init(ptr noundef %6, ptr noundef @htab)
  store ptr %48, ptr %4, align 8, !tbaa !12
  br label %49

49:                                               ; preds = %59, %47
  %50 = load ptr, ptr %4, align 8, !tbaa !12
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %61

52:                                               ; preds = %49
  %53 = load ptr, ptr %4, align 8, !tbaa !12
  %54 = getelementptr inbounds %struct.ilist, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !9
  %56 = load volatile i32, ptr %7, align 4, !tbaa !5
  %57 = add nsw i32 %56, %55
  store volatile i32 %57, ptr %7, align 4, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !12
  call void @free_beebs(ptr noundef %58)
  br label %59

59:                                               ; preds = %52
  %60 = call ptr @sglib_hashed_ilist_it_next(ptr noundef %6)
  store ptr %60, ptr %4, align 8, !tbaa !12
  br label %49, !llvm.loop !16

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

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

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

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, !6, i64 0}
!10 = !{!"ilist", !6, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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.ilist = type { i32, ptr }
%struct.sglib_hashed_ilist_iterator = type { %struct.sglib_ilist_iterator, ptr, i32, ptr, ptr }
%struct.sglib_ilist_iterator = type { ptr, ptr, ptr, ptr }

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

; 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: nounwind uwtable
declare dso_local void @sglib_hashed_ilist_init(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @sglib_hashed_ilist_it_next(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_sg_hashtable() local_unnamed_addr #1 {
  %1 = alloca %struct.ilist, align 8
  %2 = alloca %struct.sglib_hashed_ilist_iterator, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3)
  store volatile i32 0, ptr %3, align 4, !tbaa !5
  tail call void @sglib_hashed_ilist_init(ptr noundef nonnull @htab)
  br label %4

4:                                                ; preds = %0, %12
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %12 ]
  %5 = getelementptr inbounds [100 x i32], ptr @array, i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %6, ptr %1, align 8, !tbaa !9
  %7 = call ptr @sglib_hashed_ilist_find_member(ptr noundef nonnull @htab, ptr noundef nonnull %1)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %12

9:                                                ; preds = %4
  %10 = call ptr @malloc_beebs(i64 noundef 16)
  %11 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %11, ptr %10, align 8, !tbaa !9
  call void @sglib_hashed_ilist_add(ptr noundef nonnull @htab, ptr noundef nonnull %10)
  br label %12

12:                                               ; preds = %4, %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond.not, label %13, label %4, !llvm.loop !12

13:                                               ; preds = %12
  %14 = call ptr @sglib_hashed_ilist_it_init(ptr noundef nonnull %2, ptr noundef nonnull @htab)
  %15 = call ptr @sglib_hashed_ilist_it_init(ptr noundef nonnull %2, ptr noundef nonnull @htab)
  %.not18 = icmp eq ptr %15, null
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.020 = phi ptr [ %.01419, %.lr.ph ], [ %14, %13 ]
  %.01419 = phi ptr [ %17, %.lr.ph ], [ %15, %13 ]
  %16 = load i32, ptr %.020, align 8, !tbaa !9
  store i32 %16, ptr %.01419, align 8, !tbaa !9
  %17 = call ptr @sglib_hashed_ilist_it_next(ptr noundef nonnull %2)
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %13
  %18 = call ptr @sglib_hashed_ilist_it_init(ptr noundef nonnull %2, ptr noundef nonnull @htab)
  %.not1621 = icmp eq ptr %18, null
  br i1 %.not1621, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %._crit_edge, %.lr.ph24
  %.122 = phi ptr [ %21, %.lr.ph24 ], [ %18, %._crit_edge ]
  %19 = load i32, ptr %.122, align 8, !tbaa !9
  %.0..0..0..0. = load volatile i32, ptr %3, align 4, !tbaa !5
  %20 = add nsw i32 %.0..0..0..0., %19
  store volatile i32 %20, ptr %3, align 4, !tbaa !5
  call void @free_beebs(ptr noundef nonnull %.122)
  %21 = call ptr @sglib_hashed_ilist_it_next(ptr noundef nonnull %2)
  %.not16 = icmp eq ptr %21, null
  br i1 %.not16, label %._crit_edge25, label %.lr.ph24, !llvm.loop !15

._crit_edge25:                                    ; preds = %.lr.ph24, %._crit_edge
  %.0..0..0..0.1 = load volatile i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #2
  ret i32 %.0..0..0..0.1
}

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

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

attributes #0 = { mustprogress 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, !6, i64 0}
!10 = !{!"ilist", !6, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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