; LLVM IR from yudi-matsuzake/libgenerics :: doc/examples (map0)

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

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

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

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

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

4:                                                ; preds = %12, %1
  %5 = load i64, ptr %3, align 8, !tbaa !9
  %6 = icmp slt i64 %5, 10
  br i1 %6, label %7, label %15

7:                                                ; preds = %4
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !9
  %11 = getelementptr inbounds i64, ptr %9, i64 %10
  store i64 %8, ptr %11, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %7
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = add nsw i64 %13, 1
  store i64 %14, ptr %3, align 8, !tbaa !9
  br label %4, !llvm.loop !11

15:                                               ; preds = %4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %28, %15
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = icmp slt i64 %17, 10
  br i1 %18, label %19, label %31

19:                                               ; preds = %16
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load i64, ptr %3, align 8, !tbaa !9
  %22 = getelementptr inbounds i64, ptr %20, i64 %21
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call i32 @rand() #3
  %25 = srem i32 %24, 10
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i64, ptr %23, i64 %26
  call void @swap(ptr noundef %22, ptr noundef %27)
  br label %28

28:                                               ; preds = %19
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %3, align 8, !tbaa !9
  br label %16, !llvm.loop !13

31:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() #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 = { 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, !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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @randomize(ptr noundef %0) local_unnamed_addr #0 {
.preheader.preheader:
  store i64 0, ptr %0, align 8, !tbaa !5
  %1 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 1, ptr %1, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 2, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 3, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 4, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 5, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 6, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 7, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  store i64 8, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  store i64 9, ptr %9, align 8, !tbaa !5
  %10 = tail call i32 @rand() #2
  %11 = srem i32 %10, 10
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i64, ptr %0, i64 %12
  tail call void @swap(ptr noundef nonnull %0, ptr noundef nonnull %13)
  %14 = tail call i32 @rand() #2
  %15 = srem i32 %14, 10
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i64, ptr %0, i64 %16
  tail call void @swap(ptr noundef nonnull %1, ptr noundef nonnull %17)
  %18 = tail call i32 @rand() #2
  %19 = srem i32 %18, 10
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i64, ptr %0, i64 %20
  tail call void @swap(ptr noundef nonnull %2, ptr noundef nonnull %21)
  %22 = tail call i32 @rand() #2
  %23 = srem i32 %22, 10
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i64, ptr %0, i64 %24
  tail call void @swap(ptr noundef nonnull %3, ptr noundef nonnull %25)
  %26 = tail call i32 @rand() #2
  %27 = srem i32 %26, 10
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i64, ptr %0, i64 %28
  tail call void @swap(ptr noundef nonnull %4, ptr noundef nonnull %29)
  %30 = tail call i32 @rand() #2
  %31 = srem i32 %30, 10
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i64, ptr %0, i64 %32
  tail call void @swap(ptr noundef nonnull %5, ptr noundef nonnull %33)
  %34 = tail call i32 @rand() #2
  %35 = srem i32 %34, 10
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i64, ptr %0, i64 %36
  tail call void @swap(ptr noundef nonnull %6, ptr noundef nonnull %37)
  %38 = tail call i32 @rand() #2
  %39 = srem i32 %38, 10
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i64, ptr %0, i64 %40
  tail call void @swap(ptr noundef nonnull %7, ptr noundef nonnull %41)
  %42 = tail call i32 @rand() #2
  %43 = srem i32 %42, 10
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i64, ptr %0, i64 %44
  tail call void @swap(ptr noundef nonnull %8, ptr noundef nonnull %45)
  %46 = tail call i32 @rand() #2
  %47 = srem i32 %46, 10
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i64, ptr %0, i64 %48
  tail call void @swap(ptr noundef nonnull %9, ptr noundef nonnull %49)
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

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 = { 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 }

!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"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass