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

; 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_ConsoleTile = type { i32, %struct.TCOD_ColorRGBA, %struct.TCOD_ColorRGBA }
%struct.TCOD_ColorRGBA = type { i8, i8, i8, i8 }
%struct.TCOD_Console = type { i32, i32, ptr, i32, i32, %struct.TCOD_ColorRGB, %struct.TCOD_ColorRGB, i8, %struct.TCOD_ColorRGB, i32, ptr, ptr }
%struct.TCOD_ColorRGB = type { i8, i8, i8 }

; 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: inlinehint nounwind uwtable
declare hidden ptr @TCOD_console_validate_(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

9:                                                ; preds = %1
  br label %64

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 12, ptr %3) #4
  %11 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %3, i32 0, i32 0
  store i32 32, ptr %11, align 4, !tbaa !9
  %12 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %3, i32 0, i32 1
  %13 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TCOD_Console, ptr %14, i32 0, i32 5
  %16 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %15, i32 0, i32 0
  %17 = load i8, ptr %16, align 8, !tbaa !13
  store i8 %17, ptr %13, align 4, !tbaa !17
  %18 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %12, i32 0, i32 1
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TCOD_Console, ptr %19, i32 0, i32 5
  %21 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %20, i32 0, i32 1
  %22 = load i8, ptr %21, align 1, !tbaa !18
  store i8 %22, ptr %18, align 1, !tbaa !19
  %23 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %12, i32 0, i32 2
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCOD_Console, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %25, i32 0, i32 2
  %27 = load i8, ptr %26, align 2, !tbaa !20
  store i8 %27, ptr %23, align 2, !tbaa !21
  %28 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %12, i32 0, i32 3
  store i8 -1, ptr %28, align 1, !tbaa !22
  %29 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %3, i32 0, i32 2
  %30 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TCOD_Console, ptr %31, i32 0, i32 6
  %33 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %32, i32 0, i32 0
  %34 = load i8, ptr %33, align 1, !tbaa !23
  store i8 %34, ptr %30, align 4, !tbaa !17
  %35 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %29, i32 0, i32 1
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TCOD_Console, ptr %36, i32 0, i32 6
  %38 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %37, i32 0, i32 1
  %39 = load i8, ptr %38, align 1, !tbaa !24
  store i8 %39, ptr %35, align 1, !tbaa !19
  %40 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %29, i32 0, i32 2
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TCOD_Console, ptr %41, i32 0, i32 6
  %43 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %42, i32 0, i32 2
  %44 = load i8, ptr %43, align 1, !tbaa !25
  store i8 %44, ptr %40, align 2, !tbaa !21
  %45 = getelementptr inbounds %struct.TCOD_ColorRGBA, ptr %29, i32 0, i32 3
  store i8 -1, ptr %45, align 1, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !26
  br label %46

46:                                               ; preds = %60, %10
  %47 = load i32, ptr %4, align 4, !tbaa !26
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TCOD_Console, ptr %48, i32 0, i32 9
  %50 = load i32, ptr %49, align 4, !tbaa !27
  %51 = icmp slt i32 %47, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %63

53:                                               ; preds = %46
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TCOD_Console, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !28
  %57 = load i32, ptr %4, align 4, !tbaa !26
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %56, i64 %58
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %59, ptr align 4 %3, i64 12, i1 false), !tbaa.struct !29
  br label %60

60:                                               ; preds = %53
  %61 = load i32, ptr %4, align 4, !tbaa !26
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !26
  br label %46, !llvm.loop !31

63:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 12, ptr %3) #4
  br label %64

64:                                               ; preds = %63, %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"TCOD_ConsoleTile", !11, i64 0, !12, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"TCOD_ColorRGBA", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!13 = !{!14, !7, i64 24}
!14 = !{!"TCOD_Console", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16, !11, i64 20, !15, i64 24, !15, i64 27, !16, i64 30, !15, i64 31, !11, i64 36, !6, i64 40, !6, i64 48}
!15 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!12, !7, i64 0}
!18 = !{!14, !7, i64 25}
!19 = !{!12, !7, i64 1}
!20 = !{!14, !7, i64 26}
!21 = !{!12, !7, i64 2}
!22 = !{!12, !7, i64 3}
!23 = !{!14, !7, i64 27}
!24 = !{!14, !7, i64 28}
!25 = !{!14, !7, i64 29}
!26 = !{!11, !11, i64 0}
!27 = !{!14, !11, i64 36}
!28 = !{!14, !6, i64 8}
!29 = !{i64 0, i64 4, !26, i64 4, i64 1, !30, i64 5, i64 1, !30, i64 6, i64 1, !30, i64 7, i64 1, !30, i64 8, i64 1, !30, i64 9, i64 1, !30, i64 10, i64 1, !30, i64 11, i64 1, !30}
!30 = !{!7, !7, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"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_ConsoleTile = type { i32, %struct.TCOD_ColorRGBA, %struct.TCOD_ColorRGBA }
%struct.TCOD_ColorRGBA = type { i8, i8, i8, i8 }

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @TCOD_console_validate_(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_clear(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 24
  %5 = load i8, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 25
  %7 = load i8, ptr %6, align 1, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %2, i64 26
  %9 = load i8, ptr %8, align 2, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %2, i64 27
  %11 = load i8, ptr %10, align 1, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %2, i64 28
  %13 = load i8, ptr %12, align 1, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %2, i64 29
  %15 = load i8, ptr %14, align 1, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %2, i64 36
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %3
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  br label %20

20:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %21 = load ptr, ptr %19, align 8, !tbaa !19
  %22 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %21, i64 %indvars.iv
  store i32 32, ptr %22, align 4, !tbaa !20
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 4
  store i8 %5, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !21
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 5
  store i8 %7, ptr %.sroa.5.0..sroa_idx, align 1, !tbaa !21
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 6
  store i8 %9, ptr %.sroa.6.0..sroa_idx, align 2, !tbaa !21
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 7
  store i8 -1, ptr %.sroa.7.0..sroa_idx, align 1, !tbaa !21
  %.sroa.8.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 8
  store i8 %11, ptr %.sroa.8.0..sroa_idx, align 4, !tbaa !21
  %.sroa.9.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 9
  store i8 %13, ptr %.sroa.9.0..sroa_idx, align 1, !tbaa !21
  %.sroa.10.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 10
  store i8 %15, ptr %.sroa.10.0..sroa_idx, align 2, !tbaa !21
  %.sroa.11.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 11
  store i8 -1, ptr %.sroa.11.0..sroa_idx, align 1, !tbaa !21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %16, align 4, !tbaa !18
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %20, label %.loopexit, !llvm.loop !22

.loopexit:                                        ; preds = %20, %3, %1
  ret void
}

attributes #0 = { inlinehint 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 = { 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, !8, i64 24}
!6 = !{!"TCOD_Console", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16, !7, i64 20, !11, i64 24, !11, i64 27, !12, i64 30, !11, i64 31, !7, i64 36, !10, i64 40, !10, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"TCOD_ColorRGB", !8, i64 0, !8, i64 1, !8, i64 2}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!6, !8, i64 25}
!14 = !{!6, !8, i64 26}
!15 = !{!6, !8, i64 27}
!16 = !{!6, !8, i64 28}
!17 = !{!6, !8, i64 29}
!18 = !{!6, !7, i64 36}
!19 = !{!6, !10, i64 8}
!20 = !{!7, !7, i64 0}
!21 = !{!8, !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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