; LLVM IR from NOAA-PMEL/Ferret :: fer/ccr (c_dncase)

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

@STRING_MISSING_VALUE = external global ptr, align 8
@.str = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @c_dncase_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = 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) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %21

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  call void @FerMem_Free(ptr noundef %20, ptr noundef @.str, i32 noundef 55)
  br label %21

21:                                               ; preds = %18, %13, %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %26, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  br label %76

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %31 = icmp eq ptr %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %33, ptr %34, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  br label %76

35:                                               ; preds = %27
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = call i64 @strlen(ptr noundef %37) #7
  %39 = add i64 %38, 1
  %40 = mul i64 1, %39
  %41 = call ptr @FerMem_Malloc(i64 noundef %40, ptr noundef @.str, i32 noundef 67)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %41, ptr %42, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %35
  call void @abort() #8
  unreachable

47:                                               ; preds = %35
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  store ptr %49, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  store ptr %51, ptr %6, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %57, %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !9
  %55 = sext i8 %54 to i32
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %74

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %58 = call ptr @__ctype_tolower_loc() #9
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %59, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !10
  store i32 %65, ptr %8, align 4, !tbaa !10
  %66 = load i32, ptr %8, align 4, !tbaa !10
  store i32 %66, ptr %9, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %67 = load i32, ptr %9, align 4, !tbaa !10
  %68 = trunc i32 %67 to i8
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %68, ptr %69, align 1, !tbaa !9
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i32 1
  store ptr %71, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i32 1
  store ptr %73, ptr %6, align 8, !tbaa !5
  br label %52, !llvm.loop !12

74:                                               ; preds = %52
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %75, align 1, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %76

76:                                               ; preds = %74, %32, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %77 = load i32, ptr %7, align 4
  switch i32 %77, label %79 [
    i32 0, label %78
    i32 1, label %78
  ]

78:                                               ; preds = %76, %76
  ret void

79:                                               ; preds = %76
  unreachable
}

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

declare void @FerMem_Free(ptr noundef, ptr noundef, i32 noundef) #2

declare ptr @FerMem_Malloc(i64 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: noreturn nounwind
declare void @abort() #4

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() #5

; 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 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 #4 = { noreturn 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 #5 = { nounwind willreturn memory(none) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind willreturn memory(none) }

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

@STRING_MISSING_VALUE = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @c_dncase_(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  %4 = load ptr, ptr @STRING_MISSING_VALUE, align 8
  %.not25 = icmp eq ptr %3, %4
  %or.cond = select i1 %.not, i1 true, i1 %.not25
  br i1 %or.cond, label %6, label %5

5:                                                ; preds = %2
  tail call void @FerMem_Free(ptr noundef nonnull %3, ptr noundef nonnull @.str, i32 noundef 55) #5
  br label %6

6:                                                ; preds = %5, %2
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  store ptr null, ptr %1, align 8, !tbaa !5
  br label %34

10:                                               ; preds = %6
  %11 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %12 = icmp eq ptr %7, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store ptr %11, ptr %1, align 8, !tbaa !5
  br label %34

14:                                               ; preds = %10
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %7) #6
  %16 = add i64 %15, 1
  %17 = tail call ptr @FerMem_Malloc(i64 noundef %16, ptr noundef nonnull @.str, i32 noundef 67) #5
  store ptr %17, ptr %1, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  tail call void @abort() #7
  unreachable

20:                                               ; preds = %14
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %.not2627 = icmp eq i8 %22, 0
  br i1 %.not2627, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %20
  %23 = tail call ptr @__ctype_tolower_loc() #8
  br label %24

24:                                               ; preds = %.lr.ph, %24
  %25 = phi i8 [ %22, %.lr.ph ], [ %33, %24 ]
  %.029 = phi ptr [ %17, %.lr.ph ], [ %31, %24 ]
  %.01928 = phi ptr [ %21, %.lr.ph ], [ %32, %24 ]
  %26 = load ptr, ptr %23, align 8, !tbaa !5
  %27 = sext i8 %25 to i64
  %28 = getelementptr inbounds i32, ptr %26, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !10
  %30 = trunc i32 %29 to i8
  store i8 %30, ptr %.029, align 1, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %.029, i64 1
  %32 = getelementptr inbounds i8, ptr %.01928, i64 1
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %.not26 = icmp eq i8 %33, 0
  br i1 %.not26, label %._crit_edge, label %24, !llvm.loop !12

._crit_edge:                                      ; preds = %24, %20
  %.0.lcssa = phi ptr [ %17, %20 ], [ %31, %24 ]
  store i8 0, ptr %.0.lcssa, align 1, !tbaa !9
  br label %34

34:                                               ; preds = %._crit_edge, %13, %9
  ret void
}

declare void @FerMem_Free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @FerMem_Malloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() local_unnamed_addr #4

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 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 #3 = { noreturn 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 #4 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind willreturn memory(none) }

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


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