; 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_32 = type { ptr, i32, i32, i32, i32, i8, i8, i8 }
%struct.sc_map_item_32 = 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_32(ptr noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_map_get_32(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_32, 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_32, 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_32, 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_32, 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_32, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = getelementptr inbounds %struct.sc_map_item_32, ptr %31, i64 -1
  %33 = getelementptr inbounds %struct.sc_map_item_32, 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 %85

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

44:                                               ; preds = %68, %38
  br label %45

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

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

58:                                               ; preds = %45
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.sc_map_32, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds %struct.sc_map_item_32, ptr %61, i64 %63
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = call zeroext i1 @sc_map_cmp_32(ptr noundef %64, i32 noundef %65, i32 noundef %66)
  br i1 %67, label %73, label %68

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

73:                                               ; preds = %58
  br label %74

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

85:                                               ; preds = %74, %55, %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
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

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_32", !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_32", !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_32 = type { i32, i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_map_get_32(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 %36

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 %36

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

.lr.ph.preheader:                                 ; preds = %16
  %23 = tail call zeroext i1 @sc_map_cmp_32(ptr noundef nonnull %20, i32 noundef %1, i32 noundef %17)
  br i1 %23, 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 ]
  %24 = add i32 %.02529, 1
  %.0 = and i32 %24, %5
  %25 = load ptr, ptr %0, align 8, !tbaa !16
  %26 = zext i32 %.0 to i64
  %27 = getelementptr inbounds %struct.sc_map_item_32, ptr %25, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !19
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %._crit_edge, label %.lr.ph

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

.lr.ph:                                           ; preds = %.lr.ph30
  %31 = tail call zeroext i1 @sc_map_cmp_32(ptr noundef nonnull %27, i32 noundef %1, i32 noundef %17)
  br i1 %31, label %.lr.ph._crit_edge, label %.lr.ph30

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

36:                                               ; preds = %12, %7, %.lr.ph._crit_edge, %._crit_edge
  %.021 = phi i32 [ 0, %._crit_edge ], [ %35, %.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_32", !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_32", !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