; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2016 Astar Contest - Round 2A/1003-Snacks.ll (Z3addiii)

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

@ql = external dso_local global i32, align 4
@qr = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@t = external dso_local global [800040 x %struct.segtree], 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 nounwind uwtable
declare dso_local void @_Z2pdi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addiii(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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z2pdi(i32 noundef %8)
  %9 = load i32, ptr @ql, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp sgt i32 %9, %10
  br i1 %11, label %16, label %12

12:                                               ; preds = %3
  %13 = load i32, ptr @qr, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %3
  br label %67

17:                                               ; preds = %12
  %18 = load i32, ptr @ql, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %35

21:                                               ; preds = %17
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr @qr, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %25, label %35

25:                                               ; preds = %21
  %26 = load i32, ptr @q, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.segtree, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = add nsw i64 %32, %27
  store i64 %33, ptr %31, align 8, !tbaa !9
  %34 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z2pdi(i32 noundef %34)
  br label %67

35:                                               ; preds = %21, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  %39 = ashr i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = shl i32 %40, 1
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z3addiii(i32 noundef %41, i32 noundef %42, i32 noundef %43)
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = shl i32 %44, 1
  %46 = or i32 %45, 1
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3addiii(i32 noundef %46, i32 noundef %48, i32 noundef %49)
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = shl i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.segtree, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = shl i32 %55, 1
  %57 = or i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.segtree, ptr %59, i32 0, i32 0
  %61 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %54, ptr noundef nonnull align 8 dereferenceable(8) %60)
  %62 = load i64, ptr %61, align 8, !tbaa !12
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.segtree, ptr %65, i32 0, i32 0
  store i64 %62, ptr %66, align 16, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %67

67:                                               ; preds = %35, %25, %16
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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 = { 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 = { inlinehint mustprogress nounwind 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 #4 = { 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, !11, i64 8}
!10 = !{!"_ZTS7segtree", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, 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"

%struct.segtree = type { i64, i64 }

@ql = external dso_local local_unnamed_addr global i32, align 4
@qr = external dso_local local_unnamed_addr global i32, align 4
@q = external dso_local local_unnamed_addr global i32, align 4
@t = external dso_local global [800040 x %struct.segtree], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z2pdi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3addiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  tail call void @_Z2pdi(i32 noundef %0)
  %4 = load i32, ptr @ql, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, %2
  br i1 %5, label %common.ret22, label %6

6:                                                ; preds = %3
  %7 = load i32, ptr @qr, align 4, !tbaa !5
  %8 = icmp slt i32 %7, %1
  br i1 %8, label %common.ret22, label %9

9:                                                ; preds = %6
  %.not = icmp sgt i32 %4, %1
  %.not21 = icmp slt i32 %7, %2
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %17, label %10

10:                                               ; preds = %9
  %11 = load i32, ptr @q, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %13, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = add nsw i64 %15, %12
  store i64 %16, ptr %14, align 8, !tbaa !9
  tail call void @_Z2pdi(i32 noundef %0)
  br label %common.ret22

common.ret22:                                     ; preds = %3, %6, %10, %17
  ret void

17:                                               ; preds = %9
  %18 = add nsw i32 %2, %1
  %19 = ashr i32 %18, 1
  %20 = shl i32 %0, 1
  tail call void @_Z3addiii(i32 noundef %20, i32 noundef %1, i32 noundef %19)
  %21 = or disjoint i32 %20, 1
  %22 = add nsw i32 %19, 1
  tail call void @_Z3addiii(i32 noundef %21, i32 noundef %22, i32 noundef %2)
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %23
  %25 = sext i32 %21 to i64
  %26 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %25
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef nonnull align 8 dereferenceable(8) %26)
  %28 = load i64, ptr %27, align 8, !tbaa !12
  %29 = sext i32 %0 to i64
  %30 = getelementptr inbounds [800040 x %struct.segtree], ptr @t, i64 0, i64 %29
  store i64 %28, ptr %30, align 16, !tbaa !13
  br label %common.ret22
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind 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 = { inlinehint mustprogress nounwind 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"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS7segtree", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}


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