; LLVM IR from tangjz/acm-icpc :: hdu/5261.ll (Z5buildiii)

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

@resL = external dso_local global [262144 x i32], align 16
@r = external dso_local global i64, align 8
@h = external dso_local global [131072 x i64], align 16
@seg = external dso_local global [262144 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %35

11:                                               ; preds = %3
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [131072 x i64], ptr @h, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = load i64, ptr @r, align 8, !tbaa !9
  %19 = mul nsw i64 %17, %18
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = mul nsw i64 %19, %21
  %23 = add nsw i64 %15, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = call noundef i32 @_Z2idii(i32 noundef %24, i32 noundef %25)
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %27
  store i64 %23, ptr %28, align 8, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = call noundef i32 @_Z2idii(i32 noundef %30, i32 noundef %31)
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %33
  store i32 %29, ptr %34, align 4, !tbaa !5
  br label %105

35:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  %39 = ashr i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %40, i32 noundef %41, i32 noundef %42)
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %44, i32 noundef %45, i32 noundef %46)
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = call noundef i32 @_Z2idii(i32 noundef %47, i32 noundef %48)
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = call noundef i32 @_Z2idii(i32 noundef %54, i32 noundef %55)
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = icmp sge i64 %52, %59
  br i1 %60, label %61, label %73

61:                                               ; preds = %35
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = call noundef i32 @_Z2idii(i32 noundef %62, i32 noundef %63)
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = call noundef i32 @_Z2idii(i32 noundef %68, i32 noundef %69)
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %71
  store i32 %67, ptr %72, align 4, !tbaa !5
  br label %86

73:                                               ; preds = %35
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = call noundef i32 @_Z2idii(i32 noundef %75, i32 noundef %76)
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = call noundef i32 @_Z2idii(i32 noundef %81, i32 noundef %82)
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %84
  store i32 %80, ptr %85, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %73, %61
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = call noundef i32 @_Z2idii(i32 noundef %87, i32 noundef %88)
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %90
  %92 = load i32, ptr %7, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = call noundef i32 @_Z2idii(i32 noundef %93, i32 noundef %94)
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %96
  %98 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %91, ptr noundef nonnull align 8 dereferenceable(8) %97)
  %99 = load i64, ptr %98, align 8, !tbaa !9
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = call noundef i32 @_Z2idii(i32 noundef %100, i32 noundef %101)
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %103
  store i64 %99, ptr %104, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %105

105:                                              ; preds = %86, %11
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z2idii(i32 noundef, i32 noundef) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long long", !7, 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"

@resL = external dso_local local_unnamed_addr global [262144 x i32], align 16
@r = external dso_local local_unnamed_addr global i64, align 8
@h = external dso_local local_unnamed_addr global [131072 x i64], align 16
@seg = external dso_local global [262144 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %0, %1
  br i1 %4, label %5, label %20

5:                                                ; preds = %3
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [131072 x i64], ptr @h, i64 0, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = load i64, ptr @r, align 8, !tbaa !5
  %10 = sext i32 %2 to i64
  %11 = mul nsw i64 %10, %6
  %12 = mul i64 %11, %9
  %13 = add nsw i64 %12, %8
  %14 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %0)
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %15
  store i64 %13, ptr %16, align 8, !tbaa !5
  %17 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %0)
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %18
  store i32 %0, ptr %19, align 4, !tbaa !9
  br label %54

20:                                               ; preds = %3
  %21 = add nsw i32 %1, %0
  %22 = ashr i32 %21, 1
  tail call void @_Z5buildiii(i32 noundef %0, i32 noundef %22, i32 noundef %2)
  %23 = add nsw i32 %22, 1
  tail call void @_Z5buildiii(i32 noundef %23, i32 noundef %1, i32 noundef %2)
  %24 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %22)
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = tail call noundef i32 @_Z2idii(i32 noundef %23, i32 noundef %1)
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %.not = icmp slt i64 %27, %31
  br i1 %.not, label %34, label %32

32:                                               ; preds = %20
  %33 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %22)
  br label %36

34:                                               ; preds = %20
  %35 = tail call noundef i32 @_Z2idii(i32 noundef %23, i32 noundef %1)
  br label %36

36:                                               ; preds = %34, %32
  %.sink42 = phi i32 [ %35, %34 ], [ %33, %32 ]
  %37 = sext i32 %.sink42 to i64
  %38 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %1)
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !9
  %43 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %22)
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %44
  %46 = tail call noundef i32 @_Z2idii(i32 noundef %23, i32 noundef %1)
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %47
  %49 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %45, ptr noundef nonnull align 8 dereferenceable(8) %48)
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = tail call noundef i32 @_Z2idii(i32 noundef %0, i32 noundef %1)
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %52
  store i64 %50, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %36, %5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z2idii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 = { 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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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