; 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.5 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_map_string_to_font_utf = external hidden unnamed_addr constant [68 x i8], align 1

declare void @TCOD_sys_map_ascii_to_font(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_map_string_to_font_utf(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %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.7, ptr noundef @.str.5, i32 noundef 259, ptr noundef @__PRETTY_FUNCTION__.TCOD_console_map_string_to_font_utf) #3
  unreachable

11:                                               ; preds = %9
  br label %12

12:                                               ; preds = %29, %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %32

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  call void @TCOD_sys_map_ascii_to_font(i32 noundef %18, i32 noundef %19, i32 noundef %20)
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = load i32, ptr @TCOD_ctx, align 8, !tbaa !11
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %16
  store i32 0, ptr %5, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %6, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %26, %16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds i32, ptr %30, i32 1
  store ptr %31, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !16

32:                                               ; preds = %12
  ret void
}

attributes #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 = { 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 #3 = { 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, !10, i64 0}
!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 = distinct !{!16, !17}
!17 = !{!"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.5 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_map_string_to_font_utf = external hidden unnamed_addr constant [68 x i8], align 1

declare void @TCOD_sys_map_ascii_to_font(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

.preheader:                                       ; preds = %3
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %.not1416 = icmp eq i32 %4, 0
  br i1 %.not1416, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.5, i32 noundef 259, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_console_map_string_to_font_utf) #3
  unreachable

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %6 = phi i32 [ %12, %.lr.ph ], [ %4, %.preheader ]
  %.019 = phi i32 [ %spec.select15, %.lr.ph ], [ %2, %.preheader ]
  %.0818 = phi i32 [ %spec.select, %.lr.ph ], [ %1, %.preheader ]
  %.01017 = phi ptr [ %11, %.lr.ph ], [ %0, %.preheader ]
  tail call void @TCOD_sys_map_ascii_to_font(i32 noundef %6, i32 noundef %.0818, i32 noundef %.019) #4
  %7 = add nsw i32 %.0818, 1
  %8 = load i32, ptr @TCOD_ctx, align 8, !tbaa !9
  %9 = icmp eq i32 %7, %8
  %spec.select = select i1 %9, i32 0, i32 %7
  %10 = zext i1 %9 to i32
  %spec.select15 = add nsw i32 %.019, %10
  %11 = getelementptr inbounds i8, ptr %.01017, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not14 = icmp eq i32 %12, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph, !llvm.loop !15

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

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


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