; LLVM IR from libtcod/libtcod :: src/libtcod (lex_c)

; 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
define dso_local i32 @TCOD_strcasecmp(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %42, %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %40

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %19 = call ptr @__ctype_tolower_loc() #4
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %20, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !10
  store i32 %26, ptr %5, align 4, !tbaa !10
  %27 = load i32, ptr %5, align 4, !tbaa !10
  store i32 %27, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %28 = load i32, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %29 = call ptr @__ctype_tolower_loc() #4
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %30, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !10
  store i32 %36, ptr %7, align 4, !tbaa !10
  %37 = load i32, ptr %7, align 4, !tbaa !10
  store i32 %37, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %38 = load i32, ptr %8, align 4, !tbaa !10
  %39 = icmp eq i32 %28, %38
  br label %40

40:                                               ; preds = %18, %13
  %41 = phi i1 [ false, %13 ], [ %39, %18 ]
  br i1 %41, label %42, label %47

42:                                               ; preds = %40
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %4, align 8, !tbaa !5
  br label %13, !llvm.loop !12

47:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %48 = call ptr @__ctype_tolower_loc() #4
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %49, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !10
  store i32 %55, ptr %9, align 4, !tbaa !10
  %56 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %56, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %57 = load i32, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %58 = call ptr @__ctype_tolower_loc() #4
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load ptr, ptr %4, 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 %11, align 4, !tbaa !10
  %66 = load i32, ptr %11, align 4, !tbaa !10
  store i32 %66, ptr %12, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %67 = load i32, ptr %12, align 4, !tbaa !10
  %68 = sub nsw i32 %57, %67
  ret i32 %68
}

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

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 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 #3 = { nounwind }
attributes #4 = { 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"

; Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @TCOD_strcasecmp(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not16 = icmp eq i8 %3, 0
  %.pre = tail call ptr @__ctype_tolower_loc() #2
  br i1 %.not16, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = load ptr, ptr %.pre, align 8, !tbaa !8
  br label %5

5:                                                ; preds = %.lr.ph, %15
  %6 = phi i8 [ %3, %.lr.ph ], [ %18, %15 ]
  %.018 = phi ptr [ %0, %.lr.ph ], [ %16, %15 ]
  %.01417 = phi ptr [ %1, %.lr.ph ], [ %17, %15 ]
  %7 = sext i8 %6 to i64
  %8 = getelementptr inbounds i32, ptr %4, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = load i8, ptr %.01417, align 1, !tbaa !5
  %11 = sext i8 %10 to i64
  %12 = getelementptr inbounds i32, ptr %4, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = icmp eq i32 %9, %13
  br i1 %14, label %15, label %.critedge.loopexit

15:                                               ; preds = %5
  %16 = getelementptr inbounds i8, ptr %.018, i64 1
  %17 = getelementptr inbounds i8, ptr %.01417, i64 1
  %18 = load i8, ptr %16, align 1, !tbaa !5
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %.critedge.loopexit, label %5, !llvm.loop !12

.critedge.loopexit:                               ; preds = %15, %5
  %.014.lcssa.ph = phi ptr [ %.01417, %5 ], [ %17, %15 ]
  %.lcssa.ph = phi i8 [ %6, %5 ], [ 0, %15 ]
  %19 = sext i8 %.lcssa.ph to i64
  br label %.critedge

.critedge:                                        ; preds = %2, %.critedge.loopexit
  %.014.lcssa = phi ptr [ %.014.lcssa.ph, %.critedge.loopexit ], [ %1, %2 ]
  %.lcssa = phi i64 [ %19, %.critedge.loopexit ], [ 0, %2 ]
  %20 = load ptr, ptr %.pre, align 8, !tbaa !8
  %21 = getelementptr inbounds i32, ptr %20, i64 %.lcssa
  %22 = load i32, ptr %21, align 4, !tbaa !10
  %23 = load i8, ptr %.014.lcssa, align 1, !tbaa !5
  %24 = sext i8 %23 to i64
  %25 = getelementptr inbounds i32, ptr %20, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %27 = sub nsw i32 %22, %26
  ret i32 %27
}

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

attributes #0 = { nofree nosync nounwind memory(read, inaccessiblemem: none) 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 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 #2 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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