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

@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [34 x i8], align 1

; 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: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #1

declare i32 @TCOD_set_errorf(ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @vprintf_internal_(ptr noalias noundef, ptr noalias noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @normalize_old_rect_(ptr noalias noundef, i32 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_console_get_height_rect_fmt(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noalias noundef %5, ...) #4 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca %struct.PrintParams, align 8
  %15 = alloca [1 x %struct.__va_list_tag], align 16
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call ptr @TCOD_console_validate_(ptr noundef %17)
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %23, label %21

21:                                               ; preds = %6
  %22 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 1470, ptr noundef @.str.7)
  store i32 -2, ptr %7, align 4
  br label %48

23:                                               ; preds = %6
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  call void @normalize_old_rect_(ptr noundef %24, i32 noundef 0, ptr noundef %9, ptr noundef %10, ptr noundef %11, ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 56, ptr %14) #5
  %25 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 0
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = call ptr @TCOD_console_validate_(ptr noundef %26)
  store ptr %27, ptr %25, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 1
  %29 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %29, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 2
  %31 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %31, ptr %30, align 4, !tbaa !15
  %32 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 3
  %33 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %33, ptr %32, align 8, !tbaa !16
  %34 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 4
  %35 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %35, ptr %34, align 4, !tbaa !17
  %36 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 5
  store ptr null, ptr %36, align 8, !tbaa !18
  %37 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 6
  store ptr null, ptr %37, align 8, !tbaa !19
  %38 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 7
  store i32 0, ptr %38, align 8, !tbaa !20
  %39 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 8
  store i32 0, ptr %39, align 4, !tbaa !21
  %40 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 9
  store i8 1, ptr %40, align 8, !tbaa !22
  %41 = getelementptr inbounds %struct.PrintParams, ptr %14, i32 0, i32 10
  store i8 1, ptr %41, align 1, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #5
  %42 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %15, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %42)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %15, i64 0, i64 0
  %45 = call i32 @vprintf_internal_(ptr noundef %14, ptr noundef %43, ptr noundef %44)
  store i32 %45, ptr %16, align 4, !tbaa !9
  %46 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %15, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %46)
  %47 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %47, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 56, ptr %14) #5
  br label %48

48:                                               ; preds = %23, %21
  %49 = load i32, ptr %7, align 4
  ret i32 %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { 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 #3 = { "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 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 #5 = { 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 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !10, i64 20}
!18 = !{!12, !6, i64 24}
!19 = !{!12, !6, i64 32}
!20 = !{!12, !10, i64 40}
!21 = !{!12, !10, i64 44}
!22 = !{!12, !13, i64 48}
!23 = !{!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.PrintParams = type { ptr, i32, i32, i32, i32, ptr, ptr, i32, i32, i8, i8 }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [34 x i8], align 1

; 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: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #1

declare i32 @TCOD_set_errorf(ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @vprintf_internal_(ptr noalias noundef, ptr noalias noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @normalize_old_rect_(ptr noalias noundef, i32 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_console_get_height_rect_fmt(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noalias noundef %5, ...) local_unnamed_addr #4 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.PrintParams, align 8
  %12 = alloca [1 x %struct.__va_list_tag], align 16
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  %13 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %14, label %16

14:                                               ; preds = %6
  %15 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, i32 noundef 1470, ptr noundef nonnull @.str.7) #6
  br label %30

16:                                               ; preds = %6
  call void @normalize_old_rect_(ptr noundef nonnull %13, i32 noundef 0, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %10)
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %11) #6
  %17 = call ptr @TCOD_console_validate_(ptr noundef nonnull %13)
  store ptr %17, ptr %11, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %11, i64 8
  %19 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %19, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %11, i64 12
  %21 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %21, ptr %20, align 4, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %11, i64 16
  %23 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %23, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %11, i64 20
  %25 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %25, ptr %24, align 4, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %11, i64 24
  %27 = getelementptr inbounds i8, ptr %11, i64 48
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %26, i8 0, i64 24, i1 false)
  store i8 1, ptr %27, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %11, i64 49
  store i8 1, ptr %28, align 1, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %12) #6
  call void @llvm.va_start.p0(ptr nonnull %12)
  %29 = call i32 @vprintf_internal_(ptr noundef nonnull %11, ptr noundef %5, ptr noundef nonnull %12)
  call void @llvm.va_end.p0(ptr nonnull %12)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %11) #6
  br label %30

30:                                               ; preds = %16, %14
  %.0 = phi i32 [ %29, %16 ], [ -2, %14 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #2 = { 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 #3 = { "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 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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, !11, i64 0}
!10 = !{!"PrintParams", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 44, !12, i64 48, !12, i64 49}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 12}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !6, i64 20}
!17 = !{!10, !12, i64 48}
!18 = !{!10, !12, i64 49}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass