; LLVM IR from viveakrt/Competitive-programing :: SPOJ/psegtree.ll (Z6updateiiiii)

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

@tree = external dso_local global [13107200 x %struct.node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5clonei(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 noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %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
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = call noundef i32 @_Z5clonei(i32 noundef %15)
  store i32 %16, ptr %12, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %20, label %29

20:                                               ; preds = %5
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = load i32, ptr %12, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = add nsw i32 %26, %21
  store i32 %27, ptr %25, align 4, !tbaa !9
  %28 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %28, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %93

29:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = sdiv i32 %32, 2
  store i32 %33, ptr %14, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = load i32, ptr %14, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %52

37:                                               ; preds = %29
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = call noundef i32 @_Z6updateiiiii(i32 noundef %38, i32 noundef %39, i32 noundef %44, i32 noundef %45, i32 noundef %46)
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 1
  store i32 %47, ptr %51, align 4, !tbaa !11
  br label %68

52:                                               ; preds = %29
  %53 = load i32, ptr %14, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = call noundef i32 @_Z6updateiiiii(i32 noundef %54, i32 noundef %55, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  %64 = load i32, ptr %12, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 2
  store i32 %63, ptr %67, align 4, !tbaa !12
  br label %68

68:                                               ; preds = %52, %37
  %69 = load i32, ptr %12, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !11
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.node, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = load i32, ptr %12, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.node, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %81, align 4, !tbaa !12
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.node, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !9
  %87 = add nsw i32 %77, %86
  %88 = load i32, ptr %12, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %89
  %91 = getelementptr inbounds %struct.node, ptr %90, i32 0, i32 0
  store i32 %87, ptr %91, align 4, !tbaa !9
  %92 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %92, ptr %6, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %93

93:                                               ; preds = %68, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %94 = load i32, ptr %6, align 4
  ret i32 %94
}

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 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}


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

@tree = external dso_local local_unnamed_addr global [13107200 x %struct.node], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call noundef i32 @_Z5clonei(i32 noundef %2)
  %7 = icmp eq i32 %0, %1
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %9
  br label %38

11:                                               ; preds = %5
  %12 = add nsw i32 %1, %0
  %13 = sdiv i32 %12, 2
  %.not = icmp slt i32 %13, %3
  br i1 %.not, label %21, label %14

14:                                               ; preds = %11
  %15 = sext i32 %2 to i64
  %16 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %15, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = tail call noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %13, i32 noundef %17, i32 noundef %3, i32 noundef %4)
  %19 = sext i32 %6 to i64
  %20 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %19, i32 1
  store i32 %18, ptr %20, align 4, !tbaa !5
  %.phi.trans.insert35 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %19, i32 2
  %.pre36 = load i32, ptr %.phi.trans.insert35, align 4, !tbaa !10
  br label %29

21:                                               ; preds = %11
  %22 = add nsw i32 %13, 1
  %23 = sext i32 %2 to i64
  %24 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %23, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !10
  %26 = tail call noundef i32 @_Z6updateiiiii(i32 noundef %22, i32 noundef %1, i32 noundef %25, i32 noundef %3, i32 noundef %4)
  %27 = sext i32 %6 to i64
  %28 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %27, i32 2
  store i32 %26, ptr %28, align 4, !tbaa !10
  %.phi.trans.insert32 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %27, i32 1
  %.pre = load i32, ptr %.phi.trans.insert32, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %21, %14
  %.pre-phi = phi i64 [ %27, %21 ], [ %19, %14 ]
  %30 = phi i32 [ %26, %21 ], [ %.pre36, %14 ]
  %31 = phi i32 [ %.pre, %21 ], [ %18, %14 ]
  %32 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %.pre-phi
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = sext i32 %30 to i64
  %37 = getelementptr inbounds [13107200 x %struct.node], ptr @tree, i64 0, i64 %36
  br label %38

38:                                               ; preds = %29, %8
  %.sink = phi ptr [ %37, %29 ], [ %10, %8 ]
  %.sink39 = phi i32 [ %35, %29 ], [ %4, %8 ]
  %.sink37 = phi ptr [ %32, %29 ], [ %10, %8 ]
  %39 = load i32, ptr %.sink, align 4, !tbaa !11
  %40 = add nsw i32 %39, %.sink39
  store i32 %40, ptr %.sink37, align 4, !tbaa !11
  ret i32 %6
}

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


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