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

; 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.TCOD_internal_context_t = type { i32, i32, i8, i8, i8, i32, i32, i32, [512 x i8], [512 x i8], ptr, ptr, ptr, i32, i8, i32, i32, i32, i32, i32, i32, ptr, %struct.TCOD_ColorRGB, i8, %struct.TCOD_key_t, i8, i8, i8, ptr, ptr }
%struct.TCOD_ColorRGB = type { i8, i8, i8 }
%struct.TCOD_key_t = type { i32, i8, [32 x i8], i8, i8, i8, i8, i8, i8, i8, i8 }

@TCOD_ctx = external dso_local global %struct.TCOD_internal_context_t, align 8
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_map_string_to_font = external hidden unnamed_addr constant [61 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_console_map_ascii_code_to_font(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_map_string_to_font(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %3
  br label %11

10:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.5, i32 noundef 245, ptr noundef @__PRETTY_FUNCTION__.TCOD_console_map_string_to_font) #2
  unreachable

11:                                               ; preds = %9
  %12 = load ptr, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 12), align 8, !tbaa !11
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  br label %16

15:                                               ; preds = %11
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.5, i32 noundef 247, ptr noundef @__PRETTY_FUNCTION__.TCOD_console_map_string_to_font) #2
  unreachable

16:                                               ; preds = %14
  br label %17

17:                                               ; preds = %35, %16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !16
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %38

21:                                               ; preds = %17
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !16
  %24 = sext i8 %23 to i32
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  call void @TCOD_console_map_ascii_code_to_font(i32 noundef %24, i32 noundef %25, i32 noundef %26)
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr @TCOD_ctx, align 8, !tbaa !17
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %21
  store i32 0, ptr %5, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %32, %21
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i32 1
  store ptr %37, ptr %4, align 8, !tbaa !5
  br label %17, !llvm.loop !18

38:                                               ; preds = %17
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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 = { 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 #2 = { noreturn 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 = !{!12, !6, i64 1064}
!12 = !{!"TCOD_internal_context_t", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 9, !13, i64 10, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 536, !6, i64 1048, !6, i64 1056, !6, i64 1064, !10, i64 1072, !13, i64 1076, !10, i64 1080, !10, i64 1084, !10, i64 1088, !10, i64 1092, !10, i64 1096, !10, i64 1100, !6, i64 1104, !14, i64 1112, !7, i64 1115, !15, i64 1116, !13, i64 1164, !13, i64 1165, !13, i64 1166, !6, i64 1168, !6, i64 1176}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!"TCOD_key_t", !10, i64 0, !7, i64 4, !7, i64 5, !13, i64 37, !13, i64 38, !13, i64 39, !13, i64 40, !13, i64 41, !13, i64 42, !13, i64 43, !13, i64 44}
!16 = !{!7, !7, i64 0}
!17 = !{!12, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.TCOD_internal_context_t = type { i32, i32, i8, i8, i8, i32, i32, i32, [512 x i8], [512 x i8], ptr, ptr, ptr, i32, i8, i32, i32, i32, i32, i32, i32, ptr, %struct.TCOD_ColorRGB, i8, %struct.TCOD_key_t, i8, i8, i8, ptr, ptr }
%struct.TCOD_ColorRGB = type { i8, i8, i8 }
%struct.TCOD_key_t = type { i32, i8, [32 x i8], i8, i8, i8, i8, i8, i8, i8, i8 }

@TCOD_ctx = external dso_local local_unnamed_addr global %struct.TCOD_internal_context_t, align 8
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_map_string_to_font = external hidden unnamed_addr constant [61 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_console_map_ascii_code_to_font(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_map_string_to_font(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i32 noundef 245, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_console_map_string_to_font) #2
  unreachable

5:                                                ; preds = %3
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 1064), align 8, !tbaa !5
  %.not14 = icmp eq ptr %6, null
  br i1 %.not14, label %8, label %.preheader

.preheader:                                       ; preds = %5
  %7 = load i8, ptr %0, align 1, !tbaa !14
  %.not1517 = icmp eq i8 %7, 0
  br i1 %.not1517, label %._crit_edge, label %.lr.ph

8:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.5, i32 noundef 247, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_console_map_string_to_font) #2
  unreachable

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %9 = phi i8 [ %16, %.lr.ph ], [ %7, %.preheader ]
  %.020 = phi i32 [ %spec.select16, %.lr.ph ], [ %2, %.preheader ]
  %.0819 = phi i32 [ %spec.select, %.lr.ph ], [ %1, %.preheader ]
  %.01018 = phi ptr [ %15, %.lr.ph ], [ %0, %.preheader ]
  %10 = sext i8 %9 to i32
  tail call void @TCOD_console_map_ascii_code_to_font(i32 noundef %10, i32 noundef %.0819, i32 noundef %.020)
  %11 = add nsw i32 %.0819, 1
  %12 = load i32, ptr @TCOD_ctx, align 8, !tbaa !15
  %13 = icmp eq i32 %11, %12
  %spec.select = select i1 %13, i32 0, i32 %11
  %14 = zext i1 %13 to i32
  %spec.select16 = add nsw i32 %.020, %14
  %15 = getelementptr inbounds i8, ptr %.01018, i64 1
  %16 = load i8, ptr %15, align 1, !tbaa !14
  %.not15 = icmp eq i8 %16, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 = { 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 #2 = { noreturn 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, !11, i64 1064}
!6 = !{!"TCOD_internal_context_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9, !10, i64 10, !7, i64 12, !7, i64 16, !7, i64 20, !8, i64 24, !8, i64 536, !11, i64 1048, !11, i64 1056, !11, i64 1064, !7, i64 1072, !10, i64 1076, !7, i64 1080, !7, i64 1084, !7, i64 1088, !7, i64 1092, !7, i64 1096, !7, i64 1100, !11, i64 1104, !12, i64 1112, !8, i64 1115, !13, i64 1116, !10, i64 1164, !10, i64 1165, !10, i64 1166, !11, i64 1168, !11, i64 1176}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"TCOD_ColorRGB", !8, i64 0, !8, i64 1, !8, i64 2}
!13 = !{!"TCOD_key_t", !7, i64 0, !8, i64 4, !8, i64 5, !10, i64 37, !10, i64 38, !10, i64 39, !10, i64 40, !10, i64 41, !10, i64 42, !10, i64 43, !10, i64 44}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass