; 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: nounwind uwtable
define dso_local void @agoo_upgraded_add_subject(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._agooUpgraded, ptr %7, i32 0, i32 5
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %25, %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %29

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._agooSubject, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds [8 x i8], ptr %15, i64 0, i64 0
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._agooSubject, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds [8 x i8], ptr %18, i64 0, i64 0
  %20 = call i32 @strcmp(ptr noundef %16, ptr noundef %19) #5
  %21 = icmp eq i32 0, %20
  br i1 %21, label %22, label %24

22:                                               ; preds = %13
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  call void @agoo_subject_destroy(ptr noundef %23)
  store i32 1, ptr %6, align 4
  br label %38

24:                                               ; preds = %13
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._agooSubject, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %28, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !15

29:                                               ; preds = %10
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._agooUpgraded, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._agooSubject, ptr %33, i32 0, i32 0
  store ptr %32, ptr %34, align 8, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._agooUpgraded, ptr %36, i32 0, i32 5
  store ptr %35, ptr %37, align 8, !tbaa !9
  store i32 0, ptr %6, align 4
  br label %38

38:                                               ; preds = %29, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %39 = load i32, ptr %6, align 4
  switch i32 %39, label %41 [
    i32 0, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38
  ret void

41:                                               ; preds = %38
  unreachable
}

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

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

declare void @agoo_subject_destroy(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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"}


; 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 @agoo_upgraded_add_subject(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  br label %5

5:                                                ; preds = %6, %2
  %.0.in = phi ptr [ %3, %2 ], [ %.0, %6 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %11, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.0, i64 8
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) %7) #3
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %5, !llvm.loop !9

10:                                               ; preds = %6
  tail call void @agoo_subject_destroy(ptr noundef %1) #4
  br label %13

11:                                               ; preds = %5
  %12 = load ptr, ptr %3, align 8, !tbaa !11
  store ptr %12, ptr %1, align 8, !tbaa !15
  store ptr %1, ptr %3, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %11, %10
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @agoo_subject_destroy(ptr 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 = { 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 #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 willreturn memory(read) }
attributes #4 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 120}
!12 = !{!"_agooUpgraded", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 72, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !14, i64 152, !14, i64 153, !14, i64 154, !14, i64 155, !14, i64 156, !6, i64 160}
!13 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"_agooSubject", !6, i64 0, !7, i64 8}


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