; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources (dhutils)

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

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

; 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
declare dso_local signext i8 @to_lower(i8 noundef signext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @strncasecmp(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  br label %11

11:                                               ; preds = %37, %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = call signext i8 @to_lower(i8 noundef signext %13)
  store i8 %14, ptr %8, align 1, !tbaa !11
  %15 = sext i8 %14 to i32
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = call signext i8 @to_lower(i8 noundef signext %17)
  store i8 %18, ptr %9, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %15, %19
  br i1 %20, label %21, label %38

21:                                               ; preds = %11
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %7, align 4, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i32
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %21
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %44

33:                                               ; preds = %21
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  br label %38

37:                                               ; preds = %33
  br label %11, !llvm.loop !12

38:                                               ; preds = %36, %11
  %39 = load i8, ptr %8, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = load i8, ptr %9, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = sub nsw i32 %40, %42
  store i32 %43, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %44

44:                                               ; preds = %38, %32
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  %45 = load i32, ptr %4, align 4
  ret i32 %45
}

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @to_lower(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -255, 256) i32 @strncasecmp(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %.pre = load i8, ptr %0, align 1, !tbaa !5
  br label %4

4:                                                ; preds = %14, %3
  %5 = phi i8 [ %.pre, %3 ], [ %12, %14 ]
  %.011 = phi ptr [ %1, %3 ], [ %16, %14 ]
  %.010 = phi i32 [ %2, %3 ], [ %15, %14 ]
  %.09 = phi ptr [ %0, %3 ], [ %11, %14 ]
  %6 = tail call signext i8 @to_lower(i8 noundef signext %5)
  %7 = load i8, ptr %.011, align 1, !tbaa !5
  %8 = tail call signext i8 @to_lower(i8 noundef signext %7)
  %9 = icmp eq i8 %6, %8
  br i1 %9, label %10, label %18

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %.09, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = icmp eq i8 %12, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %10
  %15 = add nsw i32 %.010, -1
  %16 = getelementptr inbounds i8, ptr %.011, i64 1
  %17 = icmp eq i32 %15, 0
  br i1 %17, label %18, label %4, !llvm.loop !8

18:                                               ; preds = %14, %4
  %.lcssa = phi i8 [ %6, %14 ], [ %8, %4 ]
  %19 = sext i8 %6 to i32
  %20 = sext i8 %.lcssa to i32
  %21 = sub nsw i32 %19, %20
  br label %.loopexit

.loopexit:                                        ; preds = %10, %18
  %.0 = phi i32 [ %21, %18 ], [ 0, %10 ]
  ret i32 %.0
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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