; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/COT/ref.ll (ZN4node6insertEiii)

; 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, ptr }

@null = external dso_local global ptr, align 8

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

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4node6insertEiii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #3 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = 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
  %13 = load ptr, ptr %6, align 8
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %66

17:                                               ; preds = %4
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %66

21:                                               ; preds = %17
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %38

26:                                               ; preds = %21
  %27 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #5
  %28 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = add nsw i32 %29, 1
  %31 = load ptr, ptr @null, align 8, !tbaa !5
  %32 = load ptr, ptr @null, align 8, !tbaa !5
  invoke void @_ZN4nodeC2EiPS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %27, i32 noundef %30, ptr noundef %31, ptr noundef %32)
          to label %33 unwind label %34

33:                                               ; preds = %26
  store ptr %27, ptr %5, align 8
  br label %67

34:                                               ; preds = %26
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %10, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 24) #6
  br label %69

38:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = add nsw i32 %39, %40
  %42 = ashr i32 %41, 1
  store i32 %42, ptr %12, align 4, !tbaa !9
  %43 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #5
  %44 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = add nsw i32 %45, 1
  %47 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = invoke noundef ptr @_ZN4node6insertEiii(ptr noundef nonnull align 8 dereferenceable(24) %48, i32 noundef %49, i32 noundef %50, i32 noundef %51)
          to label %53 unwind label %62

53:                                               ; preds = %38
  %54 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = invoke noundef ptr @_ZN4node6insertEiii(ptr noundef nonnull align 8 dereferenceable(24) %55, i32 noundef %56, i32 noundef %57, i32 noundef %58)
          to label %60 unwind label %62

60:                                               ; preds = %53
  invoke void @_ZN4nodeC2EiPS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %43, i32 noundef %46, ptr noundef %52, ptr noundef %59)
          to label %61 unwind label %62

61:                                               ; preds = %60
  store ptr %43, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %67

62:                                               ; preds = %60, %53, %38
  %63 = landingpad { ptr, i32 }
          cleanup
  %64 = extractvalue { ptr, i32 } %63, 0
  store ptr %64, ptr %10, align 8
  %65 = extractvalue { ptr, i32 } %63, 1
  store i32 %65, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %43, i64 noundef 24) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %69

66:                                               ; preds = %17, %4
  store ptr %13, ptr %5, align 8
  br label %67

67:                                               ; preds = %66, %61, %33
  %68 = load ptr, ptr %5, align 8
  ret ptr %68

69:                                               ; preds = %62, %34
  %70 = load ptr, ptr %10, align 8
  %71 = load i32, ptr %11, align 4
  %72 = insertvalue { ptr, i32 } poison, ptr %70, 0
  %73 = insertvalue { ptr, i32 } %72, i32 %71, 1
  resume { ptr, i32 } %73
}

; 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

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 = { 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 #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 = { builtin allocsize(0) }
attributes #6 = { builtin nounwind }
attributes #7 = { 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 0}
!12 = !{!"_ZTS4node", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, 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"

@null = external dso_local local_unnamed_addr global ptr, align 8

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

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN4node6insertEiii(ptr noundef nonnull readonly align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %.not = icmp sle i32 %1, %3
  %5 = icmp slt i32 %3, %2
  %or.cond = and i1 %.not, %5
  br i1 %or.cond, label %6, label %30

6:                                                ; preds = %4
  %7 = add nsw i32 %1, 1
  %8 = icmp eq i32 %7, %2
  br i1 %8, label %9, label %14

9:                                                ; preds = %6
  %10 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  %11 = load i32, ptr %0, align 8, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = load ptr, ptr @null, align 8, !tbaa !11
  tail call void @_ZN4nodeC2EiPS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %10, i32 noundef %12, ptr noundef %13, ptr noundef %13)
  br label %30

14:                                               ; preds = %6
  %15 = add nsw i32 %2, %1
  %16 = ashr i32 %15, 1
  %17 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  %18 = load i32, ptr %0, align 8, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = invoke noundef ptr @_ZN4node6insertEiii(ptr noundef nonnull align 8 dereferenceable(24) %21, i32 noundef %1, i32 noundef %16, i32 noundef %3)
          to label %23 unwind label %28

23:                                               ; preds = %14
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = invoke noundef ptr @_ZN4node6insertEiii(ptr noundef nonnull align 8 dereferenceable(24) %25, i32 noundef %16, i32 noundef %2, i32 noundef %3)
          to label %27 unwind label %28

27:                                               ; preds = %23
  tail call void @_ZN4nodeC2EiPS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %17, i32 noundef %19, ptr noundef nonnull %22, ptr noundef nonnull %26)
  br label %30

28:                                               ; preds = %23, %14
  %29 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %17, i64 noundef 24) #5
  resume { ptr, i32 } %29

30:                                               ; preds = %4, %27, %9
  %.0 = phi ptr [ %10, %9 ], [ %17, %27 ], [ %0, %4 ]
  ret ptr %.0
}

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


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