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

; 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"

%class.Node = type { i32, i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6addBitP4Nodei(ptr noundef %0, i32 noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 20, ptr %5, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %65, %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %69

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = ashr i32 %14, %15
  %17 = and i32 %16, 1
  store i32 %17, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %42

20:                                               ; preds = %13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.Node, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !11
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.Node, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %38

29:                                               ; preds = %20
  %30 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %30)
          to label %31 unwind label %34

31:                                               ; preds = %29
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.Node, ptr %32, i32 0, i32 3
  store ptr %30, ptr %33, align 8, !tbaa !13
  br label %38

34:                                               ; preds = %29
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %7, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %30, i64 noundef 24) #7
  br label %68

38:                                               ; preds = %31, %20
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %class.Node, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  store ptr %41, ptr %3, align 8, !tbaa !5
  br label %64

42:                                               ; preds = %13
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %class.Node, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !14
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %44, align 8, !tbaa !14
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.Node, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %60

51:                                               ; preds = %42
  %52 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %52)
          to label %53 unwind label %56

53:                                               ; preds = %51
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.Node, ptr %54, i32 0, i32 2
  store ptr %52, ptr %55, align 8, !tbaa !15
  br label %60

56:                                               ; preds = %51
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %7, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %52, i64 noundef 24) #7
  br label %68

60:                                               ; preds = %53, %42
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.Node, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  store ptr %63, ptr %3, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %60, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !16

68:                                               ; preds = %56, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %70

69:                                               ; preds = %12
  ret void

70:                                               ; preds = %68
  %71 = load ptr, ptr %7, align 8
  %72 = load i32, ptr %8, align 4
  %73 = insertvalue { ptr, i32 } poison, ptr %71, 0
  %74 = insertvalue { ptr, i32 } %73, i32 %72, 1
  resume { ptr, i32 } %74
}

; 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(24)) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

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

; 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 4}
!12 = !{!"_ZTS4Node", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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 @_Z6addBitP4Nodei(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  br label %4

3:                                                ; preds = %21
  ret void

4:                                                ; preds = %2, %21
  %.014 = phi ptr [ %0, %2 ], [ %.1, %21 ]
  %.01213 = phi i32 [ 20, %2 ], [ %22, %21 ]
  %5 = shl nuw i32 1, %.01213
  %6 = and i32 %5, %1
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %14, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %.014, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.014, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = icmp eq ptr %12, null
  br i1 %13, label %.sink.split, label %21

14:                                               ; preds = %4
  %15 = load i32, ptr %.014, align 8, !tbaa !12
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %.014, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %.014, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp eq ptr %18, null
  br i1 %19, label %.sink.split, label %21

.sink.split:                                      ; preds = %14, %7
  %.sink17 = phi ptr [ %11, %7 ], [ %17, %14 ]
  %20 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  tail call void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %20)
  store ptr %20, ptr %.sink17, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %.sink.split, %14, %7
  %.1 = phi ptr [ %12, %7 ], [ %18, %14 ], [ %20, %.sink.split ]
  %22 = add nsw i32 %.01213, -1
  %.not16 = icmp eq i32 %.01213, 0
  br i1 %.not16, label %3, label %4, !llvm.loop !13
}

; 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(24)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

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, !7, i64 4}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !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, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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