; LLVM IR from upupming/algorithm :: kick-start/2020/RoundC/D. Candies.ll (Z6changeiii)

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

@t = external dso_local global [800040 x %struct.SegmentTree], align 16

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

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6changeiii(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
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.SegmentTree, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 16, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.SegmentTree, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = icmp eq i32 %12, %17
  br i1 %18, label %19, label %54

19:                                               ; preds = %3
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.SegmentTree, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 16, !tbaa !9
  %25 = call noundef i32 @_Z4signi(i32 noundef %24)
  %26 = sub nsw i32 0, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.SegmentTree, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 16, !tbaa !9
  %32 = mul nsw i32 %26, %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = mul nsw i32 %32, %33
  %35 = sext i32 %34 to i64
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.SegmentTree, ptr %38, i32 0, i32 2
  store i64 %35, ptr %39, align 8, !tbaa !13
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.SegmentTree, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 16, !tbaa !9
  %45 = call noundef i32 @_Z4signi(i32 noundef %44)
  %46 = sub nsw i32 0, %45
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = mul nsw i32 %46, %47
  %49 = sext i32 %48 to i64
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.SegmentTree, ptr %52, i32 0, i32 3
  store i64 %49, ptr %53, align 16, !tbaa !14
  br label %118

54:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.SegmentTree, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 16, !tbaa !9
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.SegmentTree, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !12
  %65 = add nsw i32 %59, %64
  %66 = ashr i32 %65, 1
  store i32 %66, ptr %7, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = icmp sle i32 %67, %68
  br i1 %69, label %70, label %75

70:                                               ; preds = %54
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = mul nsw i32 2, %71
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z6changeiii(i32 noundef %72, i32 noundef %73, i32 noundef %74)
  br label %81

75:                                               ; preds = %54
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = mul nsw i32 2, %76
  %78 = add nsw i32 %77, 1
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z6changeiii(i32 noundef %78, i32 noundef %79, i32 noundef %80)
  br label %81

81:                                               ; preds = %75, %70
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = mul nsw i32 2, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.SegmentTree, ptr %85, i32 0, i32 2
  %87 = load i64, ptr %86, align 8, !tbaa !13
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = mul nsw i32 2, %88
  %90 = add nsw i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.SegmentTree, ptr %92, i32 0, i32 2
  %94 = load i64, ptr %93, align 8, !tbaa !13
  %95 = add nsw i64 %87, %94
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.SegmentTree, ptr %98, i32 0, i32 2
  store i64 %95, ptr %99, align 8, !tbaa !13
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = mul nsw i32 2, %100
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %102
  %104 = getelementptr inbounds %struct.SegmentTree, ptr %103, i32 0, i32 3
  %105 = load i64, ptr %104, align 16, !tbaa !14
  %106 = load i32, ptr %4, align 4, !tbaa !5
  %107 = mul nsw i32 2, %106
  %108 = add nsw i32 %107, 1
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %109
  %111 = getelementptr inbounds %struct.SegmentTree, ptr %110, i32 0, i32 3
  %112 = load i64, ptr %111, align 16, !tbaa !14
  %113 = add nsw i64 %105, %112
  %114 = load i32, ptr %4, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %115
  %117 = getelementptr inbounds %struct.SegmentTree, ptr %116, i32 0, i32 3
  store i64 %113, ptr %117, align 16, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %118

118:                                              ; preds = %81, %19
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!10 = !{!"_ZTS11SegmentTree", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 16}


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

@t = external dso_local local_unnamed_addr global [800040 x %struct.SegmentTree], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6changeiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %4
  %6 = load i32, ptr %5, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp eq i32 %6, %8
  br i1 %9, label %10, label %22

10:                                               ; preds = %3
  %11 = tail call noundef i32 @_Z4signi(i32 noundef %6)
  %12 = load i32, ptr %5, align 16, !tbaa !5
  %13 = mul i32 %11, %2
  %14 = mul i32 %13, %12
  %15 = sub i32 0, %14
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %16, ptr %17, align 8, !tbaa !12
  %18 = tail call noundef i32 @_Z4signi(i32 noundef %12)
  %19 = mul i32 %18, %2
  %20 = sub i32 0, %19
  %21 = sext i32 %20 to i64
  br label %45

22:                                               ; preds = %3
  %23 = add nsw i32 %8, %6
  %24 = ashr i32 %23, 1
  %.not = icmp slt i32 %24, %1
  %25 = shl nsw i32 %0, 1
  br i1 %.not, label %27, label %26

26:                                               ; preds = %22
  tail call void @_Z6changeiii(i32 noundef %25, i32 noundef %1, i32 noundef %2)
  %.pre = or disjoint i32 %25, 1
  br label %29

27:                                               ; preds = %22
  %28 = or disjoint i32 %25, 1
  tail call void @_Z6changeiii(i32 noundef %28, i32 noundef %1, i32 noundef %2)
  br label %29

29:                                               ; preds = %27, %26
  %.pre-phi28 = phi i32 [ %28, %27 ], [ %.pre, %26 ]
  %30 = sext i32 %25 to i64
  %31 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %30
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load i64, ptr %32, align 8, !tbaa !12
  %34 = sext i32 %.pre-phi28 to i64
  %35 = getelementptr inbounds [800040 x %struct.SegmentTree], ptr @t, i64 0, i64 %34
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load i64, ptr %36, align 8, !tbaa !12
  %38 = add nsw i64 %37, %33
  %39 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %38, ptr %39, align 8, !tbaa !12
  %40 = getelementptr inbounds i8, ptr %31, i64 16
  %41 = load i64, ptr %40, align 16, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %35, i64 16
  %43 = load i64, ptr %42, align 16, !tbaa !13
  %44 = add nsw i64 %43, %41
  br label %45

45:                                               ; preds = %29, %10
  %.sink = phi i64 [ %44, %29 ], [ %21, %10 ]
  %46 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 %.sink, ptr %46, align 16, !tbaa !13
  ret void
}

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

!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, !7, i64 0}
!6 = !{!"_ZTS11SegmentTree", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 16}


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