; LLVM IR from mrbid/CSGO_TENSOR_TRIGGER :: GOBOT15/LIBONNX (hmap)

; 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.hmap_t = type { ptr, %struct.list_head, i32, i32, ptr }
%struct.list_head = type { ptr, ptr }
%struct.hlist_head = type { ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @hmap_alloc(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 16
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 16, ptr %4, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %11, %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  %16 = and i32 %13, %15
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %12
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = call i32 @roundup_pow_of_two(i32 noundef %19)
  store i32 %20, ptr %4, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %12
  %22 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %22, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %66

26:                                               ; preds = %21
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = mul i64 8, %28
  %30 = call noalias ptr @malloc(i64 noundef %29) #6
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.hmap_t, ptr %31, i32 0, i32 0
  store ptr %30, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.hmap_t, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = icmp ne ptr %35, null
  br i1 %36, label %39, label %37

37:                                               ; preds = %26
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %38) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %66

39:                                               ; preds = %26
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %51, %39
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %54

44:                                               ; preds = %40
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.hmap_t, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.hlist_head, ptr %47, i64 %49
  call void @init_hlist_head(ptr noundef %50)
  br label %51

51:                                               ; preds = %44
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !5
  br label %40, !llvm.loop !14

54:                                               ; preds = %40
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.hmap_t, ptr %55, i32 0, i32 1
  call void @init_list_head(ptr noundef %56)
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.hmap_t, ptr %58, i32 0, i32 2
  store i32 %57, ptr %59, align 8, !tbaa !16
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.hmap_t, ptr %60, i32 0, i32 3
  store i32 0, ptr %61, align 4, !tbaa !17
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = load ptr, ptr %6, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.hmap_t, ptr %63, i32 0, i32 4
  store ptr %62, ptr %64, align 8, !tbaa !18
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %65, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %66

66:                                               ; preds = %54, %37, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %67 = load ptr, ptr %3, align 8
  ret ptr %67
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @roundup_pow_of_two(i32 noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @init_hlist_head(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @init_list_head(ptr noundef) #2

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

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 = { inlinehint 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 allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

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


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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @hmap_alloc(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %0, i32 16)
  %3 = tail call range(i32 0, 32) i32 @llvm.ctpop.i32(i32 %spec.store.select)
  %.not = icmp ult i32 %3, 2
  br i1 %.not, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call i32 @roundup_pow_of_two(i32 noundef %spec.store.select)
  br label %6

6:                                                ; preds = %4, %2
  %.022 = phi i32 [ %5, %4 ], [ %spec.store.select, %2 ]
  %7 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %.not24 = icmp eq ptr %7, null
  br i1 %.not24, label %19, label %8

8:                                                ; preds = %6
  %9 = sext i32 %.022 to i64
  %10 = shl nsw i64 %9, 3
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #5
  store ptr %11, ptr %7, align 8, !tbaa !5
  %.not25 = icmp eq ptr %11, null
  br i1 %.not25, label %13, label %.preheader

.preheader:                                       ; preds = %8
  %12 = icmp sgt i32 %.022, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %.022 to i64
  br label %.lr.ph

13:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %7) #6
  br label %19

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %14 = getelementptr inbounds %struct.hlist_head, ptr %11, i64 %indvars.iv
  tail call void @init_hlist_head(ptr noundef nonnull %14)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %15 = getelementptr inbounds i8, ptr %7, i64 8
  tail call void @init_list_head(ptr noundef nonnull %15)
  %16 = getelementptr inbounds i8, ptr %7, i64 24
  store i32 %.022, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %7, i64 28
  store i32 0, ptr %17, align 4, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %7, i64 32
  store ptr %1, ptr %18, align 8, !tbaa !16
  br label %19

19:                                               ; preds = %6, %._crit_edge, %13
  %.021 = phi ptr [ %7, %._crit_edge ], [ null, %13 ], [ null, %6 ]
  ret ptr %.021
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @roundup_pow_of_two(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #4

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 = { inlinehint 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"hmap_t", !7, i64 0, !10, i64 8, !11, i64 24, !11, i64 28, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"list_head", !7, i64 0, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !11, i64 24}
!15 = !{!6, !11, i64 28}
!16 = !{!6, !7, i64 32}


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