; LLVM IR from tangjz/acm-icpc :: lydsy (3155)

; 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.BitTree = type { [131072 x i64] }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@num = external dso_local global [131072 x i32], align 16
@b = external dso_local global [2 x %struct.BitTree], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 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 i32, align 4
  %4 = alloca [11 x i8], align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 11, ptr %4) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %33, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %10, label %36

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %13)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) @b, i32 noundef %15, i64 noundef %20)
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %26, %31
  call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) getelementptr inbounds ([2 x %struct.BitTree], ptr @b, i64 0, i64 1), i32 noundef %21, i64 noundef %32)
  br label %33

33:                                               ; preds = %10
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

36:                                               ; preds = %6
  br label %37

37:                                               ; preds = %88, %36
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @m, align 4, !tbaa !5
  %40 = icmp ne i32 %38, 0
  br i1 %40, label %41, label %89

41:                                               ; preds = %37
  %42 = getelementptr inbounds [11 x i8], ptr %4, i64 0, i64 0
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %42, ptr noundef %2)
  %44 = getelementptr inbounds [11 x i8], ptr %4, i64 0, i64 0
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 81
  br i1 %47, label %48, label %60

48:                                               ; preds = %41
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = call noundef i64 @_ZN7BitTree5queryEi(ptr noundef nonnull align 8 dereferenceable(1048576) getelementptr inbounds ([2 x %struct.BitTree], ptr @b, i64 0, i64 1), i32 noundef %49)
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = call noundef i64 @_ZN7BitTree5queryEi(ptr noundef nonnull align 8 dereferenceable(1048576) @b, i32 noundef %51)
  %53 = load i32, ptr @n, align 4, !tbaa !5
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %52, %56
  %58 = sub nsw i64 %50, %57
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %58)
  br label %88

60:                                               ; preds = %41
  %61 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = sub nsw i32 %63, %67
  %69 = sext i32 %68 to i64
  call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) @b, i32 noundef %62, i64 noundef %69)
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = sub nsw i32 %71, %72
  %74 = add nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sub nsw i32 %76, %80
  %82 = sext i32 %81 to i64
  %83 = mul nsw i64 %75, %82
  call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) getelementptr inbounds ([2 x %struct.BitTree], ptr @b, i64 0, i64 1), i32 noundef %70, i64 noundef %83)
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = load i32, ptr %2, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %86
  store i32 %84, ptr %87, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %60, %48
  br label %37, !llvm.loop !12

89:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 11, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576), i32 noundef, i64 noundef) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN7BitTree5queryEi(ptr noundef nonnull align 8 dereferenceable(1048576), i32 noundef) #3 align 2

; 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 = { "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 = { 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 #4 = { 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"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


; 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.BitTree = type { [131072 x i64] }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@num = external dso_local global [131072 x i32], align 16
@b = external dso_local global [2 x %struct.BitTree], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [11 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 11, ptr nonnull %3) #4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not3 = icmp slt i32 %5, 1
  br i1 %.not3, label %.preheader, label %.lr.ph

.preheader.loopexit:                              ; preds = %.lr.ph
  %6 = trunc nuw i64 %indvars.iv.next to i32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %0
  %storemerge.lcssa = phi i32 [ 1, %0 ], [ %6, %.preheader.loopexit ]
  store i32 %storemerge.lcssa, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @m, align 4, !tbaa !5
  %.not15 = icmp eq i32 %7, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph6

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %9 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9)
  %11 = load i32, ptr %9, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) @b, i32 noundef %13, i64 noundef %12)
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %reass.sub = sub i32 %14, %13
  %15 = add i32 %reass.sub, 1
  %16 = sext i32 %15 to i64
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %16, %18
  tail call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) getelementptr inbounds (i8, ptr @b, i64 1048576), i32 noundef %13, i64 noundef %19)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %.not.not = icmp slt i64 %indvars.iv, %21
  br i1 %.not.not, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !9

.lr.ph6:                                          ; preds = %.preheader, %61
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %3, ptr noundef nonnull %1)
  %23 = load i8, ptr %3, align 1, !tbaa !11
  %24 = icmp eq i8 %23, 81
  br i1 %24, label %25, label %37

25:                                               ; preds = %.lr.ph6
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = call noundef i64 @_ZN7BitTree5queryEi(ptr noundef nonnull align 8 dereferenceable(1048576) getelementptr inbounds (i8, ptr @b, i64 1048576), i32 noundef %26)
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = call noundef i64 @_ZN7BitTree5queryEi(ptr noundef nonnull align 8 dereferenceable(1048576) @b, i32 noundef %28)
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %29, %33
  %35 = sub nsw i64 %27, %34
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %35)
  br label %61

37:                                               ; preds = %.lr.ph6
  %38 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sub nsw i32 %40, %43
  %45 = sext i32 %44 to i64
  call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) @b, i32 noundef %39, i64 noundef %45)
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %reass.sub7 = sub i32 %47, %46
  %48 = add i32 %reass.sub7, 1
  %49 = sext i32 %48 to i64
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %46 to i64
  %52 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sub nsw i32 %50, %53
  %55 = sext i32 %54 to i64
  %56 = mul nsw i64 %55, %49
  call void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576) getelementptr inbounds (i8, ptr @b, i64 1048576), i32 noundef %46, i64 noundef %56)
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = load i32, ptr %1, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [131072 x i32], ptr @num, i64 0, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %37, %25
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @m, align 4, !tbaa !5
  %.not1 = icmp eq i32 %62, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph6, !llvm.loop !12

._crit_edge:                                      ; preds = %61, %.preheader
  call void @llvm.lifetime.end.p0(i64 11, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7BitTree3addEix(ptr noundef nonnull align 8 dereferenceable(1048576), i32 noundef, i64 noundef) local_unnamed_addr #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN7BitTree5queryEi(ptr noundef nonnull align 8 dereferenceable(1048576), i32 noundef) local_unnamed_addr #3 align 2

; 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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


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