; LLVM IR from PetarV-/Algorithms :: Data Structures (XOR Linked List)

; 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.XORLinkedList = type { ptr, ptr }
%struct.XORNode = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @addAfter(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XORLinkedList, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %31

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %18 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XORNode, ptr %20, i32 0, i32 0
  store i32 %19, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XORNode, ptr %22, i32 0, i32 1
  store ptr null, ptr %23, align 8, !tbaa !15
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XORLinkedList, ptr %25, i32 0, i32 0
  store ptr %24, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XORLinkedList, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %103

31:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XORLinkedList, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  store ptr %34, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XORLinkedList, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.XORNode, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  store ptr %39, ptr %11, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %44, %31
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = icmp ne ptr %41, %42
  br i1 %43, label %44, label %55

44:                                               ; preds = %40
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %45, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %46, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = ptrtoint ptr %47 to i64
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XORNode, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = ptrtoint ptr %51 to i64
  %53 = xor i64 %48, %52
  %54 = inttoptr i64 %53 to ptr
  store ptr %54, ptr %11, align 8, !tbaa !5
  br label %40, !llvm.loop !17

55:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %56 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %56, ptr %12, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.XORNode, ptr %58, i32 0, i32 0
  store i32 %57, ptr %59, align 8, !tbaa !13
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = ptrtoint ptr %60 to i64
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = ptrtoint ptr %62 to i64
  %64 = xor i64 %61, %63
  %65 = inttoptr i64 %64 to ptr
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.XORNode, ptr %66, i32 0, i32 1
  store ptr %65, ptr %67, align 8, !tbaa !15
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.XORNode, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = ptrtoint ptr %70 to i64
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = ptrtoint ptr %72 to i64
  %74 = xor i64 %71, %73
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = ptrtoint ptr %75 to i64
  %77 = xor i64 %74, %76
  %78 = inttoptr i64 %77 to ptr
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.XORNode, ptr %79, i32 0, i32 1
  store ptr %78, ptr %80, align 8, !tbaa !15
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %97

83:                                               ; preds = %55
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.XORNode, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !15
  %87 = ptrtoint ptr %86 to i64
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = ptrtoint ptr %88 to i64
  %90 = xor i64 %87, %89
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = ptrtoint ptr %91 to i64
  %93 = xor i64 %90, %92
  %94 = inttoptr i64 %93 to ptr
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.XORNode, ptr %95, i32 0, i32 1
  store ptr %94, ptr %96, align 8, !tbaa !15
  br label %101

97:                                               ; preds = %55
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.XORLinkedList, ptr %99, i32 0, i32 1
  store ptr %98, ptr %100, align 8, !tbaa !16
  br label %101

101:                                              ; preds = %97, %83
  %102 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %102, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %103

103:                                              ; preds = %101, %17
  %104 = load ptr, ptr %4, align 8
  ret ptr %104
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind 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 = { nounwind }
attributes #4 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"XORLinkedList", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"XORNode", !10, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!12, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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: nofree nounwind uwtable
define dso_local noundef ptr @addAfter(ptr nocapture noundef %0, ptr noundef readnone %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %10

6:                                                ; preds = %3
  %7 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  store i32 %2, ptr %7, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr null, ptr %8, align 8, !tbaa !13
  store ptr %7, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %7, ptr %9, align 8, !tbaa !14
  br label %41

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %4, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not38 = icmp eq ptr %4, %1
  br i1 %.not38, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.03440 = phi ptr [ %18, %.lr.ph ], [ %12, %10 ]
  %.03539 = phi ptr [ %.03440, %.lr.ph ], [ %4, %10 ]
  %13 = ptrtoint ptr %.03539 to i64
  %14 = getelementptr inbounds i8, ptr %.03440, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = ptrtoint ptr %15 to i64
  %17 = xor i64 %16, %13
  %18 = inttoptr i64 %17 to ptr
  %.not = icmp eq ptr %.03440, %1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %10
  %.035.lcssa = phi ptr [ %4, %10 ], [ %.03440, %.lr.ph ]
  %.034.lcssa = phi ptr [ %12, %10 ], [ %18, %.lr.ph ]
  %19 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  store i32 %2, ptr %19, align 8, !tbaa !10
  %20 = ptrtoint ptr %.035.lcssa to i64
  %21 = ptrtoint ptr %.034.lcssa to i64
  %22 = xor i64 %21, %20
  %23 = inttoptr i64 %22 to ptr
  %24 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr %23, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %.035.lcssa, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = ptrtoint ptr %26 to i64
  %28 = ptrtoint ptr %19 to i64
  %29 = xor i64 %21, %27
  %30 = xor i64 %29, %28
  %31 = inttoptr i64 %30 to ptr
  store ptr %31, ptr %25, align 8, !tbaa !13
  %.not37 = icmp eq ptr %.034.lcssa, null
  br i1 %.not37, label %39, label %32

32:                                               ; preds = %._crit_edge
  %33 = getelementptr inbounds i8, ptr %.034.lcssa, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = ptrtoint ptr %34 to i64
  %36 = xor i64 %20, %35
  %37 = xor i64 %36, %28
  %38 = inttoptr i64 %37 to ptr
  store ptr %38, ptr %33, align 8, !tbaa !13
  br label %41

39:                                               ; preds = %._crit_edge
  %40 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %19, ptr %40, align 8, !tbaa !14
  br label %41

41:                                               ; preds = %32, %39, %6
  %.0 = phi ptr [ %7, %6 ], [ %19, %39 ], [ %19, %32 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind 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 0}
!6 = !{!"XORLinkedList", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"XORNode", !12, i64 0, !7, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !7, i64 8}
!14 = !{!6, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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