; LLVM IR from NOAA-PMEL/Ferret :: fer/efi (us2i_compare_string_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.strngs = type { [512 x i8], i32 }

@GLOBAL_unique_us2i_List = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @us2i_compare_string_list_(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
  %7 = 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) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr @GLOBAL_unique_us2i_List, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i32 @add_us2i_string(ptr noundef %11)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %12, ptr %13, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  br label %31

14:                                               ; preds = %2
  %15 = load ptr, ptr @GLOBAL_unique_us2i_List, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 @list_traverse(ptr noundef %15, ptr noundef %16, ptr noundef @ListTraverse_FoundString, i32 noundef 68)
  store i32 %17, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 1
  br i1 %19, label %20, label %24

20:                                               ; preds = %14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @add_us2i_string(ptr noundef %21)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %22, ptr %23, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  br label %31

24:                                               ; preds = %14
  %25 = load ptr, ptr @GLOBAL_unique_us2i_List, align 8, !tbaa !5
  %26 = call ptr @list_curr(ptr noundef %25)
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.strngs, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %29, ptr %30, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %31

31:                                               ; preds = %24, %20, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %32 = load i32, ptr %7, align 4
  switch i32 %32, label %34 [
    i32 0, label %33
    i32 1, label %33
  ]

33:                                               ; preds = %31, %31
  ret void

34:                                               ; preds = %31
  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 uwtable
declare hidden i32 @add_us2i_string(ptr noundef) #0

declare i32 @list_traverse(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

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

declare ptr @list_curr(ptr noundef) #2

; 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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 512}
!12 = !{!"", !7, i64 0, !10, i64 512}


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

@GLOBAL_unique_us2i_List = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @us2i_compare_string_list_(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @GLOBAL_unique_us2i_List, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call i32 @add_us2i_string(ptr noundef %0)
  br label %16

7:                                                ; preds = %2
  %8 = tail call i32 @list_traverse(ptr noundef nonnull %3, ptr noundef %0, ptr noundef nonnull @ListTraverse_FoundString, i32 noundef 68) #2
  %.not = icmp eq i32 %8, 1
  br i1 %.not, label %11, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @add_us2i_string(ptr noundef %0)
  br label %16

11:                                               ; preds = %7
  %12 = load ptr, ptr @GLOBAL_unique_us2i_List, align 8, !tbaa !5
  %13 = tail call ptr @list_curr(ptr noundef %12) #2
  %14 = getelementptr inbounds i8, ptr %13, i64 512
  %15 = load i32, ptr %14, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %11, %9, %5
  %.sink = phi i32 [ %15, %11 ], [ %10, %9 ], [ %6, %5 ]
  store i32 %.sink, ptr %1, align 4, !tbaa !12
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @add_us2i_string(ptr noundef) local_unnamed_addr #0

declare i32 @list_traverse(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

declare ptr @list_curr(ptr noundef) local_unnamed_addr #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 = { "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, !11, i64 512}
!10 = !{!"", !7, i64 0, !11, i64 512}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}


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