; LLVM IR from AlgoGenesis/C :: Linked_list/Clone_Linked_List_with _Random_Connections (program)

; 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.ListNode = type { i32, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local ptr @createNode(i32 noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @cloneLinkedListWithRandomPointer(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  br label %109

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %12 = call noalias ptr @malloc(i64 noundef 800) #5
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %22, %11
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 100
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %25

17:                                               ; preds = %13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  store ptr null, ptr %21, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !11

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %30, %25
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %44

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ListNode, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = call ptr @createNode(i32 noundef %33)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ListNode, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %35, i64 %39
  store ptr %34, ptr %40, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ListNode, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  store ptr %43, ptr %6, align 8, !tbaa !5
  br label %27, !llvm.loop !16

44:                                               ; preds = %27
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %45, ptr %6, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %95, %44
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %99

49:                                               ; preds = %46
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ListNode, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %72

54:                                               ; preds = %49
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ListNode, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct.ListNode, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds ptr, ptr %55, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ListNode, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !13
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds ptr, ptr %64, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ListNode, ptr %70, i32 0, i32 1
  store ptr %63, ptr %71, align 8, !tbaa !15
  br label %72

72:                                               ; preds = %54, %49
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ListNode, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !17
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %95

77:                                               ; preds = %72
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ListNode, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = getelementptr inbounds %struct.ListNode, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 8, !tbaa !13
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds ptr, ptr %78, i64 %84
  %86 = load ptr, ptr %85, align 8, !tbaa !5
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ListNode, ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !13
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds ptr, ptr %87, i64 %91
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ListNode, ptr %93, i32 0, i32 2
  store ptr %86, ptr %94, align 8, !tbaa !17
  br label %95

95:                                               ; preds = %77, %72
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.ListNode, ptr %96, i32 0, i32 1
  %98 = load ptr, ptr %97, align 8, !tbaa !15
  store ptr %98, ptr %6, align 8, !tbaa !5
  br label %46, !llvm.loop !18

99:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.ListNode, ptr %101, i32 0, i32 0
  %103 = load i32, ptr %102, align 8, !tbaa !13
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds ptr, ptr %100, i64 %104
  %106 = load ptr, ptr %105, align 8, !tbaa !5
  store ptr %106, ptr %7, align 8, !tbaa !5
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %107) #4
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %108, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %109

109:                                              ; preds = %99, %10
  %110 = load ptr, ptr %2, align 8
  ret ptr %110
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 "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 }
attributes #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"ListNode", !10, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !12}
!17 = !{!14, !6, i64 16}
!18 = distinct !{!18, !12}


; 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: nounwind uwtable
declare dso_local ptr @createNode(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @cloneLinkedListWithRandomPointer(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %41, label %.preheader37.preheader

.preheader37.preheader:                           ; preds = %1
  %calloc = tail call dereferenceable_or_null(800) ptr @calloc(i64 1, i64 800)
  br label %.preheader37

.preheader37:                                     ; preds = %.preheader37.preheader, %.preheader37
  %.02839 = phi ptr [ %8, %.preheader37 ], [ %0, %.preheader37.preheader ]
  %2 = load i32, ptr %.02839, align 8, !tbaa !5
  %3 = tail call ptr @createNode(i32 noundef %2)
  %4 = load i32, ptr %.02839, align 8, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds ptr, ptr %calloc, i64 %5
  store ptr %3, ptr %6, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %.02839, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %.not33 = icmp eq ptr %8, null
  br i1 %.not33, label %.preheader, label %.preheader37, !llvm.loop !13

.preheader:                                       ; preds = %.preheader37, %34
  %.140 = phi ptr [ %35, %34 ], [ %0, %.preheader37 ]
  %9 = getelementptr inbounds i8, ptr %.140, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %.not35 = icmp eq ptr %10, null
  br i1 %.not35, label %21, label %11

11:                                               ; preds = %.preheader
  %12 = load i32, ptr %10, align 8, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds ptr, ptr %calloc, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %.140, align 8, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds ptr, ptr %calloc, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr %15, ptr %20, align 8, !tbaa !12
  br label %21

21:                                               ; preds = %11, %.preheader
  %22 = getelementptr inbounds i8, ptr %.140, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %.not36 = icmp eq ptr %23, null
  br i1 %.not36, label %34, label %24

24:                                               ; preds = %21
  %25 = load i32, ptr %23, align 8, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %calloc, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load i32, ptr %.140, align 8, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %calloc, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store ptr %28, ptr %33, align 8, !tbaa !15
  br label %34

34:                                               ; preds = %24, %21
  %35 = load ptr, ptr %9, align 8, !tbaa !12
  %.not34 = icmp eq ptr %35, null
  br i1 %.not34, label %36, label %.preheader, !llvm.loop !16

36:                                               ; preds = %34
  %37 = load i32, ptr %0, align 8, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %calloc, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  tail call void @free(ptr noundef %calloc) #3
  br label %41

41:                                               ; preds = %1, %36
  %.0 = phi ptr [ %40, %36 ], [ null, %1 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass