; LLVM IR from AngoraFuzzer/Angora :: llvm_mode/dfsan_rt/dfsan/dfsan_custom.ll_ (dfsw_strncasecmp)

; 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.__dfsan::Flags" = type { i8, i8, i8, ptr }

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN7__dfsan5flagsEv() #1

declare i32 @dfsan_union(i32 noundef, i32 noundef) #2

declare i32 @dfsan_read_label(ptr noundef, i64 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 willreturn memory(read)
declare i32 @tolower(i32 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local i32 @__dfsw_strncasecmp(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6) #4 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !11
  store i32 %4, ptr %13, align 4, !tbaa !11
  store i32 %5, ptr %14, align 4, !tbaa !11
  store ptr %6, ptr %15, align 8, !tbaa !5
  %17 = load i64, ptr %11, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %7
  %20 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %20, align 4, !tbaa !11
  store i32 0, ptr %8, align 4
  br label %89

21:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %86, %21
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load i64, ptr %16, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %27 = sext i8 %26 to i32
  %28 = call i32 @tolower(i32 noundef %27) #6
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i64, ptr %16, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = sext i8 %32 to i32
  %34 = call i32 @tolower(i32 noundef %33) #6
  %35 = icmp ne i32 %28, %34
  br i1 %35, label %55, label %36

36:                                               ; preds = %22
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i64, ptr %16, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %55, label %43

43:                                               ; preds = %36
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load i64, ptr %16, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !13
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %55, label %50

50:                                               ; preds = %43
  %51 = load i64, ptr %16, align 8, !tbaa !9
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = sub i64 %52, 1
  %54 = icmp eq i64 %51, %53
  br i1 %54, label %55, label %85

55:                                               ; preds = %50, %43, %36, %22
  %56 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7__dfsan5flagsEv()
  %57 = getelementptr inbounds %"struct.__dfsan::Flags", ptr %56, i32 0, i32 2
  %58 = load i8, ptr %57, align 2, !tbaa !14, !range !17, !noundef !18
  %59 = trunc i8 %58 to i1
  br i1 %59, label %60, label %62

60:                                               ; preds = %55
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %61, align 4, !tbaa !11
  br label %73

62:                                               ; preds = %55
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i64, ptr %16, align 8, !tbaa !9
  %65 = add i64 %64, 1
  %66 = call i32 @dfsan_read_label(ptr noundef %63, i64 noundef %65)
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i64, ptr %16, align 8, !tbaa !9
  %69 = add i64 %68, 1
  %70 = call i32 @dfsan_read_label(ptr noundef %67, i64 noundef %69)
  %71 = call i32 @dfsan_union(i32 noundef %66, i32 noundef %70)
  %72 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %71, ptr %72, align 4, !tbaa !11
  br label %73

73:                                               ; preds = %62, %60
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load i64, ptr %16, align 8, !tbaa !9
  %76 = getelementptr inbounds i8, ptr %74, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !13
  %78 = sext i8 %77 to i32
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load i64, ptr %16, align 8, !tbaa !9
  %81 = getelementptr inbounds i8, ptr %79, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !13
  %83 = sext i8 %82 to i32
  %84 = sub nsw i32 %78, %83
  store i32 %84, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %89

85:                                               ; preds = %50
  br label %86

86:                                               ; preds = %85
  %87 = load i64, ptr %16, align 8, !tbaa !9
  %88 = add i64 %87, 1
  store i64 %88, ptr %16, align 8, !tbaa !9
  br label %22, !llvm.loop !19

89:                                               ; preds = %73, %19
  %90 = load i32, ptr %8, align 4
  ret i32 %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 #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 = { mustprogress 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 #5 = { nounwind }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !16, i64 2}
!15 = !{!"_ZTSN7__dfsan5FlagsE", !16, i64 0, !16, i64 1, !16, i64 2, !6, i64 8}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN7__dfsan5flagsEv() local_unnamed_addr #0

declare i32 @dfsan_union(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -255, 256) i32 @__dfsw_strncasecmp(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #3 {
  %8 = icmp eq i64 %2, 0
  br i1 %8, label %10, label %.preheader

.preheader:                                       ; preds = %7
  %9 = add i64 %2, -1
  br label %11

10:                                               ; preds = %7
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %41

11:                                               ; preds = %11, %.preheader
  %.0 = phi i64 [ %23, %11 ], [ 0, %.preheader ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %.0
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = tail call i32 @tolower(i32 noundef %14) #4
  %16 = getelementptr inbounds i8, ptr %1, i64 %.0
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = tail call i32 @tolower(i32 noundef %18) #4
  %.not = icmp ne i32 %15, %19
  %20 = icmp eq i8 %13, 0
  %or.cond = or i1 %20, %.not
  %21 = icmp eq i8 %17, 0
  %or.cond25 = or i1 %21, %or.cond
  %22 = icmp eq i64 %.0, %9
  %or.cond27 = or i1 %22, %or.cond25
  %23 = add i64 %.0, 1
  br i1 %or.cond27, label %24, label %11, !llvm.loop !10

24:                                               ; preds = %11
  %25 = getelementptr inbounds i8, ptr %0, i64 %.0
  %26 = getelementptr inbounds i8, ptr %1, i64 %.0
  %27 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7__dfsan5flagsEv()
  %28 = getelementptr inbounds i8, ptr %27, i64 2
  %29 = load i8, ptr %28, align 2, !tbaa !12, !range !16, !noundef !17
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %35, label %31

31:                                               ; preds = %24
  %32 = tail call i32 @dfsan_read_label(ptr noundef nonnull %0, i64 noundef %23)
  %33 = tail call i32 @dfsan_read_label(ptr noundef nonnull %1, i64 noundef %23)
  %34 = tail call i32 @dfsan_union(i32 noundef %32, i32 noundef %33)
  br label %35

35:                                               ; preds = %24, %31
  %storemerge = phi i32 [ %34, %31 ], [ 0, %24 ]
  store i32 %storemerge, ptr %6, align 4, !tbaa !5
  %36 = load i8, ptr %25, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = load i8, ptr %26, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = sub nsw i32 %37, %39
  br label %41

41:                                               ; preds = %35, %10
  %.023 = phi i32 [ 0, %10 ], [ %40, %35 ]
  ret i32 %.023
}

attributes #0 = { inlinehint mustprogress 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(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 = { mustprogress 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 2}
!13 = !{!"_ZTSN7__dfsan5FlagsE", !14, i64 0, !14, i64 1, !14, i64 2, !15, i64 8}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


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