; LLVM IR from xtaci/algorithms :: src (merge_sort_demo)

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

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [20 x i32], align 16
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 20, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %14, %0
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 20
  br i1 %7, label %8, label %17

8:                                                ; preds = %5
  %9 = call i32 @rand() #5
  %10 = srem i32 %9, 100
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [20 x i32], ptr %3, i64 0, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %8
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %4, align 4, !tbaa !5
  br label %5, !llvm.loop !9

17:                                               ; preds = %5
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @_ZN3algL9printlistIA20_iEEvRT_i(ptr noundef nonnull align 4 dereferenceable(80) %3, i32 noundef 20)
  %19 = getelementptr inbounds [20 x i32], ptr %3, i64 0, i64 0
  call void @_ZN3algL10merge_sortIiEEvPT_ii(ptr noundef %19, i32 noundef 0, i32 noundef 19)
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @_ZN3algL9printlistIA20_iEEvRT_i(ptr noundef nonnull align 4 dereferenceable(80) %3, i32 noundef 20)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN3algL9printlistIA20_iEEvRT_i(ptr noundef nonnull align 4 dereferenceable(80), i32 noundef) #4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN3algL10merge_sortIiEEvPT_ii(ptr noundef, i32 noundef, i32 noundef) #4

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

attributes #0 = { mustprogress norecurse 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 = { "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 = { mustprogress 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [20 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %1) #5
  %2 = tail call i32 @rand() #5
  %3 = srem i32 %2, 100
  store i32 %3, ptr %1, align 16, !tbaa !5
  %4 = tail call i32 @rand() #5
  %5 = srem i32 %4, 100
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %5, ptr %6, align 4, !tbaa !5
  %7 = tail call i32 @rand() #5
  %8 = srem i32 %7, 100
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %8, ptr %9, align 8, !tbaa !5
  %10 = tail call i32 @rand() #5
  %11 = srem i32 %10, 100
  %12 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %11, ptr %12, align 4, !tbaa !5
  %13 = tail call i32 @rand() #5
  %14 = srem i32 %13, 100
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 %14, ptr %15, align 16, !tbaa !5
  %16 = tail call i32 @rand() #5
  %17 = srem i32 %16, 100
  %18 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %17, ptr %18, align 4, !tbaa !5
  %19 = tail call i32 @rand() #5
  %20 = srem i32 %19, 100
  %21 = getelementptr inbounds i8, ptr %1, i64 24
  store i32 %20, ptr %21, align 8, !tbaa !5
  %22 = tail call i32 @rand() #5
  %23 = srem i32 %22, 100
  %24 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 %23, ptr %24, align 4, !tbaa !5
  %25 = tail call i32 @rand() #5
  %26 = srem i32 %25, 100
  %27 = getelementptr inbounds i8, ptr %1, i64 32
  store i32 %26, ptr %27, align 16, !tbaa !5
  %28 = tail call i32 @rand() #5
  %29 = srem i32 %28, 100
  %30 = getelementptr inbounds i8, ptr %1, i64 36
  store i32 %29, ptr %30, align 4, !tbaa !5
  %31 = tail call i32 @rand() #5
  %32 = srem i32 %31, 100
  %33 = getelementptr inbounds i8, ptr %1, i64 40
  store i32 %32, ptr %33, align 8, !tbaa !5
  %34 = tail call i32 @rand() #5
  %35 = srem i32 %34, 100
  %36 = getelementptr inbounds i8, ptr %1, i64 44
  store i32 %35, ptr %36, align 4, !tbaa !5
  %37 = tail call i32 @rand() #5
  %38 = srem i32 %37, 100
  %39 = getelementptr inbounds i8, ptr %1, i64 48
  store i32 %38, ptr %39, align 16, !tbaa !5
  %40 = tail call i32 @rand() #5
  %41 = srem i32 %40, 100
  %42 = getelementptr inbounds i8, ptr %1, i64 52
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = tail call i32 @rand() #5
  %44 = srem i32 %43, 100
  %45 = getelementptr inbounds i8, ptr %1, i64 56
  store i32 %44, ptr %45, align 8, !tbaa !5
  %46 = tail call i32 @rand() #5
  %47 = srem i32 %46, 100
  %48 = getelementptr inbounds i8, ptr %1, i64 60
  store i32 %47, ptr %48, align 4, !tbaa !5
  %49 = tail call i32 @rand() #5
  %50 = srem i32 %49, 100
  %51 = getelementptr inbounds i8, ptr %1, i64 64
  store i32 %50, ptr %51, align 16, !tbaa !5
  %52 = tail call i32 @rand() #5
  %53 = srem i32 %52, 100
  %54 = getelementptr inbounds i8, ptr %1, i64 68
  store i32 %53, ptr %54, align 4, !tbaa !5
  %55 = tail call i32 @rand() #5
  %56 = srem i32 %55, 100
  %57 = getelementptr inbounds i8, ptr %1, i64 72
  store i32 %56, ptr %57, align 8, !tbaa !5
  %58 = tail call i32 @rand() #5
  %59 = srem i32 %58, 100
  %60 = getelementptr inbounds i8, ptr %1, i64 76
  store i32 %59, ptr %60, align 4, !tbaa !5
  %61 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  call void @_ZN3algL9printlistIA20_iEEvRT_i(ptr noundef nonnull align 4 dereferenceable(80) %1, i32 noundef 20)
  call void @_ZN3algL10merge_sortIiEEvPT_ii(ptr noundef nonnull %1, i32 noundef 0, i32 noundef 19)
  %62 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @_ZN3algL9printlistIA20_iEEvRT_i(ptr noundef nonnull align 4 dereferenceable(80) %1, i32 noundef 20)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %1) #5
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN3algL9printlistIA20_iEEvRT_i(ptr noundef nonnull align 4 dereferenceable(80), i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN3algL10merge_sortIiEEvPT_ii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

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

attributes #0 = { mustprogress norecurse 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 = { 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 = { 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 = { mustprogress 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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