; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x02-递推与递归/97. 约数之和.ll (Z3sumxx)

; 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z10powWithModii(i32 noundef, i32 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: mustprogress uwtable
define dso_local noundef i64 @_Z3sumxx(i64 noundef %0, i64 noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i64 0, ptr %3, align 8
  br label %59

10:                                               ; preds = %2
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i64 1, ptr %3, align 8
  br label %59

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = srem i64 %15, 2
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %34

18:                                               ; preds = %14
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = trunc i64 %19 to i32
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = sdiv i64 %21, 2
  %23 = add nsw i64 %22, 1
  %24 = trunc i64 %23 to i32
  %25 = call noundef i64 @_Z10powWithModii(i32 noundef %20, i32 noundef %24)
  %26 = add nsw i64 1, %25
  %27 = srem i64 %26, 9901
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = sdiv i64 %29, 2
  %31 = call noundef i64 @_Z3sumxx(i64 noundef %28, i64 noundef %30)
  %32 = mul nsw i64 %27, %31
  %33 = srem i64 %32, 9901
  store i64 %33, ptr %6, align 8, !tbaa !5
  br label %57

34:                                               ; preds = %14
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = trunc i64 %35 to i32
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = sdiv i64 %37, 2
  %39 = trunc i64 %38 to i32
  %40 = call noundef i64 @_Z10powWithModii(i32 noundef %36, i32 noundef %39)
  %41 = add nsw i64 1, %40
  %42 = srem i64 %41, 9901
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = sdiv i64 %44, 2
  %46 = sub nsw i64 %45, 1
  %47 = call noundef i64 @_Z3sumxx(i64 noundef %43, i64 noundef %46)
  %48 = mul nsw i64 %42, %47
  %49 = srem i64 %48, 9901
  %50 = load i64, ptr %4, align 8, !tbaa !5
  %51 = trunc i64 %50 to i32
  %52 = load i64, ptr %5, align 8, !tbaa !5
  %53 = trunc i64 %52 to i32
  %54 = call noundef i64 @_Z10powWithModii(i32 noundef %51, i32 noundef %53)
  %55 = add nsw i64 %49, %54
  %56 = srem i64 %55, 9901
  store i64 %56, ptr %6, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %34, %18
  %58 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %58, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %59

59:                                               ; preds = %57, %13, %9
  %60 = load i64, ptr %3, align 8
  ret i64 %60
}

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


; 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z10powWithModii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 -9900, 9901) i64 @_Z3sumxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i64 %0, 0
  br i1 %3, label %32, label %4

4:                                                ; preds = %2
  %5 = icmp eq i64 %1, 0
  br i1 %5, label %32, label %6

6:                                                ; preds = %4
  %7 = and i64 %1, 1
  %.not = icmp eq i64 %7, 0
  %8 = trunc i64 %0 to i32
  br i1 %.not, label %18, label %9

9:                                                ; preds = %6
  %10 = sdiv i64 %1, 2
  %11 = trunc i64 %10 to i32
  %12 = add i32 %11, 1
  %13 = tail call noundef i64 @_Z10powWithModii(i32 noundef %8, i32 noundef %12)
  %14 = add nsw i64 %13, 1
  %15 = srem i64 %14, 9901
  %16 = tail call noundef i64 @_Z3sumxx(i64 noundef %0, i64 noundef %10)
  %17 = mul nsw i64 %15, %16
  br label %31

18:                                               ; preds = %6
  %19 = ashr exact i64 %1, 1
  %20 = trunc i64 %19 to i32
  %21 = tail call noundef i64 @_Z10powWithModii(i32 noundef %8, i32 noundef %20)
  %22 = add nsw i64 %21, 1
  %23 = srem i64 %22, 9901
  %24 = add nsw i64 %19, -1
  %25 = tail call noundef i64 @_Z3sumxx(i64 noundef %0, i64 noundef %24)
  %26 = mul nsw i64 %23, %25
  %.lhs.trunc = trunc nsw i64 %26 to i32
  %27 = srem i32 %.lhs.trunc, 9901
  %.sext = sext i32 %27 to i64
  %28 = trunc i64 %1 to i32
  %29 = tail call noundef i64 @_Z10powWithModii(i32 noundef %8, i32 noundef %28)
  %30 = add nsw i64 %29, %.sext
  br label %31

31:                                               ; preds = %18, %9
  %.0.in = phi i64 [ %17, %9 ], [ %30, %18 ]
  %.0 = srem i64 %.0.in, 9901
  br label %32

32:                                               ; preds = %4, %2, %31
  %.015 = phi i64 [ %.0, %31 ], [ 0, %2 ], [ 1, %4 ]
  ret i64 %.015
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass