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

; 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: nounwind uwtable
define dso_local ptr @TCOD_console_strchr_utf(ptr noundef %0, i8 noundef signext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  br label %5

5:                                                ; preds = %28, %2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %15

9:                                                ; preds = %5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i32, ptr %10, align 4, !tbaa !10
  %12 = load i8, ptr %4, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp ne i32 %11, %13
  br label %15

15:                                               ; preds = %9, %5
  %16 = phi i1 [ false, %5 ], [ %14, %9 ]
  br i1 %16, label %17, label %31

17:                                               ; preds = %15
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = icmp eq i32 %19, 6
  br i1 %20, label %25, label %21

21:                                               ; preds = %17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %24 = icmp eq i32 %23, 7
  br i1 %24, label %25, label %28

25:                                               ; preds = %21, %17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %26, i64 3
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %25, %21
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds i32, ptr %29, i32 1
  store ptr %30, ptr %3, align 8, !tbaa !5
  br label %5, !llvm.loop !12

31:                                               ; preds = %15
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 4, !tbaa !10
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  br label %38

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37, %35
  %39 = phi ptr [ %36, %35 ], [ null, %37 ]
  ret ptr %39
}

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 = !{!"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 norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @TCOD_console_strchr_utf(ptr noundef readonly %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = sext i8 %1 to i32
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %.not11 = icmp eq i32 %4, 0
  %.not912 = icmp eq i32 %4, %3
  %or.cond13 = or i1 %.not11, %.not912
  br i1 %or.cond13, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %5 = phi i32 [ %8, %.lr.ph ], [ %4, %2 ]
  %.014 = phi ptr [ %7, %.lr.ph ], [ %0, %2 ]
  %6 = and i32 %5, -2
  %switch = icmp eq i32 %6, 6
  %spec.select.idx = select i1 %switch, i64 12, i64 0
  %spec.select = getelementptr inbounds i8, ptr %.014, i64 %spec.select.idx
  %7 = getelementptr inbounds i8, ptr %spec.select, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  %.not9 = icmp eq i32 %8, %3
  %or.cond = or i1 %.not, %.not9
  br i1 %or.cond, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %2
  %.0.lcssa = phi ptr [ %0, %2 ], [ %7, %.lr.ph ]
  %.not.lcssa = phi i1 [ %.not11, %2 ], [ %.not, %.lr.ph ]
  %9 = select i1 %.not.lcssa, ptr null, ptr %.0.lcssa
  ret ptr %9
}

attributes #0 = { nofree norecurse 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" }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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