; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Easy Medium/SORTING/A.ll (Z6updateP4nodeiiii)

; 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 <{ ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateP4nodeiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %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 ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = add nsw i32 %17, %14
  store i32 %18, ptr %16, align 8, !tbaa !11
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %5
  br label %101

23:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = add nsw i32 %24, %25
  %27 = sdiv i32 %26, 2
  store i32 %27, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %31, label %65

31:                                               ; preds = %23
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %45

36:                                               ; preds = %31
  %37 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %37)
          to label %38 unwind label %41

38:                                               ; preds = %36
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 0
  store ptr %37, ptr %40, align 8, !tbaa !13
  br label %57

41:                                               ; preds = %36
  %42 = landingpad { ptr, i32 }
          cleanup
  %43 = extractvalue { ptr, i32 } %42, 0
  store ptr %43, ptr %12, align 8
  %44 = extractvalue { ptr, i32 } %42, 1
  store i32 %44, ptr %13, align 4
  call void @_ZdlPvm(ptr noundef %37, i64 noundef 24) #7
  br label %102

45:                                               ; preds = %31
  %46 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  invoke void @_ZN4nodeC2EPS_(ptr noundef nonnull align 8 dereferenceable(20) %46, ptr noundef %49)
          to label %50 unwind label %53

50:                                               ; preds = %45
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 0
  store ptr %46, ptr %52, align 8, !tbaa !13
  br label %57

53:                                               ; preds = %45
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %12, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %13, align 4
  call void @_ZdlPvm(ptr noundef %46, i64 noundef 24) #7
  br label %102

57:                                               ; preds = %50, %38
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = load i32, ptr %11, align 4, !tbaa !9
  call void @_Z6updateP4nodeiiii(ptr noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64)
  br label %100

65:                                               ; preds = %23
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = icmp eq ptr %68, null
  br i1 %69, label %70, label %79

70:                                               ; preds = %65
  %71 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %71)
          to label %72 unwind label %75

72:                                               ; preds = %70
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.node, ptr %73, i32 0, i32 1
  store ptr %71, ptr %74, align 8, !tbaa !14
  br label %91

75:                                               ; preds = %70
  %76 = landingpad { ptr, i32 }
          cleanup
  %77 = extractvalue { ptr, i32 } %76, 0
  store ptr %77, ptr %12, align 8
  %78 = extractvalue { ptr, i32 } %76, 1
  store i32 %78, ptr %13, align 4
  call void @_ZdlPvm(ptr noundef %71, i64 noundef 24) #7
  br label %102

79:                                               ; preds = %65
  %80 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.node, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  invoke void @_ZN4nodeC2EPS_(ptr noundef nonnull align 8 dereferenceable(20) %80, ptr noundef %83)
          to label %84 unwind label %87

84:                                               ; preds = %79
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 1
  store ptr %80, ptr %86, align 8, !tbaa !14
  br label %91

87:                                               ; preds = %79
  %88 = landingpad { ptr, i32 }
          cleanup
  %89 = extractvalue { ptr, i32 } %88, 0
  store ptr %89, ptr %12, align 8
  %90 = extractvalue { ptr, i32 } %88, 1
  store i32 %90, ptr %13, align 4
  call void @_ZdlPvm(ptr noundef %80, i64 noundef 24) #7
  br label %102

91:                                               ; preds = %84, %72
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.node, ptr %92, i32 0, i32 1
  %94 = load ptr, ptr %93, align 8, !tbaa !14
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = load i32, ptr %8, align 4, !tbaa !9
  %97 = load i32, ptr %11, align 4, !tbaa !9
  %98 = add nsw i32 %97, 1
  %99 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z6updateP4nodeiiii(ptr noundef %94, i32 noundef %95, i32 noundef %96, i32 noundef %98, i32 noundef %99)
  br label %100

100:                                              ; preds = %91, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %101

101:                                              ; preds = %100, %22
  ret void

102:                                              ; preds = %87, %75, %53, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %103

103:                                              ; preds = %102
  %104 = load ptr, ptr %12, align 8
  %105 = load i32, ptr %13, align 4
  %106 = insertvalue { ptr, i32 } poison, ptr %104, 0
  %107 = insertvalue { ptr, i32 } %106, i32 %105, 1
  resume { ptr, i32 } %107
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2EPS_(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 = { 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 = { nobuiltin nounwind "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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !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"

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateP4nodeiiii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = add nsw i32 %7, %2
  store i32 %8, ptr %6, align 8, !tbaa !5
  %9 = icmp eq i32 %3, %4
  br i1 %9, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %.tr33.ph40 = phi i32 [ %.tr3337, %tailrecurse.outer ], [ %4, %5 ]
  %.tr32.ph39 = phi i32 [ %30, %tailrecurse.outer ], [ %3, %5 ]
  %.tr.ph38 = phi ptr [ %27, %tailrecurse.outer ], [ %0, %5 ]
  br label %10

10:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr3337 = phi i32 [ %.tr33.ph40, %.lr.ph ], [ %12, %tailrecurse ]
  %.tr36 = phi ptr [ %.tr.ph38, %.lr.ph ], [ %16, %tailrecurse ]
  %11 = add nsw i32 %.tr3337, %.tr32.ph39
  %12 = sdiv i32 %11, 2
  %.not = icmp slt i32 %12, %1
  br i1 %.not, label %23, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %.tr36, align 8, !tbaa !11
  %15 = icmp eq ptr %14, null
  %16 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  br i1 %15, label %17, label %18

17:                                               ; preds = %13
  tail call void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %16)
  br label %tailrecurse

18:                                               ; preds = %13
  tail call void @_ZN4nodeC2EPS_(ptr noundef nonnull align 8 dereferenceable(20) %16, ptr noundef nonnull %14)
  br label %tailrecurse

tailrecurse:                                      ; preds = %18, %17
  store ptr %16, ptr %.tr36, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %16, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !5
  %21 = add nsw i32 %20, %2
  store i32 %21, ptr %19, align 8, !tbaa !5
  %22 = icmp eq i32 %.tr32.ph39, %12
  br i1 %22, label %tailrecurse.outer._crit_edge, label %10

23:                                               ; preds = %10
  %24 = getelementptr inbounds i8, ptr %.tr36, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = icmp eq ptr %25, null
  %27 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  br i1 %26, label %28, label %29

28:                                               ; preds = %23
  tail call void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %27)
  br label %tailrecurse.outer

29:                                               ; preds = %23
  tail call void @_ZN4nodeC2EPS_(ptr noundef nonnull align 8 dereferenceable(20) %27, ptr noundef nonnull %25)
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %29, %28
  store ptr %27, ptr %24, align 8, !tbaa !12
  %30 = add nsw i32 %12, 1
  %31 = getelementptr inbounds i8, ptr %27, i64 16
  %32 = load i32, ptr %31, align 8, !tbaa !5
  %33 = add nsw i32 %32, %2
  store i32 %33, ptr %31, align 8, !tbaa !5
  %34 = icmp eq i32 %30, %.tr3337
  br i1 %34, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2EPS_(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) unnamed_addr #2 align 2

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" }
attributes #1 = { nobuiltin allocsize(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 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 #3 = { builtin allocsize(0) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass