; LLVM IR from NOAA-PMEL/Ferret :: fer/ccr (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.list_t = type { i32, ptr, ptr, ptr }
%struct.list_element_t = type { ptr, ptr, ptr }

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @list_create_element(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @list_insert_after(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = call ptr @list_create_element(ptr noundef %14, i32 noundef %15, ptr noundef %16, i32 noundef %17)
  store ptr %18, ptr %12, align 8, !tbaa !5
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %97

22:                                               ; preds = %5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.list_t, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %39

27:                                               ; preds = %22
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.list_element_t, ptr %28, i32 0, i32 1
  store ptr null, ptr %29, align 8, !tbaa !13
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.list_element_t, ptr %30, i32 0, i32 0
  store ptr null, ptr %31, align 8, !tbaa !15
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.list_t, ptr %33, i32 0, i32 3
  store ptr %32, ptr %34, align 8, !tbaa !16
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.list_t, ptr %35, i32 0, i32 2
  store ptr %32, ptr %36, align 8, !tbaa !17
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.list_t, ptr %37, i32 0, i32 1
  store ptr %32, ptr %38, align 8, !tbaa !11
  br label %86

39:                                               ; preds = %22
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.list_t, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds %struct.list_element_t, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %62

46:                                               ; preds = %39
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.list_element_t, ptr %47, i32 0, i32 1
  store ptr null, ptr %48, align 8, !tbaa !13
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.list_t, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.list_element_t, ptr %52, i32 0, i32 0
  store ptr %51, ptr %53, align 8, !tbaa !15
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.list_t, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds %struct.list_element_t, ptr %57, i32 0, i32 1
  store ptr %54, ptr %58, align 8, !tbaa !13
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.list_t, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !17
  br label %85

62:                                               ; preds = %39
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.list_t, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !16
  %66 = getelementptr inbounds %struct.list_element_t, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.list_element_t, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !13
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.list_element_t, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  %74 = getelementptr inbounds %struct.list_element_t, ptr %73, i32 0, i32 0
  store ptr %70, ptr %74, align 8, !tbaa !15
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.list_t, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !16
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.list_element_t, ptr %78, i32 0, i32 0
  store ptr %77, ptr %79, align 8, !tbaa !15
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.list_t, ptr %81, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !16
  %84 = getelementptr inbounds %struct.list_element_t, ptr %83, i32 0, i32 1
  store ptr %80, ptr %84, align 8, !tbaa !13
  br label %85

85:                                               ; preds = %62, %46
  br label %86

86:                                               ; preds = %85, %27
  %87 = load ptr, ptr %12, align 8, !tbaa !5
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.list_t, ptr %88, i32 0, i32 3
  store ptr %87, ptr %89, align 8, !tbaa !16
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.list_t, ptr %90, i32 0, i32 0
  %92 = load i32, ptr %91, align 8, !tbaa !18
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %91, align 8, !tbaa !18
  %94 = load ptr, ptr %12, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.list_element_t, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !19
  store ptr %96, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %97

97:                                               ; preds = %86, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %98 = load ptr, ptr %6, align 8
  ret ptr %98
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"list_t", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!14, !6, i64 8}
!14 = !{!"list_element_t", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 0}
!16 = !{!12, !6, i64 24}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !10, i64 0}
!19 = !{!14, !6, i64 16}


; 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 hidden ptr @list_create_element(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @list_insert_after(ptr nocapture noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call ptr @list_create_element(ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %30, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %6, ptr %13, align 8, !tbaa !11
  br label %24

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = icmp eq ptr %18, null
  %20 = getelementptr inbounds i8, ptr %6, i64 8
  br i1 %19, label %21, label %23

21:                                               ; preds = %14
  store ptr null, ptr %20, align 8, !tbaa !13
  store ptr %16, ptr %6, align 8, !tbaa !15
  store ptr %6, ptr %17, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  br label %24

23:                                               ; preds = %14
  store ptr %18, ptr %20, align 8, !tbaa !13
  store ptr %6, ptr %18, align 8, !tbaa !15
  store ptr %16, ptr %6, align 8, !tbaa !15
  br label %24

24:                                               ; preds = %21, %23, %12
  %.sink = phi ptr [ %22, %21 ], [ %17, %23 ], [ %9, %12 ]
  store ptr %6, ptr %.sink, align 8, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %6, ptr %25, align 8, !tbaa !12
  %26 = load i32, ptr %0, align 8, !tbaa !17
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %0, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %6, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  br label %30

30:                                               ; preds = %5, %24
  %.0 = phi ptr [ %29, %24 ], [ null, %5 ]
  ret ptr %.0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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, !10, i64 8}
!6 = !{!"list_t", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 24}
!13 = !{!14, !10, i64 8}
!14 = !{!"list_element_t", !10, i64 0, !10, i64 8, !10, i64 16}
!15 = !{!14, !10, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!6, !7, i64 0}
!18 = !{!14, !10, i64 16}


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