; 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 @vprintf_internal_(ptr noalias noundef, ptr noalias noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_vprintf_rgb(ptr noalias noundef %0, ptr noundef byval(%struct.TCOD_PrintParamsRGB) align 8 %1, ptr noalias noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %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 ptr %2, ptr %6, align 8, !tbaa !5
  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 !9
  %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 !13
  store i32 %15, ptr %13, align 8, !tbaa !15
  %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 !16
  store i32 %18, ptr %16, align 4, !tbaa !17
  %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 !18
  store i32 %21, ptr %19, align 8, !tbaa !19
  %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 !20
  store i32 %24, ptr %22, align 4, !tbaa !21
  %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 !22
  store ptr %27, ptr %25, align 8, !tbaa !23
  %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 !24
  store ptr %30, ptr %28, align 8, !tbaa !25
  %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 !26
  %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 !26
  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 !27
  %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 !28
  store i32 %43, ptr %41, align 4, !tbaa !29
  %44 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 9
  store i8 1, ptr %44, align 8, !tbaa !30
  %45 = getelementptr inbounds %struct.PrintParams, ptr %8, i32 0, i32 10
  store i8 0, ptr %45, align 1, !tbaa !31
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call i32 @vprintf_internal_(ptr noundef %8, ptr noundef %46, ptr noundef %47)
  store i32 %48, ptr %9, align 4, !tbaa !32
  %49 = load i32, ptr %9, align 4, !tbaa !32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 56, ptr %8) #3
  ret i32 %49
}

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


; 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 @vprintf_internal_(ptr noalias noundef, ptr noalias noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_vprintf_rgb(ptr noalias noundef %0, ptr nocapture noundef readonly byval(%struct.TCOD_PrintParamsRGB) align 8 %1, ptr noalias noundef %2, ptr 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 = call i32 @vprintf_internal_(ptr noundef nonnull %5, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #4
  ret i32 %21
}

; 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