; LLVM IR from LeoVen/C-Macro-Collections :: tests (types)

; 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.linkedlist1 = type { ptr, ptr, i64, i32, ptr, ptr }
%struct.linkedlist1_node = type { %struct.struct_s, ptr, ptr }
%struct.struct_s = type { i32, i32, ptr, ptr, [10 x double] }
%struct.linkedlist1_fval = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.cmc_alloc_node = type { ptr, 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
define dso_local void @ll1_clear(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.linkedlist1, ptr %4, i32 0, i32 0
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %6, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %34, %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.linkedlist1, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %44

12:                                               ; preds = %7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.linkedlist1, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.linkedlist1_node, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.linkedlist1, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !9
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.linkedlist1, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds %struct.linkedlist1_fval, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %34

26:                                               ; preds = %12
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.linkedlist1, ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = getelementptr inbounds %struct.linkedlist1_fval, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.linkedlist1_node, ptr %32, i32 0, i32 0
  call void %31(ptr noundef byval(%struct.struct_s) align 8 %33)
  br label %34

34:                                               ; preds = %26, %12
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.linkedlist1, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = getelementptr inbounds %struct.cmc_alloc_node, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  call void %39(ptr noundef %40)
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.linkedlist1, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  store ptr %43, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !22

44:                                               ; preds = %7
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.linkedlist1, ptr %45, i32 0, i32 2
  store i64 0, ptr %46, align 8, !tbaa !24
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.linkedlist1, ptr %47, i32 0, i32 0
  store ptr null, ptr %48, align 8, !tbaa !9
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.linkedlist1, ptr %49, i32 0, i32 1
  store ptr null, ptr %50, align 8, !tbaa !25
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.linkedlist1, ptr %51, i32 0, i32 3
  store i32 0, ptr %52, align 8, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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, !6, i64 0}
!10 = !{!"linkedlist1", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 104}
!14 = !{!"linkedlist1_node", !15, i64 0, !6, i64 104, !6, i64 112}
!15 = !{!"struct_s", !12, i64 0, !12, i64 4, !6, i64 8, !6, i64 16, !7, i64 24}
!16 = !{!10, !6, i64 32}
!17 = !{!18, !6, i64 24}
!18 = !{!"linkedlist1_fval", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!19 = !{!10, !6, i64 40}
!20 = !{!21, !6, i64 24}
!21 = !{!"cmc_alloc_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!10, !11, i64 16}
!25 = !{!10, !6, i64 8}
!26 = !{!10, !12, i64 24}


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

%struct.struct_s = type { i32, i32, ptr, ptr, [10 x double] }

; Function Attrs: nounwind uwtable
define dso_local void @ll1_clear(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %.017 = load ptr, ptr %0, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.017, null
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  br label %4

4:                                                ; preds = %.lr.ph, %11
  %.019 = phi ptr [ %.017, %.lr.ph ], [ %.0, %11 ]
  %5 = getelementptr inbounds i8, ptr %.019, i64 104
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  store ptr %6, ptr %0, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %.not16 = icmp eq ptr %9, null
  br i1 %.not16, label %11, label %10

10:                                               ; preds = %4
  tail call void %9(ptr noundef nonnull byval(%struct.struct_s) align 8 %.019) #2
  br label %11

11:                                               ; preds = %10, %4
  %12 = load ptr, ptr %3, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  tail call void %14(ptr noundef nonnull %.019) #2
  %.0 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %4, !llvm.loop !21

._crit_edge:                                      ; preds = %11, %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %0, i8 0, i64 28, i1 false)
  ret void
}

; 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) }
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, !7, i64 0}
!6 = !{!"linkedlist1", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 104}
!13 = !{!"linkedlist1_node", !14, i64 0, !7, i64 104, !7, i64 112}
!14 = !{!"struct_s", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 16, !8, i64 24}
!15 = !{!6, !7, i64 32}
!16 = !{!17, !7, i64 24}
!17 = !{!"linkedlist1_fval", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!18 = !{!6, !7, i64 40}
!19 = !{!20, !7, i64 24}
!20 = !{!"cmc_alloc_node", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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