; LLVM IR from BurntSushi/clibs :: libds (linkedlist)

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

@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.ds_list_copy = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ds_list_create() #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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; 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 @ds_list_copy(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = call ptr @ds_list_create()
  store ptr %7, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.DSLinkedList, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %53, %1
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %57

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  br label %20

19:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 143, ptr noundef @__PRETTY_FUNCTION__.ds_list_copy) #6
  unreachable

20:                                               ; preds = %18
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.DSListNode, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DSListNode, ptr %24, i32 0, i32 0
  store ptr %23, ptr %25, align 8, !tbaa !12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.DSListNode, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !14
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.DSListNode, ptr %29, i32 0, i32 1
  store ptr null, ptr %30, align 8, !tbaa !15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.DSLinkedList, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = icmp eq ptr %31, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %20
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.DSLinkedList, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !16
  br label %51

40:                                               ; preds = %20
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.DSLinkedList, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = icmp eq ptr %41, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %40
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DSLinkedList, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %46, %40
  br label %51

51:                                               ; preds = %50, %36
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %52, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %53

53:                                               ; preds = %51
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.DSListNode, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  store ptr %56, ptr %4, align 8, !tbaa !5
  br label %11, !llvm.loop !17

57:                                               ; preds = %11
  store ptr null, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DSLinkedList, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  store ptr %60, ptr %4, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %69, %57
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %73

64:                                               ; preds = %61
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.DSListNode, ptr %66, i32 0, i32 1
  store ptr %65, ptr %67, align 8, !tbaa !15
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %68, ptr %5, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %64
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.DSListNode, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  store ptr %72, ptr %4, align 8, !tbaa !5
  br label %61, !llvm.loop !19

73:                                               ; preds = %61
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.DSLinkedList, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !20
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.DSLinkedList, ptr %77, i32 0, i32 0
  store i32 %76, ptr %78, align 8, !tbaa !20
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %79
}

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 = { noreturn 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) }
attributes #6 = { noreturn 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 16}
!10 = !{!"DSLinkedList", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"DSListNode", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!13, !6, i64 16}
!15 = !{!13, !6, i64 8}
!16 = !{!10, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!10, !11, i64 0}


; 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.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.ds_list_copy = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ds_list_create() local_unnamed_addr #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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ds_list_copy(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call ptr @ds_list_create()
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %.032 = load ptr, ptr %3, align 8, !tbaa !5
  %.not33 = icmp eq ptr %.032, null
  br i1 %.not33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %2, i64 16
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  br label %7

7:                                                ; preds = %.lr.ph, %19
  %.035 = phi ptr [ %.032, %.lr.ph ], [ %.0, %19 ]
  %.02734 = phi ptr [ null, %.lr.ph ], [ %8, %19 ]
  %8 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  %.not31 = icmp eq ptr %8, null
  br i1 %.not31, label %9, label %10

9:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 143, ptr noundef nonnull @__PRETTY_FUNCTION__.ds_list_copy) #4
  unreachable

10:                                               ; preds = %7
  %11 = load ptr, ptr %.035, align 8, !tbaa !9
  store ptr %11, ptr %8, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %.02734, ptr %12, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr null, ptr %13, align 8, !tbaa !12
  %14 = load ptr, ptr %4, align 8, !tbaa !13
  %15 = icmp eq ptr %.035, %14
  br i1 %15, label %.sink.split, label %16

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !16
  %18 = icmp eq ptr %.035, %17
  br i1 %18, label %.sink.split, label %19

.sink.split:                                      ; preds = %16, %10
  %.sink = phi ptr [ %6, %10 ], [ %5, %16 ]
  store ptr %8, ptr %.sink, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %.sink.split, %16
  %20 = getelementptr inbounds i8, ptr %.035, i64 8
  %.0 = load ptr, ptr %20, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !17

._crit_edge:                                      ; preds = %19, %1
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  %.136 = load ptr, ptr %21, align 8, !tbaa !5
  %.not3037 = icmp eq ptr %.136, null
  br i1 %.not3037, label %._crit_edge42, label %.lr.ph41

.lr.ph41:                                         ; preds = %._crit_edge, %.lr.ph41
  %.139 = phi ptr [ %.1, %.lr.ph41 ], [ %.136, %._crit_edge ]
  %.12838 = phi ptr [ %.139, %.lr.ph41 ], [ null, %._crit_edge ]
  %22 = getelementptr inbounds i8, ptr %.139, i64 8
  store ptr %.12838, ptr %22, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %.139, i64 16
  %.1 = load ptr, ptr %23, align 8, !tbaa !5
  %.not30 = icmp eq ptr %.1, null
  br i1 %.not30, label %._crit_edge42, label %.lr.ph41, !llvm.loop !19

._crit_edge42:                                    ; preds = %.lr.ph41, %._crit_edge
  %24 = load i32, ptr %0, align 8, !tbaa !20
  store i32 %24, ptr %2, align 8, !tbaa !20
  ret ptr %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 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 = { noreturn 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 #3 = { nounwind allocsize(0) }
attributes #4 = { noreturn 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 0}
!10 = !{!"DSListNode", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 16}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !6, i64 8}
!14 = !{!"DSLinkedList", !15, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!14, !15, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass