; LLVM IR from introlab/odas :: src/amessage (amsg_categories)

; 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.amsg_categories_obj = type { i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @amsg_categories_destroy(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %9, %1
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.amsg_categories_obj, ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = call i32 @fifo_nElements(ptr noundef %6)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %14

9:                                                ; preds = %3
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.amsg_categories_obj, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call ptr @fifo_pop(ptr noundef %12)
  call void @msg_categories_destroy(ptr noundef %13)
  br label %3, !llvm.loop !12

14:                                               ; preds = %3
  br label %15

15:                                               ; preds = %21, %14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.amsg_categories_obj, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = call i32 @fifo_nElements(ptr noundef %18)
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %15
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.amsg_categories_obj, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = call ptr @fifo_pop(ptr noundef %24)
  call void @msg_categories_destroy(ptr noundef %25)
  br label %15, !llvm.loop !15

26:                                               ; preds = %15
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.amsg_categories_obj, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  call void @fifo_destroy(ptr noundef %29)
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.amsg_categories_obj, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  call void @fifo_destroy(ptr noundef %32)
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %33) #3
  ret void
}

declare i32 @fifo_nElements(ptr noundef) #1

declare void @msg_categories_destroy(ptr noundef) #1

declare ptr @fifo_pop(ptr noundef) #1

declare void @fifo_destroy(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #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 = { 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 }

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


; 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
define dso_local void @amsg_categories_destroy(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 @fifo_nElements(ptr noundef %3) #3
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = tail call i32 @fifo_nElements(ptr noundef %7) #3
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph8, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = tail call ptr @fifo_pop(ptr noundef %10) #3
  tail call void @msg_categories_destroy(ptr noundef %11) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = tail call i32 @fifo_nElements(ptr noundef %12) #3
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %.preheader, !llvm.loop !12

.lr.ph8:                                          ; preds = %.preheader, %.lr.ph8
  %15 = load ptr, ptr %6, align 8, !tbaa !11
  %16 = tail call ptr @fifo_pop(ptr noundef %15) #3
  tail call void @msg_categories_destroy(ptr noundef %16) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !11
  %18 = tail call i32 @fifo_nElements(ptr noundef %17) #3
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph8, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph8, %.preheader
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @fifo_destroy(ptr noundef %20) #3
  %21 = load ptr, ptr %6, align 8, !tbaa !11
  tail call void @fifo_destroy(ptr noundef %21) #3
  tail call void @free(ptr noundef nonnull %0) #3
  ret void
}

declare i32 @fifo_nElements(ptr noundef) local_unnamed_addr #1

declare void @msg_categories_destroy(ptr noundef) local_unnamed_addr #1

declare ptr @fifo_pop(ptr noundef) local_unnamed_addr #1

declare void @fifo_destroy(ptr noundef) 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 = { "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, !10, i64 8}
!6 = !{!"amsg_categories_obj", !7, i64 0, !10, i64 8, !10, i64 16}
!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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