; LLVM IR from sysprog21/shecc :: src (ssa)

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

; 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 uwtable
declare dso_local i32 @hashmap_hash_index(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @hashmap_node_new(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @hashmap_rehash(ptr noundef) #1

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

12:                                               ; preds = %3
  br label %74

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.hashmap_t, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i32 @hashmap_hash_index(i32 noundef %16, ptr noundef %17)
  store i32 %18, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.hashmap_t, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %7, align 4, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  store ptr %25, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call ptr @hashmap_node_new(ptr noundef %26, ptr noundef %27)
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %39, label %31

31:                                               ; preds = %13
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.hashmap_t, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = load i32, ptr %7, align 4, !tbaa !12
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %35, i64 %37
  store ptr %32, ptr %38, align 8, !tbaa !5
  br label %53

39:                                               ; preds = %13
  br label %40

40:                                               ; preds = %45, %39
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hashmap_node, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %49

45:                                               ; preds = %40
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hashmap_node, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  store ptr %48, ptr %8, align 8, !tbaa !5
  br label %40, !llvm.loop !16

49:                                               ; preds = %40
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.hashmap_node, ptr %51, i32 0, i32 2
  store ptr %50, ptr %52, align 8, !tbaa !14
  br label %53

53:                                               ; preds = %49, %31
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hashmap_t, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !18
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 8, !tbaa !18
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.hashmap_t, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = ashr i32 %60, 2
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.hashmap_t, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = ashr i32 %64, 1
  %66 = add nsw i32 %61, %65
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.hashmap_t, ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !18
  %70 = icmp sle i32 %66, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %53
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  call void @hashmap_rehash(ptr noundef %72)
  br label %73

73:                                               ; preds = %71, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %74

74:                                               ; preds = %73, %12
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !6, i64 16}
!15 = !{!"hashmap_node", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, 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
declare dso_local i32 @hashmap_hash_index(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @hashmap_node_new(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @hashmap_rehash(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @hashmap_put(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = tail call i32 @hashmap_hash_index(i32 noundef %6, ptr noundef %1)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds ptr, ptr %9, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = tail call ptr @hashmap_node_new(ptr noundef %1, ptr noundef %2)
  %.not22 = icmp eq ptr %12, null
  br i1 %.not22, label %14, label %.preheader

14:                                               ; preds = %4
  %15 = load ptr, ptr %8, align 8, !tbaa !11
  %16 = getelementptr inbounds ptr, ptr %15, i64 %10
  br label %21

.preheader:                                       ; preds = %4, %.preheader
  %.0 = phi ptr [ %18, %.preheader ], [ %12, %4 ]
  %17 = getelementptr inbounds i8, ptr %.0, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %.not23 = icmp eq ptr %18, null
  br i1 %.not23, label %19, label %.preheader, !llvm.loop !15

19:                                               ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %.0, i64 16
  br label %21

21:                                               ; preds = %19, %14
  %.sink = phi ptr [ %20, %19 ], [ %16, %14 ]
  store ptr %13, ptr %.sink, align 8, !tbaa !12
  %22 = load i32, ptr %0, align 8, !tbaa !17
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %0, align 8, !tbaa !17
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = ashr i32 %24, 2
  %26 = ashr i32 %24, 1
  %27 = add nsw i32 %25, %26
  %.not24 = icmp sgt i32 %27, %23
  br i1 %.not24, label %29, label %28

28:                                               ; preds = %21
  tail call void @hashmap_rehash(ptr noundef nonnull %0)
  br label %29

29:                                               ; preds = %21, %28, %3
  ret void
}

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

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


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