; LLVM IR from marcobambini/gravity :: src/shared (gravity_hash)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_hash_create(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %5
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %16, %5
  store ptr null, ptr %6, align 8
  br label %56

20:                                               ; preds = %16
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = icmp ult i32 %21, 32
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 32, ptr %7, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %23, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %25 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 56)
  store ptr %25, ptr %12, align 8, !tbaa !9
  %26 = load ptr, ptr %12, align 8, !tbaa !9
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %55

29:                                               ; preds = %24
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = call ptr @gravity_calloc(ptr noundef null, i64 noundef %31, i64 noundef 8)
  %33 = load ptr, ptr %12, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.gravity_hash_t, ptr %33, i32 0, i32 2
  store ptr %32, ptr %34, align 8, !tbaa !11
  %35 = icmp ne ptr %32, null
  br i1 %35, label %38, label %36

36:                                               ; preds = %29
  %37 = load ptr, ptr %12, align 8, !tbaa !9
  call void @free(ptr noundef %37) #4
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %55

38:                                               ; preds = %29
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = load ptr, ptr %12, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.gravity_hash_t, ptr %40, i32 0, i32 3
  store ptr %39, ptr %41, align 8, !tbaa !13
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = load ptr, ptr %12, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.gravity_hash_t, ptr %43, i32 0, i32 4
  store ptr %42, ptr %44, align 8, !tbaa !14
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.gravity_hash_t, ptr %46, i32 0, i32 5
  store ptr %45, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = load ptr, ptr %12, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.gravity_hash_t, ptr %49, i32 0, i32 6
  store ptr %48, ptr %50, align 8, !tbaa !16
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load ptr, ptr %12, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.gravity_hash_t, ptr %52, i32 0, i32 0
  store i32 %51, ptr %53, align 8, !tbaa !17
  %54 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %54, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %55

55:                                               ; preds = %38, %36, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %56

56:                                               ; preds = %55, %19
  %57 = load ptr, ptr %6, align 8
  ret ptr %57
}

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

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #2

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

; 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 = { "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 = { 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, !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 8}
!12 = !{!"gravity_hash_t", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !6, i64 48, !6, i64 52}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !10, i64 32}
!16 = !{!12, !10, i64 40}
!17 = !{!12, !6, i64 0}


; 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 uwtable
define dso_local ptr @gravity_hash_create(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = icmp ne ptr %1, null
  %7 = icmp ne ptr %2, null
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %8, label %20

8:                                                ; preds = %5
  %spec.store.select = tail call i32 @llvm.umax.i32(i32 %0, i32 32)
  %9 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 56) #4
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %20, label %10

10:                                               ; preds = %8
  %11 = zext i32 %spec.store.select to i64
  %12 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef %11, i64 noundef 8) #4
  %13 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !5
  %.not22 = icmp eq ptr %12, null
  br i1 %.not22, label %14, label %15

14:                                               ; preds = %10
  tail call void @free(ptr noundef nonnull %9) #4
  br label %20

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %1, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %2, ptr %17, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr %3, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %9, i64 40
  store ptr %4, ptr %19, align 8, !tbaa !14
  store i32 %spec.store.select, ptr %9, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %14, %15, %8, %5
  %.1 = phi ptr [ null, %5 ], [ %9, %15 ], [ null, %14 ], [ null, %8 ]
  ret ptr %.1
}

declare ptr @gravity_calloc(ptr noundef, i64 noundef, 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 i32 @llvm.umax.i32(i32, i32) #3

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 = { "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 = { 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, !10, i64 8}
!6 = !{!"gravity_hash_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !10, i64 40}
!15 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass