; LLVM IR from AlgoGenesis/C :: Linked_list/Circular_Linked_list/deletion/at_a_specific_position (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.Node = type { i32, ptr }

@.str = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [53 x i8], align 1

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

13:                                               ; preds = %2
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %94

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %56

20:                                               ; preds = %15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Node, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = icmp eq ptr %23, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %20
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %28) #4
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %29, align 8, !tbaa !5
  br label %55

30:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %6, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %40, %30
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp ne ptr %36, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %33
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  store ptr %43, ptr %6, align 8, !tbaa !5
  br label %33, !llvm.loop !13

44:                                               ; preds = %33
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Node, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 1
  store ptr %47, ptr %49, align 8, !tbaa !11
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %52, ptr %53, align 8, !tbaa !5
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %54) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %55

55:                                               ; preds = %44, %27
  store i32 1, ptr %7, align 4
  br label %92

56:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %70, %56
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %61, label %68

61:                                               ; preds = %57
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Node, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = icmp ne ptr %64, %66
  br label %68

68:                                               ; preds = %61, %57
  %69 = phi i1 [ false, %57 ], [ %67, %61 ]
  br i1 %69, label %70, label %77

70:                                               ; preds = %68
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %71, ptr %8, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Node, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  store ptr %74, ptr %5, align 8, !tbaa !5
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %9, align 4, !tbaa !9
  br label %57, !llvm.loop !15

77:                                               ; preds = %68
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = icmp ne i32 %78, %79
  br i1 %80, label %81, label %84

81:                                               ; preds = %77
  %82 = load i32, ptr %4, align 4, !tbaa !9
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %82)
  store i32 1, ptr %7, align 4
  br label %91

84:                                               ; preds = %77
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.Node, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !11
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 1
  store ptr %87, ptr %89, align 8, !tbaa !11
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %90) #4
  store i32 0, ptr %7, align 4
  br label %91

91:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %92

92:                                               ; preds = %91, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %93 = load i32, ptr %7, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92, %13
  ret void

95:                                               ; preds = %92
  unreachable
}

declare i32 @printf(ptr noundef, ...) #1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

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


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

@.str = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @deleteAtPosition(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %30

7:                                                ; preds = %2
  %8 = icmp eq i32 %1, 1
  br i1 %8, label %12, label %.preheader37

.preheader37:                                     ; preds = %7
  %9 = icmp sgt i32 %1, 1
  br i1 %9, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.preheader37
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %.not62 = icmp eq ptr %11, %3
  br i1 %.not62, label %.critedge, label %.lr.ph65

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = icmp eq ptr %14, %3
  br i1 %15, label %16, label %.preheader

16:                                               ; preds = %12
  tail call void @free(ptr noundef nonnull %3) #3
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %30

.preheader:                                       ; preds = %12, %.preheader
  %.029 = phi ptr [ %18, %.preheader ], [ %3, %12 ]
  %17 = getelementptr inbounds i8, ptr %.029, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %.not36 = icmp eq ptr %18, %3
  br i1 %.not36, label %19, label %.preheader, !llvm.loop !12

19:                                               ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %.029, i64 8
  store ptr %14, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %21, ptr %0, align 8, !tbaa !5
  tail call void @free(ptr noundef %3) #3
  br label %30

.lr.ph:                                           ; preds = %.lr.ph65
  %22 = getelementptr inbounds i8, ptr %24, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %.not = icmp eq ptr %23, %3
  br i1 %.not, label %.critedge, label %.lr.ph65, !llvm.loop !14

.lr.ph65:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %24 = phi ptr [ %23, %.lr.ph ], [ %11, %.lr.ph.preheader ]
  %.0303864 = phi ptr [ %24, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.04063 = phi i32 [ %25, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %25 = add nuw nsw i32 %.04063, 1
  %exitcond.not = icmp eq i32 %25, %1
  br i1 %exitcond.not, label %.critedge.thread, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.preheader37, %.lr.ph.preheader, %.lr.ph
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %1)
  br label %30

.critedge.thread:                                 ; preds = %.lr.ph65
  %27 = getelementptr inbounds i8, ptr %24, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %.0303864, i64 8
  store ptr %28, ptr %29, align 8, !tbaa !9
  tail call void @free(ptr noundef %24) #3
  br label %30

30:                                               ; preds = %19, %16, %.critedge.thread, %.critedge, %5
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture 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 = { nofree 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 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"Node", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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