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

; 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: 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 @_Z7seg_mixRiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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 %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %4
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %24, label %18

18:                                               ; preds = %15, %4
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = add nsw i32 %20, %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %22, ptr %23, align 4, !tbaa !9
  br label %91

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr @tot, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @tot, align 4, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %28, ptr %29, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %36
  store i32 %33, ptr %37, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = add nsw i32 %49, %53
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %57
  store i32 %54, ptr %58, align 4, !tbaa !9
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = icmp eq i32 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %24
  store i32 1, ptr %10, align 4
  br label %89

63:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = add nsw i32 %64, %65
  %67 = ashr i32 %66, 1
  store i32 %67, ptr %11, align 4, !tbaa !9
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %70
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  call void @_Z7seg_mixRiiii(ptr noundef nonnull align 4 dereferenceable(4) %71, i32 noundef %75, i32 noundef %76, i32 noundef %77)
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %80
  %82 = load i32, ptr %6, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = load i32, ptr %11, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  %88 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z7seg_mixRiiii(ptr noundef nonnull align 4 dereferenceable(4) %81, i32 noundef %85, i32 noundef %87, i32 noundef %88)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  store i32 0, ptr %10, align 4
  br label %89

89:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %90 = load i32, ptr %10, align 4
  switch i32 %90, label %92 [
    i32 0, label %91
    i32 1, label %91
  ]

91:                                               ; preds = %89, %89, %18
  ret void

92:                                               ; preds = %89
  unreachable
}

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
@lch = external dso_local 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 nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z7seg_mixRiiii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %0, align 4, !tbaa !5
  %6 = icmp ne i32 %5, 0
  %7 = icmp ne i32 %1, 0
  %or.cond35 = and i1 %7, %6
  br i1 %or.cond35, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %.tr.lcssa = phi ptr [ %0, %4 ], [ %41, %tailrecurse ]
  %.tr29.lcssa = phi i32 [ %1, %4 ], [ %43, %tailrecurse ]
  %.lcssa = phi i32 [ %5, %4 ], [ %45, %tailrecurse ]
  %8 = add nsw i32 %.lcssa, %.tr29.lcssa
  store i32 %8, ptr %.tr.lcssa, align 4, !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %4, %tailrecurse
  %9 = phi i32 [ %45, %tailrecurse ], [ %5, %4 ]
  %.tr3038 = phi i32 [ %44, %tailrecurse ], [ %2, %4 ]
  %.tr2937 = phi i32 [ %43, %tailrecurse ], [ %1, %4 ]
  %.tr36 = phi ptr [ %41, %tailrecurse ], [ %0, %4 ]
  %10 = load i32, ptr @tot, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @tot, align 4, !tbaa !5
  store i32 %11, ptr %.tr36, align 4, !tbaa !5
  %12 = sext i32 %9 to i64
  %13 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %11 to i64
  %16 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %15
  store i32 %14, ptr %16, align 4, !tbaa !5
  %17 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %12
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr %.tr36, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  %22 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %12
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %.tr2937 to i64
  %25 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, %23
  %28 = load i32, ptr %.tr36, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  %31 = icmp eq i32 %.tr3038, %3
  br i1 %31, label %.loopexit, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph
  %32 = add nsw i32 %.tr3038, %3
  %33 = ashr i32 %32, 1
  %34 = load i32, ptr %.tr36, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %35
  %37 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %24
  %38 = load i32, ptr %37, align 4, !tbaa !5
  tail call void @_Z7seg_mixRiiii(ptr noundef nonnull align 4 dereferenceable(4) %36, i32 noundef %38, i32 noundef %.tr3038, i32 noundef %33)
  %39 = load i32, ptr %.tr36, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %40
  %42 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %24
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %33, 1
  %45 = load i32, ptr %41, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  %47 = icmp ne i32 %43, 0
  %or.cond = and i1 %47, %46
  br i1 %or.cond, label %.lr.ph, label %tailrecurse._crit_edge

.loopexit:                                        ; preds = %.lr.ph, %tailrecurse._crit_edge
  ret void
}

attributes #0 = { mustprogress nofree 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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass