; LLVM IR from ohler55/agoo :: ext/agoo (upgraded)

; 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._agooUpgraded = type { ptr, ptr, ptr, %struct._agooAtom, %struct._agooAtom, ptr, ptr, ptr, ptr, i8, i8, i8, i8, i8, ptr }
%struct._agooAtom = type { ptr, %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct._agooSubject = type { ptr, [8 x i8] }

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

declare void @agoo_subject_destroy(ptr noundef) #2

; 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 @agoo_upgraded_del_subject(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr null, %7
  br i1 %8, label %9, label %25

9:                                                ; preds = %2
  br label %10

10:                                               ; preds = %15, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._agooUpgraded, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr null, %13
  br i1 %14, label %15, label %24

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._agooUpgraded, ptr %16, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct._agooSubject, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._agooUpgraded, ptr %21, i32 0, i32 5
  store ptr %20, ptr %22, align 8, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  call void @agoo_subject_destroy(ptr noundef %23)
  br label %10, !llvm.loop !15

24:                                               ; preds = %10
  br label %65

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._agooUpgraded, ptr %26, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  store ptr %28, ptr %5, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %60, %25
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = icmp ne ptr null, %30
  br i1 %31, label %32, label %64

32:                                               ; preds = %29
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._agooSubject, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds [8 x i8], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._agooSubject, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds [8 x i8], ptr %37, i64 0, i64 0
  %39 = call i32 @strcmp(ptr noundef %35, ptr noundef %38) #5
  %40 = icmp eq i32 0, %39
  br i1 %40, label %41, label %58

41:                                               ; preds = %32
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = icmp eq ptr null, %42
  br i1 %43, label %44, label %50

44:                                               ; preds = %41
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._agooSubject, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._agooUpgraded, ptr %48, i32 0, i32 5
  store ptr %47, ptr %49, align 8, !tbaa !9
  br label %56

50:                                               ; preds = %41
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._agooSubject, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._agooSubject, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !13
  br label %56

56:                                               ; preds = %50, %44
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  call void @agoo_subject_destroy(ptr noundef %57)
  br label %64

58:                                               ; preds = %32
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %59, ptr %6, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %58
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._agooSubject, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  store ptr %63, ptr %5, align 8, !tbaa !5
  br label %29, !llvm.loop !17

64:                                               ; preds = %56, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %65

65:                                               ; preds = %64, %24
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 = { "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 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 120}
!10 = !{!"_agooUpgraded", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 72, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 153, !12, i64 154, !12, i64 155, !12, i64 156, !6, i64 160}
!11 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_agooSubject", !6, i64 0, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

declare void @agoo_subject_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @agoo_upgraded_del_subject(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %3 = icmp eq ptr %1, null
  %4 = getelementptr inbounds i8, ptr %0, i64 120
  br i1 %3, label %.preheader, label %9

.preheader:                                       ; preds = %2
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not2024 = icmp eq ptr %5, null
  br i1 %.not2024, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %6 = phi ptr [ %8, %.lr.ph ], [ %5, %.preheader ]
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  store ptr %7, ptr %4, align 8, !tbaa !5
  tail call void @agoo_subject_destroy(ptr noundef nonnull %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %.not20 = icmp eq ptr %8, null
  br i1 %.not20, label %.loopexit, label %.lr.ph, !llvm.loop !14

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  br label %11

11:                                               ; preds = %12, %9
  %.017.in = phi ptr [ %4, %9 ], [ %.017, %12 ]
  %.0 = phi ptr [ null, %9 ], [ %.017, %12 ]
  %.017 = load ptr, ptr %.017.in, align 8, !tbaa !16
  %.not = icmp eq ptr %.017, null
  br i1 %.not, label %.loopexit, label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds i8, ptr %.017, i64 8
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %10, ptr noundef nonnull dereferenceable(1) %13) #4
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %11, !llvm.loop !17

16:                                               ; preds = %12
  %17 = icmp eq ptr %.0, null
  %18 = load ptr, ptr %.017, align 8, !tbaa !12
  %..0.lcssa30 = select i1 %17, ptr %4, ptr %.0
  store ptr %18, ptr %..0.lcssa30, align 8, !tbaa !16
  tail call void @agoo_subject_destroy(ptr noundef nonnull %.017) #3
  br label %.loopexit

.loopexit:                                        ; preds = %11, %.lr.ph, %.preheader, %16
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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 120}
!6 = !{!"_agooUpgraded", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 72, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !11, i64 152, !11, i64 153, !11, i64 154, !11, i64 155, !11, i64 156, !7, i64 160}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_agooAtom", !7, i64 0, !8, i64 8}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"_agooSubject", !7, i64 0, !8, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !15}


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