; LLVM IR from BurntSushi/clibs :: libds (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.DSHashMap = type { ptr, ptr }
%struct.DSVector = type { i32, i32, ptr }
%struct.DSHashKey = type { ptr, i8, %union.anon }
%union.anon = type { ptr }

@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1

; 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 ptr @ds_gets(ptr noundef, ptr noundef) #1

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

declare ptr @ds_vector_get(ptr noundef, i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @ds_hashmap_print_keyvals(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %50, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.DSHashMap, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.DSVector, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp slt i32 %8, %13
  br i1 %14, label %15, label %53

15:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DSHashMap, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = call ptr @ds_vector_get(ptr noundef %18, i32 noundef %19)
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.DSHashKey, ptr %21, i32 0, i32 1
  %23 = load i8, ptr %22, align 8, !tbaa !15
  %24 = sext i8 %23 to i32
  switch i32 %24, label %49 [
    i32 2, label %25
    i32 1, label %37
  ]

25:                                               ; preds = %15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.DSHashKey, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.DSHashKey, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = call ptr @ds_gets(ptr noundef %30, ptr noundef %33)
  %35 = call ptr %29(ptr noundef %34)
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %28, ptr noundef %35)
  br label %49

37:                                               ; preds = %15
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.DSHashKey, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !17
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.DSHashKey, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 8, !tbaa !17
  %46 = call ptr @ds_geti(ptr noundef %42, i32 noundef %45)
  %47 = call ptr %41(ptr noundef %46)
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %40, ptr noundef %47)
  br label %49

49:                                               ; preds = %37, %25, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !18

53:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  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 = { "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 }

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


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

@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1

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

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

declare ptr @ds_vector_get(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @ds_hashmap_print_keyvals(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = load i32, ptr %3, align 8, !tbaa !10
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %22
  %6 = phi ptr [ %24, %22 ], [ %3, %2 ]
  %.013 = phi i32 [ %23, %22 ], [ 0, %2 ]
  %7 = tail call ptr @ds_vector_get(ptr noundef nonnull %6, i32 noundef %.013) #3
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i8, ptr %8, align 8, !tbaa !13
  switch i8 %9, label %22 [
    i8 2, label %10
    i8 1, label %16
  ]

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %7, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = tail call ptr @ds_gets(ptr noundef nonnull %0, ptr noundef %12)
  %14 = tail call ptr %1(ptr noundef %13) #3
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %12, ptr noundef %14)
  br label %22

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %7, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = tail call ptr @ds_geti(ptr noundef nonnull %0, i32 noundef %18)
  %20 = tail call ptr %1(ptr noundef %19) #3
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %18, ptr noundef %20)
  br label %22

22:                                               ; preds = %16, %10, %.lr.ph
  %23 = add nuw nsw i32 %.013, 1
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = load i32, ptr %24, align 8, !tbaa !10
  %26 = icmp slt i32 %23, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %22, %2
  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" }
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 = { nofree 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 #3 = { 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, !7, i64 0}
!6 = !{!"DSHashMap", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"DSVector", !12, i64 0, !12, i64 4, !7, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !8, i64 8}
!14 = !{!"DSHashKey", !7, i64 0, !8, i64 8, !8, i64 16}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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