; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions/GSS1.ll (Z7combine4nodeS_)

; 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 { i64, i64, i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8makeNodellll(ptr dead_on_unwind noalias writable sret(%struct.node) align 8, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7combine4nodeS_(ptr dead_on_unwind noalias writable sret(%struct.node) align 8 %0, ptr noundef byval(%struct.node) align 8 %1, ptr noundef byval(%struct.node) align 8 %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %9, ptr %4, align 8, !tbaa !10
  %10 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 2
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = add nsw i64 %11, %13
  %15 = load i64, ptr %4, align 8, !tbaa !10
  %16 = icmp sgt i64 %14, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %3
  %18 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = add nsw i64 %19, %21
  store i64 %22, ptr %4, align 8, !tbaa !10
  br label %23

23:                                               ; preds = %17, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %24 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !12
  store i64 %25, ptr %5, align 8, !tbaa !10
  %26 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !12
  %30 = add nsw i64 %27, %29
  %31 = load i64, ptr %5, align 8, !tbaa !10
  %32 = icmp sgt i64 %30, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %23
  %34 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 3
  %37 = load i64, ptr %36, align 8, !tbaa !12
  %38 = add nsw i64 %35, %37
  store i64 %38, ptr %5, align 8, !tbaa !10
  br label %39

39:                                               ; preds = %33, %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %40 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = add nsw i64 %41, %43
  store i64 %44, ptr %7, align 8, !tbaa !10
  %45 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 1
  %46 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 1
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %45, ptr noundef nonnull align 8 dereferenceable(8) %46)
  %48 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %47)
  %49 = load i64, ptr %48, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  store i64 %49, ptr %6, align 8, !tbaa !10
  %50 = getelementptr inbounds %struct.node, ptr %1, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.node, ptr %2, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = add nsw i64 %51, %53
  %55 = load i64, ptr %6, align 8, !tbaa !10
  %56 = load i64, ptr %4, align 8, !tbaa !10
  %57 = load i64, ptr %5, align 8, !tbaa !10
  call void @_Z8makeNodellll(ptr dead_on_unwind writable sret(%struct.node) align 8 %0, i64 noundef %54, i64 noundef %55, i64 noundef %56, i64 noundef %57)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  ret void
}

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

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

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 16}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 24}


; 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 { i64, i64, i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8makeNodellll(ptr dead_on_unwind noalias writable sret(%struct.node) align 8, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7combine4nodeS_(ptr dead_on_unwind noalias writable sret(%struct.node) align 8 %0, ptr noundef byval(%struct.node) align 8 %1, ptr noundef byval(%struct.node) align 8 %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = load i64, ptr %1, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %2, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = add nsw i64 %9, %7
  %spec.select = tail call i64 @llvm.smax.i64(i64 %10, i64 %6)
  %11 = getelementptr inbounds i8, ptr %2, i64 24
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = load i64, ptr %2, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = add nsw i64 %15, %13
  %.05 = tail call i64 @llvm.smax.i64(i64 %16, i64 %12)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %17 = add nsw i64 %15, %9
  store i64 %17, ptr %4, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull align 8 dereferenceable(8) %19)
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %20)
  %22 = load i64, ptr %21, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %23 = load i64, ptr %1, align 8, !tbaa !10
  %24 = load i64, ptr %2, align 8, !tbaa !10
  %25 = add nsw i64 %24, %23
  call void @_Z8makeNodellll(ptr dead_on_unwind writable sret(%struct.node) align 8 %0, i64 noundef %25, i64 noundef %22, i64 noundef %spec.select, i64 noundef %.05)
  ret void
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 16}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!7, !7, i64 0}


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