; LLVM IR from tangjz/acm-icpc :: hdu/5709.ll (Z7seg_updRiiiii)

; 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
@lch = external dso_local global [10200103 x i32], align 16
@rch = external dso_local global [10200103 x i32], align 16
@val = external dso_local global [10200103 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %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
  %12 = alloca i32, align 4
  %13 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %15, ptr %11, align 4, !tbaa !9
  %16 = load i32, ptr @tot, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @tot, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !9
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %25
  store i32 %22, ptr %26, align 4, !tbaa !9
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %33
  store i32 %30, ptr %34, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = add nsw i32 %38, %39
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %43
  store i32 %40, ptr %44, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %5
  store i32 1, ptr %12, align 4
  br label %77

49:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = add nsw i32 %50, %51
  %53 = ashr i32 %52, 1
  store i32 %53, ptr %13, align 4, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = icmp sle i32 %54, %55
  br i1 %56, label %57, label %66

57:                                               ; preds = %49
  %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 [10200103 x i32], ptr @lch, i64 0, i64 %60
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %61, i32 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  br label %76

66:                                               ; preds = %49
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %69
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z7seg_updRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %70, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75)
  br label %76

76:                                               ; preds = %66, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  store i32 0, ptr %12, align 4
  br label %77

77:                                               ; preds = %76, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  %78 = load i32, ptr %12, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

79:                                               ; preds = %77, %77
  ret void

80:                                               ; preds = %77
  unreachable
}

; 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

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 = { 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
@lch = external dso_local local_unnamed_addr global [10200103 x i32], align 16
@rch = external dso_local local_unnamed_addr global [10200103 x i32], align 16
@val = external dso_local local_unnamed_addr global [10200103 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z7seg_updRiiiii(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 = %33, %5
  %.tr.ph = phi ptr [ %34, %33 ], [ %0, %5 ]
  %.tr28.ph = phi i32 [ %35, %33 ], [ %1, %5 ]
  %.tr29.ph = phi i32 [ %.tr29, %33 ], [ %2, %5 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %31
  %.tr = phi ptr [ %32, %31 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr29 = phi i32 [ %28, %31 ], [ %.tr29.ph, %tailrecurse.outer ]
  %6 = load i32, ptr %.tr, align 4, !tbaa !5
  %7 = load i32, ptr @tot, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @tot, align 4, !tbaa !5
  store i32 %8, ptr %.tr, align 4, !tbaa !5
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %8 to i64
  %13 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %12
  store i32 %11, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %9
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = load i32, ptr %.tr, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %17
  store i32 %15, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %9
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %4
  %22 = load i32, ptr %.tr, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  %25 = icmp eq i32 %.tr28.ph, %.tr29
  br i1 %25, label %36, label %26

26:                                               ; preds = %tailrecurse
  %27 = add nsw i32 %.tr29, %.tr28.ph
  %28 = ashr i32 %27, 1
  %.not = icmp slt i32 %28, %3
  %29 = load i32, ptr %.tr, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  br i1 %.not, label %33, label %31

31:                                               ; preds = %26
  %32 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %30
  br label %tailrecurse

33:                                               ; preds = %26
  %34 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %30
  %35 = add nsw i32 %28, 1
  br label %tailrecurse.outer

36:                                               ; preds = %tailrecurse
  ret void
}

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,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass