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

; 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, i8, 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, i8 noundef signext %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %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 i8 %1, ptr %5, align 1, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !10
  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 !12
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = call i32 %11(i8 noundef signext %12)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.tablet, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = urem i32 %13, %16
  store i32 %17, ptr %8, align 4, !tbaa !10
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.tablet, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i32, ptr %8, align 4, !tbaa !10
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  store ptr %24, ptr %7, align 8, !tbaa !5
  br label %25

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

28:                                               ; preds = %25
  %29 = load i8, ptr %5, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.bucket, ptr %31, i32 0, i32 1
  %33 = load i8, ptr %32, align 8, !tbaa !16
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %30, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %28
  br label %42

37:                                               ; preds = %28
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.bucket, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  store ptr %41, ptr %7, align 8, !tbaa !5
  br label %25, !llvm.loop !19

42:                                               ; preds = %36, %25
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %73

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

73:                                               ; preds = %45, %42
  %74 = load i32, ptr %6, align 4, !tbaa !10
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.bucket, ptr %75, i32 0, i32 2
  store i32 %74, ptr %76, align 4, !tbaa !21
  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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"tablet", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!14 = !{!13, !11, i64 0}
!15 = !{!13, !6, i64 16}
!16 = !{!17, !7, i64 8}
!17 = !{!"bucket", !6, i64 0, !7, i64 8, !11, i64 12}
!18 = !{!17, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!17, !11, i64 12}
!22 = !{!13, !11, 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, i8 noundef signext %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 %5(i8 noundef signext %1) #2
  %7 = load i32, ptr %0, align 8, !tbaa !11
  %8 = urem i32 %6, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = zext i32 %8 to i64
  %12 = getelementptr inbounds ptr, ptr %10, i64 %11
  br label %13

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

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

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

.loopexit:                                        ; preds = %14, %18
  %.1 = phi ptr [ %19, %18 ], [ %.0, %14 ]
  %26 = getelementptr inbounds i8, ptr %.1, i64 12
  store i32 %2, ptr %26, align 4, !tbaa !18
  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, !10, i64 8}
!6 = !{!"tablet", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!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 = !{!6, !10, i64 16}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !8, i64 8}
!15 = !{!"bucket", !10, i64 0, !8, i64 8, !7, i64 12}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!15, !7, i64 12}
!19 = !{!15, !10, i64 0}
!20 = !{!6, !7, i64 4}


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