; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_018)

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

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @homework_018_141() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = call noalias ptr @malloc(i64 noundef 16) #5
  store ptr %4, ptr %1, align 8, !tbaa !5
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.ListNode, ptr %5, i32 0, i32 0
  store i32 3, ptr %6, align 8, !tbaa !9
  %7 = call noalias ptr @malloc(i64 noundef 16) #5
  store ptr %7, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ListNode, ptr %8, i32 0, i32 0
  store i32 2, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ListNode, ptr %11, i32 0, i32 1
  store ptr %10, ptr %12, align 8, !tbaa !12
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %13, ptr %3, align 8, !tbaa !5
  %14 = call noalias ptr @malloc(i64 noundef 16) #5
  store ptr %14, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ListNode, ptr %15, i32 0, i32 0
  store i32 0, ptr %16, align 8, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ListNode, ptr %18, i32 0, i32 1
  store ptr %17, ptr %19, align 8, !tbaa !12
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = call noalias ptr @malloc(i64 noundef 16) #5
  store ptr %21, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ListNode, ptr %22, i32 0, i32 0
  store i32 -4, ptr %23, align 8, !tbaa !9
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ListNode, ptr %25, i32 0, i32 1
  store ptr %24, ptr %26, align 8, !tbaa !12
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ListNode, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  store ptr %29, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ListNode, ptr %31, i32 0, i32 1
  store ptr %30, ptr %32, align 8, !tbaa !12
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = call zeroext i1 @hasCycle(ptr noundef %33)
  br i1 %34, label %35, label %37

35:                                               ; preds = %0
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %39

37:                                               ; preds = %0
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %39

39:                                               ; preds = %37, %35
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ListNode, ptr %40, i32 0, i32 1
  store ptr null, ptr %41, align 8, !tbaa !12
  call void @destroyList(ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; 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: nounwind uwtable
declare dso_local zeroext i1 @hasCycle(ptr noundef) #0

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

declare void @destroyList(ptr noundef) #3

; 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 = { "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, !11, i64 0}
!10 = !{!"ListNode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}


; 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 [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @homework_018_141() local_unnamed_addr #0 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %2 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  store ptr %2, ptr %1, align 8, !tbaa !5
  store i32 3, ptr %2, align 8, !tbaa !9
  %3 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  store i32 2, ptr %3, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %3, ptr %4, align 8, !tbaa !12
  %5 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  store i32 0, ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %5, ptr %6, align 8, !tbaa !12
  %7 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  store i32 -4, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr %3, ptr %9, align 8, !tbaa !12
  %10 = tail call zeroext i1 @hasCycle(ptr noundef nonnull %2)
  %.str..str.1 = select i1 %10, ptr @.str, ptr @.str.1
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str..str.1)
  store ptr null, ptr %9, align 8, !tbaa !12
  call void @destroyList(ptr noundef nonnull %1) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @hasCycle(ptr noundef) local_unnamed_addr #0

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

declare void @destroyList(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 = { 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, !11, i64 0}
!10 = !{!"ListNode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass