; LLVM IR from davidar/c-hashtable :: hashtable_powers (create_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.hashtable = type { i32, ptr, i32, i32, i32, ptr, ptr }

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

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %77

15:                                               ; preds = %3
  br label %16

16:                                               ; preds = %20, %15
  %17 = load i32, ptr %10, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = shl i32 %21, 1
  store i32 %22, ptr %10, align 4, !tbaa !5
  br label %16, !llvm.loop !11

23:                                               ; preds = %16
  %24 = call noalias ptr @malloc(i64 noundef 48) #6
  store ptr %24, ptr %8, align 8, !tbaa !9
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = icmp eq ptr null, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %77

28:                                               ; preds = %23
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = zext i32 %29 to i64
  %31 = mul i64 8, %30
  %32 = call noalias ptr @malloc(i64 noundef %31) #6
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.hashtable, ptr %33, i32 0, i32 1
  store ptr %32, ptr %34, align 8, !tbaa !13
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.hashtable, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = icmp eq ptr null, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %28
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %40) #5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %77

41:                                               ; preds = %28
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %53, %41
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = icmp ult i32 %43, %44
  br i1 %45, label %46, label %56

46:                                               ; preds = %42
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.hashtable, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  store ptr null, ptr %52, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %46
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %9, align 4, !tbaa !5
  br label %42, !llvm.loop !15

56:                                               ; preds = %42
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.hashtable, ptr %58, i32 0, i32 0
  store i32 %57, ptr %59, align 8, !tbaa !16
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.hashtable, ptr %60, i32 0, i32 2
  store i32 0, ptr %61, align 8, !tbaa !17
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.hashtable, ptr %63, i32 0, i32 5
  store ptr %62, ptr %64, align 8, !tbaa !18
  %65 = load ptr, ptr %7, align 8, !tbaa !9
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.hashtable, ptr %66, i32 0, i32 6
  store ptr %65, ptr %67, align 8, !tbaa !19
  %68 = load i32, ptr %10, align 4, !tbaa !5
  %69 = uitofp i32 %68 to float
  %70 = fmul float %69, 0x3FE4CCCCC0000000
  %71 = fpext float %70 to double
  %72 = call double @llvm.ceil.f64(double %71)
  %73 = fptoui double %72 to i32
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.hashtable, ptr %74, i32 0, i32 3
  store i32 %73, ptr %75, align 4, !tbaa !20
  %76 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %76, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %77

77:                                               ; preds = %56, %39, %27, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %78 = load ptr, ptr %4, align 8
  ret ptr %78
}

; 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: nounwind
declare void @free(ptr noundef) #3

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

; 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 "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 }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 8}
!14 = !{!"hashtable", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !10, i64 32, !10, i64 40}
!15 = distinct !{!15, !12}
!16 = !{!14, !6, i64 0}
!17 = !{!14, !6, i64 16}
!18 = !{!14, !10, i64 32}
!19 = !{!14, !10, i64 40}
!20 = !{!14, !6, i64 20}


; 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: nounwind memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @create_hashtable(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp ugt i32 %0, -2147483648
  br i1 %4, label %25, label %.preheader27

.preheader27:                                     ; preds = %3, %.preheader27
  %.0 = phi i32 [ %6, %.preheader27 ], [ 1, %3 ]
  %5 = icmp ult i32 %.0, %0
  %6 = shl i32 %.0, 1
  br i1 %5, label %.preheader27, label %7, !llvm.loop !5

7:                                                ; preds = %.preheader27
  %8 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %25, label %10

10:                                               ; preds = %7
  %11 = zext i32 %.0 to i64
  %12 = shl nuw nsw i64 %11, 3
  %13 = tail call noalias ptr @malloc(i64 noundef %12) #5
  %14 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !7
  %15 = icmp eq ptr %13, null
  br i1 %15, label %16, label %.preheader

.preheader:                                       ; preds = %10
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %13, i8 0, i64 %12, i1 false), !tbaa !13
  br label %._crit_edge

16:                                               ; preds = %10
  tail call void @free(ptr noundef nonnull %8) #6
  br label %25

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.preheader
  store i32 %.0, ptr %8, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %8, i64 16
  store i32 0, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %8, i64 32
  store ptr %1, ptr %18, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %8, i64 40
  store ptr %2, ptr %19, align 8, !tbaa !17
  %20 = uitofp i32 %.0 to float
  %21 = fmul float %20, 0x3FE4CCCCC0000000
  %22 = tail call float @llvm.ceil.f32(float %21)
  %23 = fptoui float %22 to i32
  %24 = getelementptr inbounds i8, ptr %8, i64 20
  store i32 %23, ptr %24, align 4, !tbaa !18
  br label %25

25:                                               ; preds = %7, %3, %._crit_edge, %16
  %.025 = phi ptr [ null, %16 ], [ %8, %._crit_edge ], [ null, %3 ], [ null, %7 ]
  ret ptr %.025
}

; 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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.ceil.f32(float) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { nounwind memory(readwrite, argmem: none) 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 8}
!8 = !{!"hashtable", !9, i64 0, !12, i64 8, !9, i64 16, !9, i64 20, !9, i64 24, !12, i64 32, !12, i64 40}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!8, !9, i64 0}
!15 = !{!8, !9, i64 16}
!16 = !{!8, !12, i64 32}
!17 = !{!8, !12, i64 40}
!18 = !{!8, !9, i64 20}


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