; 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"

%struct.TCOD_PrintParamsRGB = type { i32, i32, i32, i32, ptr, ptr, i32, i32 }
%struct.PrintParams = type { ptr, i32, i32, i32, i32, ptr, ptr, i32, i32, 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: nounwind uwtable
declare hidden i32 @printn_internal_(ptr noalias noundef, i64 noundef, ptr noalias noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_printn_rgb(ptr noalias noundef %0, ptr noundef byval(%struct.TCOD_PrintParamsRGB) align 8 %1, i32 noundef %2, ptr noalias noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.PrintParams, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  store ptr %3, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 56, ptr %8) #3
  %10 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 0
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call ptr @TCOD_console_validate_(ptr noundef %11)
  store ptr %12, ptr %10, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 1
  %14 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !14
  store i32 %15, ptr %13, align 8, !tbaa !16
  %16 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 2
  %17 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !17
  store i32 %18, ptr %16, align 4, !tbaa !18
  %19 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 3
  %20 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !19
  store i32 %21, ptr %19, align 8, !tbaa !20
  %22 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 4
  %23 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !21
  store i32 %24, ptr %22, align 4, !tbaa !22
  %25 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 5
  %26 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  store ptr %27, ptr %25, align 8, !tbaa !24
  %28 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 6
  %29 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 5
  %30 = load ptr, ptr %29, align 8, !tbaa !25
  store ptr %30, ptr %28, align 8, !tbaa !26
  %31 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 7
  %32 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 6
  %33 = load i32, ptr %32, align 8, !tbaa !27
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %4
  %36 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 6
  %37 = load i32, ptr %36, align 8, !tbaa !27
  br label %39

38:                                               ; preds = %4
  br label %39

39:                                               ; preds = %38, %35
  %40 = phi i32 [ %37, %35 ], [ 1, %38 ]
  store i32 %40, ptr %31, align 8, !tbaa !28
  %41 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 8
  %42 = getelementptr inbounds %struct.TCOD_PrintParamsRGB, ptr %1, i32 0, i32 7
  %43 = load i32, ptr %42, align 4, !tbaa !29
  store i32 %43, ptr %41, align 4, !tbaa !30
  %44 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 9
  store i8 1, ptr %44, align 8, !tbaa !31
  %45 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 10
  store i8 0, ptr %45, align 1, !tbaa !32
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = call i32 @printn_internal_(ptr noundef %8, i64 noundef %47, ptr noundef %48)
  store i32 %49, ptr %9, align 4, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 56, ptr %8) #3
  ret i32 %50
}

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 = { 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 = !{!"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 0}
!12 = !{!"PrintParams", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !13, i64 48, !13, i64 49}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"TCOD_PrintParamsRGB", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!16 = !{!12, !10, i64 8}
!17 = !{!15, !10, i64 4}
!18 = !{!12, !10, i64 12}
!19 = !{!15, !10, i64 8}
!20 = !{!12, !10, i64 16}
!21 = !{!15, !10, i64 12}
!22 = !{!12, !10, i64 20}
!23 = !{!15, !6, i64 16}
!24 = !{!12, !6, i64 24}
!25 = !{!15, !6, i64 24}
!26 = !{!12, !6, i64 32}
!27 = !{!15, !10, i64 32}
!28 = !{!12, !10, i64 40}
!29 = !{!15, !10, i64 36}
!30 = !{!12, !10, i64 44}
!31 = !{!12, !13, i64 48}
!32 = !{!12, !13, i64 49}


; 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_PrintParamsRGB = type { i32, i32, i32, i32, ptr, ptr, i32, i32 }
%struct.PrintParams = type { ptr, i32, i32, i32, i32, ptr, ptr, i32, i32, i8, i8 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @printn_internal_(ptr noalias noundef, i64 noundef, ptr noalias noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_printn_rgb(ptr noalias noundef %0, ptr nocapture noundef readonly byval(%struct.TCOD_PrintParamsRGB) align 8 %1, i32 noundef %2, ptr noalias noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.PrintParams, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %5) #4
  %6 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  store ptr %6, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  %8 = load <4 x i32>, ptr %1, align 8, !tbaa !12
  store <4 x i32> %8, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %5, i64 24
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load <2 x ptr>, ptr %10, align 8, !tbaa !13
  store <2 x ptr> %11, ptr %9, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %5, i64 40
  %13 = getelementptr inbounds i8, ptr %1, i64 32
  %14 = load i32, ptr %13, align 8
  %15 = tail call i32 @llvm.umax.i32(i32 %14, i32 1)
  store i32 %15, ptr %12, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %5, i64 44
  %17 = getelementptr inbounds i8, ptr %1, i64 36
  %18 = load i32, ptr %17, align 4, !tbaa !15
  store i32 %18, ptr %16, align 4, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %5, i64 48
  store i8 1, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %5, i64 49
  store i8 0, ptr %20, align 1, !tbaa !19
  %21 = sext i32 %2 to i64
  %22 = call i32 @printn_internal_(ptr noundef nonnull %5, i64 noundef %21, ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #4
  ret i32 %22
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #3

attributes #0 = { mustprogress 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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"PrintParams", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !11, i64 48, !11, i64 49}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !10, i64 40}
!15 = !{!16, !10, i64 36}
!16 = !{!"TCOD_PrintParamsRGB", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!17 = !{!6, !10, i64 44}
!18 = !{!6, !11, i64 48}
!19 = !{!6, !11, i64 49}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass