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

; 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_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 }
%struct.TCOD_ConsoleTile = type { i32, %struct.TCOD_ColorRGBA, %struct.TCOD_ColorRGBA }
%struct.TCOD_ColorRGBA = type { i8, i8, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_put_rgb(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i24, align 4
  %17 = alloca i24, 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 ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  store i32 %6, ptr %14, align 4, !tbaa !9
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call ptr @TCOD_console_validate_(ptr noundef %18)
  store ptr %19, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %7
  br label %68

23:                                               ; preds = %7
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = call zeroext i1 @TCOD_console_is_index_valid_(ptr noundef %24, i32 noundef %25, i32 noundef %26)
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  br label %68

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TCOD_Console, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = mul nsw i32 %30, %33
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %34, %35
  store i32 %36, ptr %15, align 4, !tbaa !9
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %39, label %48

39:                                               ; preds = %29
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TCOD_Console, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load i32, ptr %15, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %46, i32 0, i32 0
  store i32 %40, ptr %47, align 4, !tbaa !16
  br label %48

48:                                               ; preds = %39, %29
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 1 %55, i64 3, i1 false)
  %56 = load i24, ptr %16, align 4
  call void @TCOD_console_set_char_foreground(ptr noundef %52, i32 noundef %53, i32 noundef %54, i24 %56)
  br label %57

57:                                               ; preds = %51, %48
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %67

60:                                               ; preds = %57
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  %65 = load i32, ptr %14, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 1 %64, i64 3, i1 false)
  %66 = load i24, ptr %17, align 4
  call void @TCOD_console_set_char_background(ptr noundef %61, i32 noundef %62, i32 noundef %63, i24 %66, i32 noundef %65)
  br label %67

67:                                               ; preds = %60, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %68

68:                                               ; preds = %67, %28, %22
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @TCOD_console_is_index_valid_(ptr noundef, i32 noundef, i32 noundef) #1

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

declare void @TCOD_console_set_char_foreground(ptr noundef, i32 noundef, i32 noundef, i24) #3

; 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) #4

declare void @TCOD_console_set_char_background(ptr noundef, i32 noundef, i32 noundef, i24, i32 noundef) #3

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

attributes #0 = { 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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!12 = !{!"TCOD_Console", !10, i64 0, !10, i64 4, !6, i64 8, !10, i64 16, !10, i64 20, !13, i64 24, !13, i64 27, !14, i64 30, !13, i64 31, !10, i64 36, !6, i64 40, !6, i64 48}
!13 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"TCOD_ConsoleTile", !10, i64 0, !18, i64 4, !18, i64 8}
!18 = !{!"TCOD_ColorRGBA", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}


; 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: nounwind uwtable
define dso_local void @TCOD_console_put_rgb(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef readonly %4, ptr noundef readonly %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %25, label %9

9:                                                ; preds = %7
  %10 = tail call zeroext i1 @TCOD_console_is_index_valid_(ptr noundef nonnull %8, i32 noundef %1, i32 noundef %2)
  br i1 %10, label %11, label %25

11:                                               ; preds = %9
  %12 = icmp sgt i32 %3, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %11
  %14 = load i32, ptr %8, align 8, !tbaa !5
  %15 = mul nsw i32 %14, %2
  %16 = add nsw i32 %15, %1
  %17 = getelementptr inbounds i8, ptr %8, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = sext i32 %16 to i64
  %20 = getelementptr inbounds %struct.TCOD_ConsoleTile, ptr %18, i64 %19
  store i32 %3, ptr %20, align 4, !tbaa !14
  br label %21

21:                                               ; preds = %13, %11
  %.not28 = icmp eq ptr %4, null
  br i1 %.not28, label %23, label %22

22:                                               ; preds = %21
  %.0.copyload1 = load i24, ptr %4, align 1
  tail call void @TCOD_console_set_char_foreground(ptr noundef nonnull %8, i32 noundef %1, i32 noundef %2, i24 %.0.copyload1) #3
  br label %23

23:                                               ; preds = %22, %21
  %.not29 = icmp eq ptr %5, null
  br i1 %.not29, label %25, label %24

24:                                               ; preds = %23
  %.0.copyload = load i24, ptr %5, align 1
  tail call void @TCOD_console_set_char_background(ptr noundef nonnull %8, i32 noundef %1, i32 noundef %2, i24 %.0.copyload, i32 noundef %6) #3
  br label %25

25:                                               ; preds = %23, %24, %9, %7
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @TCOD_console_is_index_valid_(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @TCOD_console_set_char_foreground(ptr noundef, i32 noundef, i32 noundef, i24) local_unnamed_addr #2

declare void @TCOD_console_set_char_background(ptr noundef, i32 noundef, i32 noundef, i24, i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 = { 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 = { "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, !7, i64 0}
!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, !10, i64 8}
!14 = !{!15, !7, i64 0}
!15 = !{!"TCOD_ConsoleTile", !7, i64 0, !16, i64 4, !16, i64 8}
!16 = !{!"TCOD_ColorRGBA", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3}


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