; LLVM IR from tangjz/acm-icpc :: lydsy/3673.ll (Z6updateRiiiii)

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

@tot = external dso_local global i32, align 4
@pL = external dso_local global [8000001 x i32], align 16
@pR = external dso_local global [8000001 x i32], align 16
@dsu = external dso_local global [8000001 x i32], 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: mustprogress uwtable
define dso_local void @_Z6updateRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [8000001 x i32], ptr @pL, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = load i32, ptr @tot, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [8000001 x i32], ptr @pL, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [8000001 x i32], ptr @pR, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = load i32, ptr @tot, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [8000001 x i32], ptr @pR, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !9
  %28 = load i32, ptr @tot, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @tot, align 4, !tbaa !9
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %28, ptr %30, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %40

34:                                               ; preds = %5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [8000001 x i32], ptr @dsu, i64 0, i64 %38
  store i32 %35, ptr %39, align 4, !tbaa !9
  br label %68

40:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = add nsw i32 %41, %42
  %44 = ashr i32 %43, 1
  store i32 %44, ptr %11, align 4, !tbaa !9
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %48, label %57

48:                                               ; preds = %40
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [8000001 x i32], ptr @pL, i64 0, i64 %51
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z6updateRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %52, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  br label %67

57:                                               ; preds = %40
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [8000001 x i32], ptr @pR, i64 0, i64 %60
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z6updateRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %61, i32 noundef %63, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  br label %67

67:                                               ; preds = %57, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %68

68:                                               ; preds = %67, %34
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@pL = external dso_local local_unnamed_addr global [8000001 x i32], align 16
@pR = external dso_local local_unnamed_addr global [8000001 x i32], align 16
@dsu = external dso_local local_unnamed_addr global [8000001 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z6updateRiiiii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %25, %5
  %.tr.ph = phi ptr [ %26, %25 ], [ %0, %5 ]
  %.tr24.ph = phi i32 [ %27, %25 ], [ %1, %5 ]
  %.tr25.ph = phi i32 [ %.tr25, %25 ], [ %2, %5 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %22
  %.tr = phi ptr [ %12, %22 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr25 = phi i32 [ %24, %22 ], [ %.tr25.ph, %tailrecurse.outer ]
  %6 = load i32, ptr %.tr, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [8000001 x i32], ptr @pL, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr @tot, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [8000001 x i32], ptr @pL, i64 0, i64 %11
  store i32 %9, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %.tr, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [8000001 x i32], ptr @pR, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds [8000001 x i32], ptr @pR, i64 0, i64 %11
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = add nsw i32 %10, 1
  store i32 %18, ptr @tot, align 4, !tbaa !5
  store i32 %10, ptr %.tr, align 4, !tbaa !5
  %19 = icmp eq i32 %.tr24.ph, %.tr25
  br i1 %19, label %20, label %22

20:                                               ; preds = %tailrecurse
  %21 = getelementptr inbounds [8000001 x i32], ptr @dsu, i64 0, i64 %11
  store i32 %4, ptr %21, align 4, !tbaa !5
  ret void

22:                                               ; preds = %tailrecurse
  %23 = add nsw i32 %.tr25, %.tr24.ph
  %24 = ashr i32 %23, 1
  %.not = icmp slt i32 %24, %3
  br i1 %.not, label %25, label %tailrecurse

25:                                               ; preds = %22
  %26 = getelementptr inbounds [8000001 x i32], ptr @pR, i64 0, i64 %11
  %27 = add nsw i32 %24, 1
  br label %tailrecurse.outer
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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