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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @example_str() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca %struct.sc_map_str, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, 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_str(ptr noundef %3, i32 noundef 0, i32 noundef 0)
  %7 = call ptr @sc_map_put_str(ptr noundef %3, ptr noundef @.str, ptr noundef @.str.1)
  %8 = call ptr @sc_map_put_str(ptr noundef %3, ptr noundef @.str.2, ptr noundef @.str.3)
  %9 = call ptr @sc_map_put_str(ptr noundef %3, ptr noundef @.str.4, ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 -1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %59, %0
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %19, label %13

13:                                               ; preds = %10
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.sc_map_str, ptr %3, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = icmp slt i64 %14, %17
  br label %19

19:                                               ; preds = %13, %10
  %20 = phi i1 [ false, %10 ], [ %18, %13 ]
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %19
  %23 = getelementptr inbounds %struct.sc_map_str, ptr %3, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.sc_map_item_str, ptr %24, i64 %25
  %27 = getelementptr inbounds %struct.sc_map_item_str, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  store ptr %28, ptr %2, align 8, !tbaa !17
  %29 = getelementptr inbounds %struct.sc_map_str, ptr %3, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.sc_map_item_str, ptr %30, i64 %31
  %33 = getelementptr inbounds %struct.sc_map_item_str, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  store ptr %34, ptr %1, align 8, !tbaa !17
  store i64 1, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %57, %22
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %49

38:                                               ; preds = %35
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = icmp eq i64 %39, -1
  br i1 %40, label %41, label %45

41:                                               ; preds = %38
  %42 = getelementptr inbounds %struct.sc_map_str, ptr %3, i32 0, i32 5
  %43 = load i8, ptr %42, align 8, !tbaa !19, !range !20, !noundef !21
  %44 = trunc i8 %43 to i1
  br i1 %44, label %48, label %45

45:                                               ; preds = %41, %38
  %46 = load ptr, ptr %1, align 8, !tbaa !17
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %45, %41
  br label %50

49:                                               ; preds = %45, %35
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %49, %48
  %51 = phi i64 [ 1, %48 ], [ 0, %49 ]
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %1, align 8, !tbaa !17
  %55 = load ptr, ptr %2, align 8, !tbaa !17
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %54, ptr noundef %55)
  br label %57

57:                                               ; preds = %53
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %35, !llvm.loop !22

58:                                               ; preds = %50
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %4, align 8, !tbaa !5
  %61 = add nsw i64 %60, 1
  store i64 %61, ptr %4, align 8, !tbaa !5
  br label %10, !llvm.loop !24

62:                                               ; preds = %21
  call void @sc_map_term_str(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 8, ptr %1) #3
  ret void
}

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

declare zeroext i1 @sc_map_init_str(ptr noundef, i32 noundef, i32 noundef) #2

declare ptr @sc_map_put_str(ptr noundef, ptr noundef, ptr noundef) #2

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

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

declare void @sc_map_term_str(ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"sc_map_str", !11, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !13, i64 24, !13, i64 25, !13, i64 26}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!16, !11, i64 8}
!16 = !{!"sc_map_item_str", !11, i64 0, !11, i64 8, !12, i64 16}
!17 = !{!11, !11, i64 0}
!18 = !{!16, !11, i64 0}
!19 = !{!10, !13, i64 24}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @example_str() local_unnamed_addr #0 {
  %1 = alloca %struct.sc_map_str, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #4
  %2 = call zeroext i1 @sc_map_init_str(ptr noundef nonnull %1, i32 noundef 0, i32 noundef 0) #4
  %3 = call ptr @sc_map_put_str(ptr noundef nonnull %1, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #4
  %4 = call ptr @sc_map_put_str(ptr noundef nonnull %1, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3) #4
  %5 = call ptr @sc_map_put_str(ptr noundef nonnull %1, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5) #4
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 -24
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %1, i64 24
  %11 = load i8, ptr %10, align 8, !tbaa !14, !range !15, !noundef !16
  %12 = trunc nuw i8 %11 to i1
  %13 = icmp ne ptr %9, null
  %or.cond.peel = select i1 %12, i1 true, i1 %13
  br i1 %or.cond.peel, label %.critedge, label %17

.critedge:                                        ; preds = %0
  %14 = getelementptr inbounds i8, ptr %7, i64 -16
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %9, ptr noundef %15)
  br label %17

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

.loopexit:                                        ; preds = %26, %17
  call void @sc_map_term_str(ptr noundef nonnull %1) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #4
  ret void

.critedge.peel.next:                              ; preds = %17, %26
  %.01013 = phi i64 [ %27, %26 ], [ 0, %17 ]
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sc_map_item_str, ptr %19, i64 %.01013
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %.old1.not = icmp eq ptr %21, null
  br i1 %.old1.not, label %26, label %22

22:                                               ; preds = %.critedge.peel.next
  %23 = getelementptr inbounds i8, ptr %20, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %21, ptr noundef %24)
  br label %26

26:                                               ; preds = %.critedge.peel.next, %22
  %27 = add nuw nsw i64 %.01013, 1
  %28 = load i32, ptr %6, align 8
  %29 = zext i32 %28 to i64
  %30 = icmp ult i64 %27, %29
  br i1 %30, label %.critedge.peel.next, label %.loopexit, !llvm.loop !18
}

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

declare zeroext i1 @sc_map_init_str(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare ptr @sc_map_put_str(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

declare void @sc_map_term_str(ptr noundef) local_unnamed_addr #2

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


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