; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (1365)

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

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

24:                                               ; preds = %35, %3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %39

27:                                               ; preds = %24
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bucket, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = icmp eq i32 %28, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  br label %39

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.bucket, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  store ptr %38, ptr %7, align 8, !tbaa !5
  br label %24, !llvm.loop !18

39:                                               ; preds = %33, %24
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %70

42:                                               ; preds = %39
  %43 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.bucket, ptr %45, i32 0, i32 2
  store i32 %44, ptr %46, align 4, !tbaa !20
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bucket, ptr %48, i32 0, i32 1
  store i32 %47, ptr %49, align 8, !tbaa !15
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.tablet, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.bucket, ptr %57, i32 0, i32 0
  store ptr %56, ptr %58, align 8, !tbaa !17
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.tablet, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds ptr, ptr %62, i64 %64
  store ptr %59, ptr %65, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.tablet, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !21
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %67, align 4, !tbaa !21
  br label %70

70:                                               ; preds = %42, %39
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.bucket, ptr %72, i32 0, i32 2
  store i32 %71, ptr %73, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 }
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 8}
!12 = !{!"tablet", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !10, i64 8}
!16 = !{!"bucket", !6, i64 0, !10, i64 8, !10, i64 12}
!17 = !{!16, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!16, !10, i64 12}
!21 = !{!12, !10, i64 4}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @tablet_set(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = call i32 %6(ptr noundef nonnull %4) #2
  %8 = load i32, ptr %0, align 8, !tbaa !12
  %9 = urem i32 %7, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = zext i32 %9 to i64
  %13 = getelementptr inbounds ptr, ptr %11, i64 %12
  %14 = load i32, ptr %4, align 4
  br label %15

15:                                               ; preds = %16, %3
  %.0.in = phi ptr [ %13, %3 ], [ %.0, %16 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %cond = icmp eq ptr %.0, null
  br i1 %cond, label %20, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %.0, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = icmp eq i32 %14, %18
  br i1 %19, label %.loopexit, label %15, !llvm.loop !17

20:                                               ; preds = %15
  %21 = call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #3
  %22 = getelementptr inbounds i8, ptr %21, i64 12
  store i32 %2, ptr %22, align 4, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %21, i64 8
  store i32 %14, ptr %23, align 8, !tbaa !15
  %24 = load ptr, ptr %13, align 8, !tbaa !14
  store ptr %24, ptr %21, align 8, !tbaa !20
  store ptr %21, ptr %13, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !21
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !21
  br label %.loopexit

.loopexit:                                        ; preds = %16, %20
  %.1 = phi ptr [ %21, %20 ], [ %.0, %16 ]
  %28 = getelementptr inbounds i8, ptr %.1, i64 12
  store i32 %2, ptr %28, align 4, !tbaa !19
  ret void
}

attributes #0 = { 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 #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 }
attributes #3 = { 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, !11, i64 8}
!10 = !{!"tablet", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"bucket", !11, i64 0, !6, i64 8, !6, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!16, !6, i64 12}
!20 = !{!16, !11, i64 0}
!21 = !{!10, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass