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

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

@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 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

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

; 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
define dso_local void @example_int_to_str() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.sc_map_64s, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #3
  %6 = call zeroext i1 @sc_map_init_64s(ptr noundef %3, i32 noundef 0, i32 noundef 0)
  %7 = call ptr @sc_map_put_64s(ptr noundef %3, i64 noundef 100, ptr noundef @.str.1)
  %8 = call ptr @sc_map_put_64s(ptr noundef %3, i64 noundef 200, ptr noundef @.str.3)
  %9 = call ptr @sc_map_put_64s(ptr noundef %3, i64 noundef 300, ptr noundef @.str.5)
  %10 = call ptr @sc_map_get_64s(ptr noundef %3, i64 noundef 200)
  store ptr %10, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 7
  %12 = load i8, ptr %11, align 2, !tbaa !9, !range !13, !noundef !14
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %17

14:                                               ; preds = %0
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %15)
  br label %17

17:                                               ; preds = %14, %0
  %18 = call ptr @sc_map_del_64s(ptr noundef %3, i64 noundef 100)
  store ptr %18, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 7
  %20 = load i8, ptr %19, align 2, !tbaa !9, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %23)
  br label %25

25:                                               ; preds = %22, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 -1, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %76, %25
  %27 = load i64, ptr %5, align 8, !tbaa !15
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %35, label %29

29:                                               ; preds = %26
  %30 = load i64, ptr %4, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !17
  %33 = zext i32 %32 to i64
  %34 = icmp slt i64 %30, %33
  br label %35

35:                                               ; preds = %29, %26
  %36 = phi i1 [ false, %26 ], [ %34, %29 ]
  br i1 %36, label %38, label %37

37:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %79

38:                                               ; preds = %35
  %39 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load i64, ptr %4, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.sc_map_item_64s, ptr %40, i64 %41
  %43 = getelementptr inbounds %struct.sc_map_item_64s, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  store ptr %44, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = load i64, ptr %4, align 8, !tbaa !15
  %48 = getelementptr inbounds %struct.sc_map_item_64s, ptr %46, i64 %47
  %49 = getelementptr inbounds %struct.sc_map_item_64s, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !21
  %51 = trunc i64 %50 to i32
  store i32 %51, ptr %1, align 4, !tbaa !22
  store i64 1, ptr %5, align 8, !tbaa !15
  br label %52

52:                                               ; preds = %74, %38
  %53 = load i64, ptr %5, align 8, !tbaa !15
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %66

55:                                               ; preds = %52
  %56 = load i64, ptr %4, align 8, !tbaa !15
  %57 = icmp eq i64 %56, -1
  br i1 %57, label %58, label %62

58:                                               ; preds = %55
  %59 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 5
  %60 = load i8, ptr %59, align 8, !tbaa !23, !range !13, !noundef !14
  %61 = trunc i8 %60 to i1
  br i1 %61, label %65, label %62

62:                                               ; preds = %58, %55
  %63 = load i32, ptr %1, align 4, !tbaa !22
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %62, %58
  br label %67

66:                                               ; preds = %62, %52
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %66, %65
  %68 = phi i64 [ 1, %65 ], [ 0, %66 ]
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %70, label %75

70:                                               ; preds = %67
  %71 = load i32, ptr %1, align 4, !tbaa !22
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %71, ptr noundef %72)
  br label %74

74:                                               ; preds = %70
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %52, !llvm.loop !24

75:                                               ; preds = %67
  br label %76

76:                                               ; preds = %75
  %77 = load i64, ptr %4, align 8, !tbaa !15
  %78 = add nsw i64 %77, 1
  store i64 %78, ptr %4, align 8, !tbaa !15
  br label %26, !llvm.loop !26

79:                                               ; preds = %37
  %80 = call ptr @sc_map_del_64s(ptr noundef %3, i64 noundef 200)
  store ptr %80, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 7
  %82 = load i8, ptr %81, align 2, !tbaa !9, !range !13, !noundef !14
  %83 = trunc i8 %82 to i1
  br i1 %83, label %84, label %87

84:                                               ; preds = %79
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef %85)
  br label %87

87:                                               ; preds = %84, %79
  %88 = call ptr @sc_map_put_64s(ptr noundef %3, i64 noundef 300, ptr noundef @.str.11)
  store ptr %88, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.sc_map_64s, ptr %3, i32 0, i32 7
  %90 = load i8, ptr %89, align 2, !tbaa !9, !range !13, !noundef !14
  %91 = trunc i8 %90 to i1
  br i1 %91, label %92, label %95

92:                                               ; preds = %87
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, ptr noundef %93)
  br label %95

95:                                               ; preds = %92, %87
  call void @sc_map_term_64s(ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

declare zeroext i1 @sc_map_init_64s(ptr noundef, i32 noundef, i32 noundef) #1

declare ptr @sc_map_put_64s(ptr noundef, i64 noundef, ptr noundef) #1

declare ptr @sc_map_get_64s(ptr noundef, i64 noundef) #1

declare ptr @sc_map_del_64s(ptr noundef, i64 noundef) #1

declare void @sc_map_term_64s(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !12, i64 26}
!10 = !{!"sc_map_64s", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 25, !12, i64 26}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !11, i64 8}
!18 = !{!10, !6, i64 0}
!19 = !{!20, !6, i64 8}
!20 = !{!"sc_map_item_64s", !16, i64 0, !6, i64 8}
!21 = !{!20, !16, i64 0}
!22 = !{!11, !11, i64 0}
!23 = !{!10, !12, i64 24}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


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

@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @example_int_to_str() local_unnamed_addr #2 {
  %1 = alloca %struct.sc_map_64s, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #4
  %2 = call zeroext i1 @sc_map_init_64s(ptr noundef nonnull %1, i32 noundef 0, i32 noundef 0) #4
  %3 = call ptr @sc_map_put_64s(ptr noundef nonnull %1, i64 noundef 100, ptr noundef nonnull @.str.1) #4
  %4 = call ptr @sc_map_put_64s(ptr noundef nonnull %1, i64 noundef 200, ptr noundef nonnull @.str.3) #4
  %5 = call ptr @sc_map_put_64s(ptr noundef nonnull %1, i64 noundef 300, ptr noundef nonnull @.str.5) #4
  %6 = call ptr @sc_map_get_64s(ptr noundef nonnull %1, i64 noundef 200) #4
  %7 = getelementptr inbounds i8, ptr %1, i64 26
  %8 = load i8, ptr %7, align 2, !tbaa !5, !range !12, !noundef !13
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %10, label %12

10:                                               ; preds = %0
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %6)
  br label %12

12:                                               ; preds = %10, %0
  %13 = call ptr @sc_map_del_64s(ptr noundef nonnull %1, i64 noundef 100) #4
  %14 = load i8, ptr %7, align 2, !tbaa !5, !range !12, !noundef !13
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %13)
  br label %18

18:                                               ; preds = %12, %16
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load ptr, ptr %1, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %20, i64 -16
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = trunc i64 %22 to i32
  %24 = getelementptr inbounds i8, ptr %1, i64 24
  %25 = load i8, ptr %24, align 8, !tbaa !18, !range !12, !noundef !13
  %26 = trunc nuw i8 %25 to i1
  %27 = icmp ne i32 %23, 0
  %or.cond.peel = select i1 %26, i1 true, i1 %27
  br i1 %or.cond.peel, label %.critedge, label %31

.critedge:                                        ; preds = %18
  %28 = getelementptr inbounds i8, ptr %20, i64 -8
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %23, ptr noundef %29)
  br label %31

31:                                               ; preds = %18, %.critedge
  %32 = load i32, ptr %19, align 8
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %.loopexit, label %.critedge.peel.next

.loopexit:                                        ; preds = %44, %31
  %33 = call ptr @sc_map_del_64s(ptr noundef nonnull %1, i64 noundef 200) #4
  %34 = load i8, ptr %7, align 2, !tbaa !5, !range !12, !noundef !13
  %35 = trunc nuw i8 %34 to i1
  br i1 %35, label %49, label %51

.critedge.peel.next:                              ; preds = %31, %44
  %.01518 = phi i64 [ %45, %44 ], [ 0, %31 ]
  %36 = load ptr, ptr %1, align 8, !tbaa !14
  %37 = getelementptr inbounds %struct.sc_map_item_64s, ptr %36, i64 %.01518
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %39 = trunc i64 %38 to i32
  %.old1.not = icmp eq i32 %39, 0
  br i1 %.old1.not, label %44, label %40

40:                                               ; preds = %.critedge.peel.next
  %41 = getelementptr inbounds i8, ptr %37, i64 8
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %39, ptr noundef %42)
  br label %44

44:                                               ; preds = %.critedge.peel.next, %40
  %45 = add nuw nsw i64 %.01518, 1
  %46 = load i32, ptr %19, align 8
  %47 = zext i32 %46 to i64
  %48 = icmp ult i64 %45, %47
  br i1 %48, label %.critedge.peel.next, label %.loopexit, !llvm.loop !20

49:                                               ; preds = %.loopexit
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, ptr noundef %33)
  br label %51

51:                                               ; preds = %49, %.loopexit
  %52 = call ptr @sc_map_put_64s(ptr noundef nonnull %1, i64 noundef 300, ptr noundef nonnull @.str.11) #4
  %53 = load i8, ptr %7, align 2, !tbaa !5, !range !12, !noundef !13
  %54 = trunc nuw i8 %53 to i1
  br i1 %54, label %55, label %57

55:                                               ; preds = %51
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, ptr noundef %52)
  br label %57

57:                                               ; preds = %55, %51
  call void @sc_map_term_64s(ptr noundef nonnull %1) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #4
  ret void
}

declare zeroext i1 @sc_map_init_64s(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare ptr @sc_map_put_64s(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare ptr @sc_map_get_64s(ptr noundef, i64 noundef) local_unnamed_addr #3

declare ptr @sc_map_del_64s(ptr noundef, i64 noundef) local_unnamed_addr #3

declare void @sc_map_term_64s(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { "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 #4 = { 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, !11, i64 26}
!6 = !{!"sc_map_64s", !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 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !17, i64 0}
!16 = !{!"sc_map_item_64s", !17, i64 0, !7, i64 8}
!17 = !{!"long", !8, i64 0}
!18 = !{!6, !11, i64 24}
!19 = !{!16, !7, i64 8}
!20 = distinct !{!20, !21, !22}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass