; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x43-线段树/246. 区间最大公约数.ll (Z7ask_segiii)

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

@t = external dso_local global [2000040 x %struct.SegmentTree], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 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 @_Z7ask_segiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [2000040 x %struct.SegmentTree], ptr @t, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.SegmentTree, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 16, !tbaa !9
  %17 = icmp sle i32 %11, %16
  br i1 %17, label %18, label %32

18:                                               ; preds = %3
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2000040 x %struct.SegmentTree], ptr @t, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.SegmentTree, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = icmp sge i32 %19, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %18
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [2000040 x %struct.SegmentTree], ptr @t, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.SegmentTree, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !13
  store i64 %31, ptr %4, align 8
  br label %71

32:                                               ; preds = %18, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2000040 x %struct.SegmentTree], ptr @t, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.SegmentTree, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 16, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2000040 x %struct.SegmentTree], ptr @t, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.SegmentTree, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !12
  %43 = add nsw i32 %37, %42
  %44 = ashr i32 %43, 1
  store i32 %44, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !14
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %48, label %54

48:                                               ; preds = %32
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = mul nsw i32 2, %49
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = call noundef i64 @_Z7ask_segiii(i32 noundef %50, i32 noundef %51, i32 noundef %52)
  store i64 %53, ptr %9, align 8, !tbaa !14
  br label %54

54:                                               ; preds = %48, %32
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = icmp sge i32 %55, %57
  br i1 %58, label %59, label %66

59:                                               ; preds = %54
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = mul nsw i32 2, %60
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = call noundef i64 @_Z7ask_segiii(i32 noundef %62, i32 noundef %63, i32 noundef %64)
  store i64 %65, ptr %10, align 8, !tbaa !14
  br label %66

66:                                               ; preds = %59, %54
  %67 = load i64, ptr %9, align 8, !tbaa !14
  %68 = load i64, ptr %10, align 8, !tbaa !14
  %69 = call noundef i64 @_Z3gcdxx(i64 noundef %67, i64 noundef %68)
  %70 = call noundef i64 @_ZSt3absx(i64 noundef %69)
  store i64 %70, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %71

71:                                               ; preds = %66, %26
  %72 = load i64, ptr %4, align 8
  ret i64 %72
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS11SegmentTree", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!11, !11, i64 0}


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

@t = external dso_local local_unnamed_addr global [2000040 x %struct.SegmentTree], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z7ask_segiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [2000040 x %struct.SegmentTree], ptr @t, i64 0, i64 %4
  %6 = load i32, ptr %5, align 16, !tbaa !5
  %.not = icmp slt i32 %6, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !11
  %.not24 = icmp sgt i32 %.pre, %2
  %or.cond = select i1 %.not, i1 true, i1 %.not24
  br i1 %or.cond, label %._crit_edge, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !12
  br label %23

._crit_edge:                                      ; preds = %3
  %10 = add nsw i32 %.pre, %6
  %11 = ashr i32 %10, 1
  %.not25 = icmp slt i32 %11, %1
  br i1 %.not25, label %15, label %12

12:                                               ; preds = %._crit_edge
  %13 = shl nsw i32 %0, 1
  %14 = tail call noundef i64 @_Z7ask_segiii(i32 noundef %13, i32 noundef %1, i32 noundef %2)
  br label %15

15:                                               ; preds = %12, %._crit_edge
  %.020 = phi i64 [ %14, %12 ], [ 0, %._crit_edge ]
  %.not26.not = icmp slt i32 %11, %2
  br i1 %.not26.not, label %16, label %20

16:                                               ; preds = %15
  %17 = shl nsw i32 %0, 1
  %18 = or disjoint i32 %17, 1
  %19 = tail call noundef i64 @_Z7ask_segiii(i32 noundef %18, i32 noundef %1, i32 noundef %2)
  br label %20

20:                                               ; preds = %16, %15
  %.0 = phi i64 [ %19, %16 ], [ 0, %15 ]
  %21 = tail call noundef i64 @_Z3gcdxx(i64 noundef %.020, i64 noundef %.0)
  %22 = tail call noundef i64 @_ZSt3absx(i64 noundef %21)
  br label %23

23:                                               ; preds = %20, %7
  %.021 = phi i64 [ %9, %7 ], [ %22, %20 ]
  ret i64 %.021
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_ZTS11SegmentTree", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass