; LLVM IR from jovanlanik/wip :: src (wip_hashmap)

; 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.wip_hashmap_t = type { i32, [0 x %struct.anon] }
%struct.anon = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @wip_hashmapGet(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call i32 @hash_djb2(ptr noundef %10)
  store i32 %11, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.wip_hashmap_t, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = srem i32 %12, %15
  store i32 %16, ptr %7, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %44, %2
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.wip_hashmap_t, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  br label %47

24:                                               ; preds = %17
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.wip_hashmap_t, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [0 x %struct.anon], ptr %26, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call i32 @strcmp(ptr noundef %31, ptr noundef %32) #4
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %43

35:                                               ; preds = %24
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.wip_hashmap_t, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [0 x %struct.anon], ptr %37, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  store ptr %42, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %47

43:                                               ; preds = %24
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %7, align 4, !tbaa !9
  br label %17, !llvm.loop !14

47:                                               ; preds = %35, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %48 = load i32, ptr %8, align 4
  switch i32 %48, label %81 [
    i32 2, label %49
  ]

49:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %75, %49
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  store i32 5, ptr %8, align 4
  br label %78

55:                                               ; preds = %50
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.wip_hashmap_t, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [0 x %struct.anon], ptr %57, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.anon, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call i32 @strcmp(ptr noundef %62, ptr noundef %63) #4
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %74

66:                                               ; preds = %55
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.wip_hashmap_t, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [0 x %struct.anon], ptr %68, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.anon, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  store ptr %73, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %78

74:                                               ; preds = %55
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %9, align 4, !tbaa !9
  br label %50, !llvm.loop !16

78:                                               ; preds = %66, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %79 = load i32, ptr %8, align 4
  switch i32 %79, label %81 [
    i32 5, label %80
  ]

80:                                               ; preds = %78
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %81

81:                                               ; preds = %80, %78, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %82 = load ptr, ptr %3, align 8
  ret ptr %82
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @hash_djb2(ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr 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 willreturn memory(read) "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 willreturn memory(read) }

!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 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

%struct.anon = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @wip_hashmapGet(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @hash_djb2(ptr noundef %1)
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %.not29 = icmp sgt i32 %4, -1
  br i1 %.not29, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %2
  %5 = srem i32 %3, %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = sext i32 %5 to i64
  %8 = zext nneg i32 %4 to i64
  br label %11

9:                                                ; preds = %11
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %.not = icmp slt i64 %indvars.iv.next, %8
  br i1 %.not, label %11, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %9, %2
  %.not2631 = icmp sgt i32 %3, 0
  br i1 %.not2631, label %.lr.ph33, label %.loopexit

.lr.ph33:                                         ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %17

11:                                               ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ %7, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %12 = getelementptr inbounds [0 x %struct.anon], ptr %6, i64 0, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) %1) #2
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %.loopexit.sink.split, label %9

16:                                               ; preds = %17
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %17, !llvm.loop !14

17:                                               ; preds = %.lr.ph33, %16
  %indvars.iv38 = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next39, %16 ]
  %18 = getelementptr inbounds [0 x %struct.anon], ptr %10, i64 0, i64 %indvars.iv38
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %19, ptr noundef nonnull dereferenceable(1) %1) #2
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.loopexit.sink.split, label %16

.loopexit.sink.split:                             ; preds = %11, %17
  %.lcssa.sink = phi ptr [ %18, %17 ], [ %12, %11 ]
  %22 = getelementptr inbounds i8, ptr %.lcssa.sink, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.loopexit.sink.split, %.preheader
  %.2 = phi ptr [ null, %.preheader ], [ %23, %.loopexit.sink.split ], [ null, %16 ]
  ret ptr %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @hash_djb2(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = !{!12, !13, i64 8}


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