; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 10/1960. Palindromes and Super Abilities.ll (Z3addii)

; 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, ptr, [26 x ptr] }

@root_even = external dso_local global ptr, align 8
@root_odd = external dso_local global ptr, align 8
@last = external dso_local global ptr, align 8
@cnt = external dso_local global i32, align 4

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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z10findParentii(i32 noundef, i32 noundef) #3

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z9find_linkP4nodeii(ptr noundef, i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addii(i32 noundef %0, i32 noundef %1) #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = call noundef ptr @_Z10findParentii(i32 noundef %9, i32 noundef %10)
  store ptr %11, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.node, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [26 x ptr], ptr %13, i64 0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %53

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %20 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 224) #6
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = add nsw i32 %23, 2
  invoke void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(224) %20, i32 noundef %24)
          to label %25 unwind label %39

25:                                               ; preds = %19
  store ptr %20, ptr %6, align 8, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [26 x ptr], ptr %28, i64 0, i64 %30
  store ptr %26, ptr %31, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load ptr, ptr @root_odd, align 8, !tbaa !9
  %34 = icmp eq ptr %32, %33
  br i1 %34, label %35, label %43

35:                                               ; preds = %25
  %36 = load ptr, ptr @root_even, align 8, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !13
  br label %50

39:                                               ; preds = %19
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %7, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %20, i64 noundef 224) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %60

43:                                               ; preds = %25
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = call noundef ptr @_Z9find_linkP4nodeii(ptr noundef %44, i32 noundef %45, i32 noundef %46)
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 1
  store ptr %47, ptr %49, align 8, !tbaa !13
  br label %50

50:                                               ; preds = %43, %35
  %51 = load i32, ptr @cnt, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr @cnt, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %53

53:                                               ; preds = %50, %2
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [26 x ptr], ptr %55, i64 0, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  store ptr %59, ptr @last, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void

60:                                               ; preds = %39
  %61 = load ptr, ptr %7, align 8
  %62 = load i32, ptr %8, align 4
  %63 = insertvalue { ptr, i32 } poison, ptr %61, 0
  %64 = insertvalue { ptr, i32 } %63, i32 %62, 1
  resume { ptr, i32 } %64
}

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

@root_even = external dso_local local_unnamed_addr global ptr, align 8
@root_odd = external dso_local local_unnamed_addr global ptr, align 8
@last = external dso_local local_unnamed_addr global ptr, align 8
@cnt = external dso_local local_unnamed_addr global i32, align 4

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(224), i32 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z10findParentii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z9find_linkP4nodeii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noundef ptr @_Z10findParentii(i32 noundef %0, i32 noundef %1)
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds [26 x ptr], ptr %4, i64 0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %23

9:                                                ; preds = %2
  %10 = tail call noalias noundef nonnull dereferenceable(224) ptr @_Znwm(i64 noundef 224) #3
  %11 = load i32, ptr %3, align 8, !tbaa !9
  %12 = add nsw i32 %11, 2
  tail call void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(224) %10, i32 noundef %12)
  store ptr %10, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr @root_odd, align 8, !tbaa !5
  %14 = icmp eq ptr %3, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %9
  %16 = load ptr, ptr @root_even, align 8, !tbaa !5
  br label %19

17:                                               ; preds = %9
  %18 = tail call noundef ptr @_Z9find_linkP4nodeii(ptr noundef nonnull %3, i32 noundef %0, i32 noundef %1)
  %.pre.pre = load ptr, ptr %6, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %17, %15
  %.pre = phi ptr [ %10, %15 ], [ %.pre.pre, %17 ]
  %.sink = phi ptr [ %16, %15 ], [ %18, %17 ]
  %20 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %.sink, ptr %20, align 8
  %21 = load i32, ptr @cnt, align 4, !tbaa !12
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @cnt, align 4, !tbaa !12
  br label %23

23:                                               ; preds = %19, %2
  %24 = phi ptr [ %.pre, %19 ], [ %7, %2 ]
  store ptr %24, ptr @last, align 8, !tbaa !5
  ret void
}

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


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