; LLVM IR from tangjz/acm-icpc :: codeforces/complete/757G.ll (Z8tree_updiii)

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

@tot = external dso_local global i32, align 4
@dis = external dso_local global [31 x [400001 x i64]], align 16
@tree = external dso_local global [20000001 x %struct.Info], align 16

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8tree_updiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  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
  %9 = load i32, ptr %7, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 31
  br i1 %10, label %20, label %11

11:                                               ; preds = %3
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [31 x [400001 x i64]], ptr @dis, i64 0, i64 %13
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [400001 x i64], ptr %14, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %22, label %20

20:                                               ; preds = %11, %3
  %21 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %21, ptr %4, align 4
  br label %111

22:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %23 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %23, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr @tot, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @tot, align 4, !tbaa !5
  store i32 %25, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %27
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %31, ptr align 16 %28, i64 32, i1 false), !tbaa.struct !11
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [31 x [400001 x i64]], ptr @dis, i64 0, i64 %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [400001 x i64], ptr %34, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %75

40:                                               ; preds = %22
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Info, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 8, !tbaa !12
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %44, align 8, !tbaa !12
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [31 x [400001 x i64]], ptr @dis, i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [400001 x i64], ptr %49, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = sub nsw i64 0, %53
  %55 = sub nsw i64 %54, 1
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.Info, ptr %58, i32 0, i32 4
  %60 = load i64, ptr %59, align 16, !tbaa !14
  %61 = add nsw i64 %60, %55
  store i64 %61, ptr %59, align 16, !tbaa !14
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.Info, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 16, !tbaa !15
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = call noundef i32 @_Z8tree_updiii(i32 noundef %66, i32 noundef %67, i32 noundef %69)
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.Info, ptr %73, i32 0, i32 0
  store i32 %70, ptr %74, align 16, !tbaa !15
  br label %109

75:                                               ; preds = %22
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.Info, ptr %78, i32 0, i32 3
  %80 = load i32, ptr %79, align 4, !tbaa !16
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %79, align 4, !tbaa !16
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [31 x [400001 x i64]], ptr @dis, i64 0, i64 %83
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [400001 x i64], ptr %84, i64 0, i64 %86
  %88 = load i64, ptr %87, align 8, !tbaa !9
  %89 = sub nsw i64 %88, 1
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.Info, ptr %92, i32 0, i32 5
  %94 = load i64, ptr %93, align 8, !tbaa !17
  %95 = add nsw i64 %94, %89
  store i64 %95, ptr %93, align 8, !tbaa !17
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.Info, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !18
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = load i32, ptr %7, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  %104 = call noundef i32 @_Z8tree_updiii(i32 noundef %100, i32 noundef %101, i32 noundef %103)
  %105 = load i32, ptr %5, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.Info, ptr %107, i32 0, i32 1
  store i32 %104, ptr %108, align 4, !tbaa !18
  br label %109

109:                                              ; preds = %75, %40
  %110 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %110, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %111

111:                                              ; preds = %109, %20
  %112 = load i32, ptr %4, align 4
  ret i32 %112
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = !{!"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}
!11 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 8, !9, i64 24, i64 8, !9}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS4Info", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !10, i64 16, !10, i64 24}
!14 = !{!13, !10, i64 16}
!15 = !{!13, !6, i64 0}
!16 = !{!13, !6, i64 12}
!17 = !{!13, !10, i64 24}
!18 = !{!13, !6, i64 4}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@dis = external dso_local local_unnamed_addr global [31 x [400001 x i64]], align 16
@tree = external dso_local local_unnamed_addr global [20000001 x %struct.Info], align 16

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z8tree_updiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp sgt i32 %2, 30
  br i1 %4, label %common.ret28, label %5

5:                                                ; preds = %3
  %6 = sext i32 %2 to i64
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds [31 x [400001 x i64]], ptr @dis, i64 0, i64 %6, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %common.ret28, label %10

10:                                               ; preds = %5
  %11 = load i32, ptr @tot, align 4, !tbaa !9
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @tot, align 4, !tbaa !9
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %13
  %15 = sext i32 %12 to i64
  %16 = getelementptr inbounds [20000001 x %struct.Info], ptr @tree, i64 0, i64 %15
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %16, ptr noundef nonnull align 16 dereferenceable(32) %14, i64 32, i1 false), !tbaa.struct !11
  %17 = icmp slt i64 %9, 0
  br i1 %17, label %18, label %29

common.ret28:                                     ; preds = %3, %5, %29, %18
  %common.ret28.op = phi i32 [ %12, %18 ], [ %12, %29 ], [ %0, %5 ], [ %0, %3 ]
  ret i32 %common.ret28.op

18:                                               ; preds = %10
  %19 = getelementptr inbounds i8, ptr %16, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 8, !tbaa !12
  %22 = xor i64 %9, -1
  %23 = getelementptr inbounds i8, ptr %16, i64 16
  %24 = load i64, ptr %23, align 16, !tbaa !14
  %25 = add nsw i64 %24, %22
  store i64 %25, ptr %23, align 16, !tbaa !14
  %26 = load i32, ptr %16, align 16, !tbaa !15
  %27 = add nsw i32 %2, 1
  %28 = tail call noundef i32 @_Z8tree_updiii(i32 noundef %26, i32 noundef %1, i32 noundef %27)
  store i32 %28, ptr %16, align 16, !tbaa !15
  br label %common.ret28

29:                                               ; preds = %10
  %30 = getelementptr inbounds i8, ptr %16, i64 12
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !16
  %33 = add nsw i64 %9, -1
  %34 = getelementptr inbounds i8, ptr %16, i64 24
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = add nsw i64 %33, %35
  store i64 %36, ptr %34, align 8, !tbaa !17
  %37 = getelementptr inbounds i8, ptr %16, i64 4
  %38 = load i32, ptr %37, align 4, !tbaa !18
  %39 = add nsw i32 %2, 1
  %40 = tail call noundef i32 @_Z8tree_updiii(i32 noundef %38, i32 noundef %1, i32 noundef %39)
  store i32 %40, ptr %37, align 4, !tbaa !18
  br label %common.ret28
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nosync nounwind memory(readwrite, 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 = !{!"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}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 8, !5, i64 24, i64 8, !5}
!12 = !{!13, !10, i64 8}
!13 = !{!"_ZTS4Info", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24}
!14 = !{!13, !6, i64 16}
!15 = !{!13, !10, i64 0}
!16 = !{!13, !10, i64 12}
!17 = !{!13, !6, i64 24}
!18 = !{!13, !10, i64 4}


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