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

@.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
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 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) #0

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TCOD_console_printn_rect(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_console_printn_frame(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i64 noundef %5, ptr noalias noundef %6, ptr noalias noundef %7, ptr noalias noundef %8, i32 noundef %9, i1 noundef zeroext %10) #4 {
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  %23 = alloca i8, align 1
  %24 = alloca ptr, align 8
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  store ptr %0, ptr %13, align 8, !tbaa !5
  store i32 %1, ptr %14, align 4, !tbaa !9
  store i32 %2, ptr %15, align 4, !tbaa !9
  store i32 %3, ptr %16, align 4, !tbaa !9
  store i32 %4, ptr %17, align 4, !tbaa !9
  store i64 %5, ptr %18, align 8, !tbaa !11
  store ptr %6, ptr %19, align 8, !tbaa !5
  store ptr %7, ptr %20, align 8, !tbaa !5
  store ptr %8, ptr %21, align 8, !tbaa !5
  store i32 %9, ptr %22, align 4, !tbaa !9
  %27 = zext i1 %10 to i8
  store i8 %27, ptr %23, align 1, !tbaa !13
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  %29 = call ptr @TCOD_console_validate_(ptr noundef %28)
  store ptr %29, ptr %13, align 8, !tbaa !5
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %34, label %32

32:                                               ; preds = %11
  %33 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 1328, ptr noundef @.str.7)
  store i32 -2, ptr %12, align 4
  br label %91

34:                                               ; preds = %11
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = load i32, ptr %14, align 4, !tbaa !9
  %37 = load i32, ptr %15, align 4, !tbaa !9
  %38 = load i32, ptr %16, align 4, !tbaa !9
  %39 = load i32, ptr %17, align 4, !tbaa !9
  %40 = load ptr, ptr %20, align 8, !tbaa !5
  %41 = load ptr, ptr %21, align 8, !tbaa !5
  %42 = load i32, ptr %22, align 4, !tbaa !9
  %43 = load i8, ptr %23, align 1, !tbaa !13, !range !15, !noundef !16
  %44 = trunc i8 %43 to i1
  %45 = call i32 @TCOD_console_draw_frame_rgb(ptr noundef %35, i32 noundef %36, i32 noundef %37, i32 noundef %38, i32 noundef %39, ptr noundef null, ptr noundef %40, ptr noundef %41, i32 noundef %42, i1 noundef zeroext %44)
  %46 = load i64, ptr %18, align 8, !tbaa !11
  %47 = icmp ugt i64 %46, 0
  br i1 %47, label %48, label %90

48:                                               ; preds = %34
  %49 = load ptr, ptr %19, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %90

51:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #7
  %52 = load i64, ptr %18, align 8, !tbaa !11
  %53 = add i64 %52, 2
  %54 = call noalias ptr @malloc(i64 noundef %53) #8
  store ptr %54, ptr %24, align 8, !tbaa !5
  %55 = load ptr, ptr %24, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %59, label %57

57:                                               ; preds = %51
  %58 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 1335, ptr noundef @.str.8)
  store i32 -3, ptr %12, align 4
  store i32 1, ptr %25, align 4
  br label %87

59:                                               ; preds = %51
  %60 = load ptr, ptr %24, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 1
  %62 = load ptr, ptr %19, align 8, !tbaa !5
  %63 = load i64, ptr %18, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %61, ptr align 1 %62, i64 %63, i1 false)
  %64 = load ptr, ptr %24, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 0
  store i8 32, ptr %65, align 1, !tbaa !17
  %66 = load ptr, ptr %24, align 8, !tbaa !5
  %67 = load i64, ptr %18, align 8, !tbaa !11
  %68 = add i64 %67, 1
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  store i8 32, ptr %69, align 1, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #7
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = load i32, ptr %14, align 4, !tbaa !9
  %72 = load i32, ptr %15, align 4, !tbaa !9
  %73 = load i32, ptr %16, align 4, !tbaa !9
  %74 = load i64, ptr %18, align 8, !tbaa !11
  %75 = add i64 %74, 2
  %76 = load ptr, ptr %24, align 8, !tbaa !5
  %77 = load ptr, ptr %21, align 8, !tbaa !5
  %78 = load ptr, ptr %20, align 8, !tbaa !5
  %79 = call i32 @TCOD_console_printn_rect(ptr noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef 1, i64 noundef %75, ptr noundef %76, ptr noundef %77, ptr noundef %78, i32 noundef 1, i32 noundef 2)
  store i32 %79, ptr %26, align 4, !tbaa !9
  %80 = load ptr, ptr %24, align 8, !tbaa !5
  call void @free(ptr noundef %80) #7
  %81 = load i32, ptr %26, align 4, !tbaa !9
  %82 = icmp slt i32 %81, 0
  br i1 %82, label %83, label %85

