; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/2725（模拟）.ll (Z4calcii)

; 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.Node = type { i32, i32, i32, i32 }

@s = external dso_local global [50 x i8], align 16
@len = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_Z4calcii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca %struct.Node, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %26, %2
  br label %8

8:                                                ; preds = %7
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @len, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %25

12:                                               ; preds = %8
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 46
  br i1 %18, label %19, label %25

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %6, align 4, !tbaa !5
  br label %26

25:                                               ; preds = %12, %8
  br label %27

26:                                               ; preds = %19
  br label %7, !llvm.loop !10

27:                                               ; preds = %25
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 2
  store i32 %28, ptr %29, align 4, !tbaa !12
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr @len, align 4, !tbaa !5
  %32 = icmp sge i32 %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %27
  %34 = load i32, ptr @len, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %33, %27
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 3
  store i32 %37, ptr %38, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %39 = load { i64, i64 }, ptr %3, align 4
  ret { i64, i64 } %39
}

; 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

attributes #0 = { mustprogress 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 }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!14 = !{!13, !6, i64 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"

@s = external dso_local local_unnamed_addr global [50 x i8], align 16
@len = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local { i64, i64 } @_Z4calcii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @len, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, %0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %2
  %5 = add nsw i32 %3, -1
  br label %17

.lr.ph.preheader:                                 ; preds = %2
  %6 = sext i32 %0 to i64
  %7 = sext i32 %1 to i64
  %8 = sext i32 %3 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %11
  %indvars.iv = phi i64 [ %6, %.lr.ph.preheader ], [ %indvars.iv.next, %11 ]
  %.012 = phi i32 [ 0, %.lr.ph.preheader ], [ %12, %11 ]
  %9 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %.not = icmp eq i8 %10, 46
  br i1 %.not, label %11, label %15

11:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, %7
  %12 = add nuw nsw i32 %.012, 1
  %13 = icmp slt i64 %indvars.iv.next, %8
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %11
  %14 = add nsw i32 %3, -1
  br label %17

15:                                               ; preds = %.lr.ph
  %16 = trunc nsw i64 %indvars.iv to i32
  br label %17

17:                                               ; preds = %._crit_edge, %._crit_edge.thread, %15
  %.0.lcssa24.shrunk = phi i32 [ %.012, %15 ], [ %12, %._crit_edge ], [ 0, %._crit_edge.thread ]
  %18 = phi i32 [ %16, %15 ], [ %14, %._crit_edge ], [ %5, %._crit_edge.thread ]
  %.0.lcssa24 = zext i32 %.0.lcssa24.shrunk to i64
  %.sroa.3.8.insert.ext = zext i32 %18 to i64
  %.sroa.3.8.insert.shift = shl nuw i64 %.sroa.3.8.insert.ext, 32
  %.sroa.1.8.insert.insert = or disjoint i64 %.sroa.3.8.insert.shift, %.0.lcssa24
  %.fca.1.insert = insertvalue { i64, i64 } { i64 undef, i64 poison }, i64 %.sroa.1.8.insert.insert, 1
  ret { i64, i64 } %.fca.1.insert
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass