; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2016复赛/1004.ll (Z3addRiiii)

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

@c = external dso_local global [2 x [4000005 x i32]], align 16
@s = external dso_local global [4000005 x i32], align 16
@tot = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = 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
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %28, label %12

12:                                               ; preds = %4
  %13 = load i32, ptr @tot, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @tot, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %14, ptr %15, align 4, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4000005 x i32], ptr @s, i64 0, i64 %18
  store i32 0, ptr %19, align 4, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4000005 x i32], ptr getelementptr inbounds ([2 x [4000005 x i32]], ptr @c, i64 0, i64 1), i64 0, i64 %22
  store i32 0, ptr %23, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4000005 x i32], ptr @c, i64 0, i64 %26
  store i32 0, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %12, %4
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4000005 x i32], ptr @s, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = add nsw i32 %34, %29
  store i32 %35, ptr %33, align 4, !tbaa !9
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %28
  br label %63

39:                                               ; preds = %28
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = shl i32 1, %41
  %43 = and i32 %40, %42
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %54

45:                                               ; preds = %39
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4000005 x i32], ptr getelementptr inbounds ([2 x [4000005 x i32]], ptr @c, i64 0, i64 1), i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %49, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  br label %63

54:                                               ; preds = %39
  %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 [4000005 x i32], ptr @c, i64 0, i64 %57
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = sub nsw i32 %59, 1
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %58, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  br label %63

63:                                               ; preds = %54, %45, %38
  ret void
}

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

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

@c = external dso_local local_unnamed_addr global [2 x [4000005 x i32]], align 16
@s = external dso_local local_unnamed_addr global [4000005 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4

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

tailrecurse:                                      ; preds = %tailrecurse.backedge, %4
  %.tr = phi ptr [ %0, %4 ], [ %28, %tailrecurse.backedge ]
  %.tr18 = phi i32 [ %1, %4 ], [ %.tr18.be, %tailrecurse.backedge ]
  %5 = load i32, ptr %.tr, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %17

6:                                                ; preds = %tailrecurse
  %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 %8 to i64
  %10 = getelementptr inbounds [4000005 x i32], ptr @s, i64 0, i64 %9
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr %.tr, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [4000005 x i32], ptr getelementptr inbounds (i8, ptr @c, i64 16000020), i64 0, i64 %12
  store i32 0, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %.tr, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4000005 x i32], ptr @c, i64 0, i64 %15
  store i32 0, ptr %16, align 4, !tbaa !5
  %.pre = load i32, ptr %.tr, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %6, %tailrecurse
  %18 = phi i32 [ %.pre, %6 ], [ %5, %tailrecurse ]
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4000005 x i32], ptr @s, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, %3
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = icmp slt i32 %.tr18, 0
  br i1 %23, label %29, label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %17
  %24 = shl nuw i32 1, %.tr18
  %25 = and i32 %24, %2
  %.not17 = icmp eq i32 %25, 0
  %26 = load i32, ptr %.tr, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %spec.select = select i1 %.not17, ptr @c, ptr getelementptr inbounds (i8, ptr @c, i64 16000020)
  %28 = getelementptr inbounds [4000005 x i32], ptr %spec.select, i64 0, i64 %27
  %.tr18.be = add nsw i32 %.tr18, -1
  br label %tailrecurse

29:                                               ; preds = %17
  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,IPSCCPPass,InstCombinePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass