; 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

; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_map_ascii_codes_to_font(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %10, ptr %9, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %31, %4
  %12 = load i32, ptr %9, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = add nsw i32 %13, %14
  %16 = icmp slt i32 %12, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %34

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

27:                                               ; preds = %18
  store i32 0, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %27, %18
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %9, align 4, !tbaa !5
  br label %11, !llvm.loop !15

34:                                               ; preds = %17
  ret void
}

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


; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_map_ascii_codes_to_font(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = add nsw i32 %1, %0
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

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

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.018 = phi i32 [ %11, %.lr.ph ], [ %0, %4 ]
  %.01117 = phi i32 [ %spec.select15, %.lr.ph ], [ %3, %4 ]
  %.01216 = phi i32 [ %spec.select, %.lr.ph ], [ %2, %4 ]
  tail call void @TCOD_sys_map_ascii_to_font(i32 noundef %.018, i32 noundef %.01216, i32 noundef %.01117) #2
  %7 = add nsw i32 %.01216, 1
  %8 = load i32, ptr @TCOD_ctx, align 8, !tbaa !5
  %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 %.01117, %10
  %11 = add nsw i32 %.018, 1
  %12 = icmp slt i32 %11, %5
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

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 = { 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, !7, i64 0}
!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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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