; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (ohtbl)

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

@vacated = external hidden global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ohtbl_init(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = mul i64 %17, 8
  %19 = call noalias ptr @malloc(i64 noundef %18) #4
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.OHTbl_, ptr %20, i32 0, i32 7
  store ptr %19, ptr %21, align 8, !tbaa !11
  %22 = icmp eq ptr %19, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %6
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %61

24:                                               ; preds = %6
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.OHTbl_, ptr %26, i32 0, i32 0
  store i32 %25, ptr %27, align 8, !tbaa !13
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %41, %24
  %29 = load i32, ptr %14, align 4, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.OHTbl_, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %34, label %44

34:                                               ; preds = %28
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.OHTbl_, ptr %35, i32 0, i32 7
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %14, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %37, i64 %39
  store ptr null, ptr %40, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %14, align 4, !tbaa !9
  br label %28, !llvm.loop !14

44:                                               ; preds = %28
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.OHTbl_, ptr %45, i32 0, i32 1
  store ptr @vacated, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.OHTbl_, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !17
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.OHTbl_, ptr %51, i32 0, i32 3
  store ptr %50, ptr %52, align 8, !tbaa !18
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.OHTbl_, ptr %54, i32 0, i32 4
  store ptr %53, ptr %55, align 8, !tbaa !19
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.OHTbl_, ptr %57, i32 0, i32 5
  store ptr %56, ptr %58, align 8, !tbaa !20
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.OHTbl_, ptr %59, i32 0, i32 6
  store i32 0, ptr %60, align 8, !tbaa !21
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %61

61:                                               ; preds = %44, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %62 = load i32, ptr %7, align 4
  ret i32 %62
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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 = { 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 #3 = { nounwind }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 56}
!12 = !{!"OHTbl_", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !6, i64 56}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !6, i64 24}
!19 = !{!12, !6, i64 32}
!20 = !{!12, !6, i64 40}
!21 = !{!12, !10, i64 48}


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

@vacated = external hidden global i8, align 1

; Function Attrs: nofree nounwind memory(write, argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local range(i32 -1, 1) i32 @ohtbl_init(ptr nocapture noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = sext i32 %1 to i64
  %8 = shl nsw i64 %7, 3
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #2
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %9, ptr %10, align 8, !tbaa !5
  %11 = icmp eq ptr %9, null
  br i1 %11, label %31, label %12

12:                                               ; preds = %6
  store i32 %1, ptr %0, align 8, !tbaa !11
  %13 = icmp sgt i32 %1, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %12
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %14 = icmp ult i32 %1, 4
  br i1 %14, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv
  store ptr null, ptr %16, align 8, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv.next
  store ptr null, ptr %18, align 8, !tbaa !12
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv.next.1
  store ptr null, ptr %20, align 8, !tbaa !12
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds ptr, ptr %21, i64 %indvars.iv.next.2
  store ptr null, ptr %22, align 8, !tbaa !12
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.epil
  store ptr null, ptr %24, align 8, !tbaa !12
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !15

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %12
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr @vacated, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %2, ptr %26, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %3, ptr %27, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %4, ptr %28, align 8, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %5, ptr %29, align 8, !tbaa !21
  %30 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 0, ptr %30, align 8, !tbaa !22
  br label %31

31:                                               ; preds = %6, %._crit_edge
  %.019 = phi i32 [ 0, %._crit_edge ], [ -1, %6 ]
  ret i32 %.019
}

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

attributes #0 = { nofree nounwind memory(write, argmem: readwrite, inaccessiblemem: readwrite) 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 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 #2 = { 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, !10, i64 56}
!6 = !{!"OHTbl_", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !10, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = !{!6, !10, i64 8}
!18 = !{!6, !10, i64 16}
!19 = !{!6, !10, i64 24}
!20 = !{!6, !10, i64 32}
!21 = !{!6, !10, i64 40}
!22 = !{!6, !7, i64 48}


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