; LLVM IR from tezc/sc :: map (sc_map)

; 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.sc_map_int = type { ptr, i32, i32, i32, i32, i8, i8, i8 }
%struct.sc_map_item_int = type { i32, i32 }

; 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 zeroext i1 @sc_map_cmp_int(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @sc_map_hash_64(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_map_get_int(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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 i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.sc_map_int, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = sub i32 %12, 1
  store i32 %13, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %38

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sc_map_int, ptr %17, i32 0, i32 5
  %19 = load i8, ptr %18, align 8, !tbaa !14, !range !15, !noundef !16
  %20 = trunc i8 %19 to i1
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sc_map_int, ptr %21, i32 0, i32 7
  %23 = zext i1 %20 to i8
  store i8 %23, ptr %22, align 2, !tbaa !17
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.sc_map_int, ptr %24, i32 0, i32 5
  %26 = load i8, ptr %25, align 8, !tbaa !14, !range !15, !noundef !16
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %35

28:                                               ; preds = %16
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.sc_map_int, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = getelementptr inbounds %struct.sc_map_item_int, ptr %31, i64 -1
  %33 = getelementptr inbounds %struct.sc_map_item_int, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !19
  br label %36

35:                                               ; preds = %16
  br label %36

36:                                               ; preds = %35, %28
  %37 = phi i32 [ %34, %28 ], [ 0, %35 ]
  store i32 %37, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %86

38:                                               ; preds = %2
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = call i32 @sc_map_hash_64(i64 noundef %40)
  store i32 %41, ptr %7, align 4, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = and i32 %42, %43
  store i32 %44, ptr %8, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %69, %38
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.sc_map_int, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds %struct.sc_map_item_int, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct.sc_map_item_int, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 4, !tbaa !21
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %46
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.sc_map_int, ptr %57, i32 0, i32 7
  store i8 0, ptr %58, align 2, !tbaa !17
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %86

59:                                               ; preds = %46
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.sc_map_int, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds %struct.sc_map_item_int, ptr %62, i64 %64
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = call zeroext i1 @sc_map_cmp_int(ptr noundef %65, i32 noundef %66, i32 noundef %67)
  br i1 %68, label %74, label %69

69:                                               ; preds = %59
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = add i32 %70, 1
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = and i32 %71, %72
  store i32 %73, ptr %8, align 4, !tbaa !9
  br label %45

74:                                               ; preds = %59
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.sc_map_int, ptr %76, i32 0, i32 7
  store i8 1, ptr %77, align 2, !tbaa !17
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.sc_map_int, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !18
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds %struct.sc_map_item_int, ptr %80, i64 %82
  %84 = getelementptr inbounds %struct.sc_map_item_int, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !19
  store i32 %85, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %86

86:                                               ; preds = %75, %56, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"sc_map_int", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !13, i64 25, !13, i64 26}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !13, i64 24}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!12, !13, i64 26}
!18 = !{!12, !6, i64 0}
!19 = !{!20, !10, i64 4}
!20 = !{!"sc_map_item_int", !10, i64 0, !10, i64 4}
!21 = !{!20, !10, 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"

%struct.sc_map_item_int = type { i32, i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_map_get_int(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add i32 %4, -1
  %6 = icmp eq i32 %1, 0
  br i1 %6, label %7, label %16

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i8, ptr %8, align 8, !tbaa !12, !range !13, !noundef !14
  %10 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 %9, ptr %10, align 2, !tbaa !15
  %11 = trunc nuw i8 %9 to i1
  br i1 %11, label %12, label %37

12:                                               ; preds = %7
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %13, i64 -4
  %15 = load i32, ptr %14, align 4, !tbaa !17
  br label %37

16:                                               ; preds = %2
  %17 = sext i32 %1 to i64
  %18 = tail call i32 @sc_map_hash_64(i64 noundef %17)
  %.024 = and i32 %18, %5
  %19 = load ptr, ptr %0, align 8, !tbaa !16
  %20 = zext i32 %.024 to i64
  %21 = getelementptr inbounds %struct.sc_map_item_int, ptr %19, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %16
  %24 = tail call zeroext i1 @sc_map_cmp_int(ptr noundef nonnull %21, i32 noundef %1, i32 noundef %18)
  br i1 %24, label %.lr.ph._crit_edge, label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.02529 = phi i32 [ %.0, %.lr.ph ], [ %.024, %.lr.ph.preheader ]
  %25 = add i32 %.02529, 1
  %.0 = and i32 %25, %5
  %26 = load ptr, ptr %0, align 8, !tbaa !16
  %27 = zext i32 %.0 to i64
  %28 = getelementptr inbounds %struct.sc_map_item_int, ptr %26, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !19
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph30, %16
  %31 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 0, ptr %31, align 2, !tbaa !15
  br label %37

.lr.ph:                                           ; preds = %.lr.ph30
  %32 = tail call zeroext i1 @sc_map_cmp_int(ptr noundef nonnull %28, i32 noundef %1, i32 noundef %18)
  br i1 %32, label %.lr.ph._crit_edge, label %.lr.ph30

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa = phi i64 [ %20, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %33 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 1, ptr %33, align 2, !tbaa !15
  %34 = load ptr, ptr %0, align 8, !tbaa !16
  %35 = getelementptr inbounds %struct.sc_map_item_int, ptr %34, i64 %.lcssa, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !17
  br label %37

37:                                               ; preds = %12, %7, %.lr.ph._crit_edge, %._crit_edge
  %.021 = phi i32 [ 0, %._crit_edge ], [ %36, %.lr.ph._crit_edge ], [ %15, %12 ], [ 0, %7 ]
  ret i32 %.021
}

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, !10, i64 8}
!6 = !{!"sc_map_int", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 25, !11, i64 26}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !11, i64 24}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !11, i64 26}
!16 = !{!6, !7, i64 0}
!17 = !{!18, !10, i64 4}
!18 = !{!"sc_map_item_int", !10, i64 0, !10, i64 4}
!19 = !{!18, !10, i64 0}


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