83:                                               ; preds = %59
  %84 = load i32, ptr %26, align 4, !tbaa !9
  store i32 %84, ptr %12, align 4
  store i32 1, ptr %25, align 4
  br label %86

85:                                               ; preds = %59
  store i32 0, ptr %25, align 4
  br label %86

86:                                               ; preds = %85, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #7
  br label %87

87:                                               ; preds = %86, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #7
  %88 = load i32, ptr %25, align 4
  switch i32 %88, label %93 [
    i32 0, label %89
    i32 1, label %91
  ]

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89, %48, %34
  store i32 0, ptr %12, align 4
  br label %91

91:                                               ; preds = %90, %87, %32
  %92 = load i32, ptr %12, align 4
  ret i32 %92

93:                                               ; preds = %87
  unreachable
}

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

declare i32 @TCOD_console_draw_frame_rgb(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i1 noundef zeroext) #5

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #6

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

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!7, !7, 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"

@.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
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TCOD_console_printn_rect(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_console_printn_frame(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i64 noundef %5, ptr noalias noundef readonly %6, ptr noalias noundef %7, ptr noalias noundef %8, i32 noundef %9, i1 noundef zeroext %10) local_unnamed_addr #3 {
  %12 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %13, label %15

13:                                               ; preds = %11
  %14 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, i32 noundef 1328, ptr noundef nonnull @.str.7) #7
  br label %.thread

15:                                               ; preds = %11
  %16 = tail call i32 @TCOD_console_draw_frame_rgb(ptr noundef nonnull %12, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef null, ptr noundef %7, ptr noundef %8, i32 noundef %9, i1 noundef zeroext %10) #7
  %17 = icmp ne i64 %5, 0
  %18 = icmp ne ptr %6, null
  %or.cond = and i1 %17, %18
  br i1 %or.cond, label %19, label %.thread

19:                                               ; preds = %15
  %20 = add i64 %5, 2
  %21 = tail call noalias ptr @malloc(i64 noundef %20) #8
  %.not39 = icmp eq ptr %21, null
  br i1 %.not39, label %22, label %24

22:                                               ; preds = %19
  %23 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, i32 noundef 1335, ptr noundef nonnull @.str.8) #7
  br label %.thread

24:                                               ; preds = %19
  %25 = getelementptr inbounds i8, ptr %21, i64 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %25, ptr nonnull align 1 %6, i64 %5, i1 false)
  store i8 32, ptr %21, align 1, !tbaa !5
  %26 = getelementptr i8, ptr %21, i64 %5
  %27 = getelementptr i8, ptr %26, i64 1
  store i8 32, ptr %27, align 1, !tbaa !5
  %28 = tail call i32 @TCOD_console_printn_rect(ptr noundef nonnull %12, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 1, i64 noundef %20, ptr noundef nonnull %21, ptr noundef %8, ptr noundef %7, i32 noundef 1, i32 noundef 2)
  tail call void @free(ptr noundef nonnull %21) #7
  %spec.select = tail call i32 @llvm.smin.i32(i32 %28, i32 0)
  br label %.thread

.thread:                                          ; preds = %24, %22, %15, %13
  %.2 = phi i32 [ -2, %13 ], [ 0, %15 ], [ -3, %22 ], [ %spec.select, %24 ]
  ret i32 %.2
}

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

declare i32 @TCOD_console_draw_frame_rgb(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #5

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { 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 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass