; 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_ColorRGB = type { i8, i8, i8 }

@.str = external hidden unnamed_addr constant [52 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_set_color_control = external hidden unnamed_addr constant [80 x i8], align 1
@color_control_fore = external hidden global [5 x %struct.TCOD_ColorRGB], align 1
@color_control_back = external hidden global [5 x %struct.TCOD_ColorRGB], align 1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_set_color_control(i32 noundef %0, i24 %1, i24 %2) #0 {
  %4 = alloca %struct.TCOD_ColorRGB, align 1
  %5 = alloca %struct.TCOD_ColorRGB, align 1
  %6 = alloca i32, align 4
  store i24 %1, ptr %4, align 1
  store i24 %2, ptr %5, align 1
  store i32 %0, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp uge i32 %7, 1
  br i1 %8, label %9, label %13

9:                                                ; preds = %3
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp ule i32 %10, 5
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  br label %14

13:                                               ; preds = %9, %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 65, ptr noundef @__PRETTY_FUNCTION__.TCOD_console_set_color_control) #3
  unreachable

14:                                               ; preds = %12
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sub i32 %15, 1
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [5 x %struct.TCOD_ColorRGB], ptr @color_control_fore, i64 0, i64 %17
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %4, i64 3, i1 false), !tbaa.struct !9
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sub i32 %19, 1
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [5 x %struct.TCOD_ColorRGB], ptr @color_control_back, i64 0, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr align 1 %5, i64 3, i1 false), !tbaa.struct !9
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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) #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 = { noreturn 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn 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 = !{i64 0, i64 1, !10, i64 1, i64 1, !10, i64 2, i64 1, !10}
!10 = !{!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"

%struct.TCOD_ColorRGB = type { i8, i8, i8 }

@.str = external hidden unnamed_addr constant [52 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_set_color_control = external hidden unnamed_addr constant [80 x i8], align 1
@color_control_fore = external hidden local_unnamed_addr global [5 x %struct.TCOD_ColorRGB], align 1
@color_control_back = external hidden local_unnamed_addr global [5 x %struct.TCOD_ColorRGB], align 1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_set_color_control(i32 noundef %0, i24 %1, i24 %2) local_unnamed_addr #0 {
  %4 = add i32 %0, -1
  %or.cond = icmp ult i32 %4, 5
  br i1 %or.cond, label %6, label %5

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 65, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_console_set_color_control) #2
  unreachable

6:                                                ; preds = %3
  %7 = zext nneg i32 %4 to i64
  %8 = getelementptr inbounds [5 x %struct.TCOD_ColorRGB], ptr @color_control_fore, i64 0, i64 %7
  store i24 %1, ptr %8, align 1
  %9 = getelementptr inbounds [5 x %struct.TCOD_ColorRGB], ptr @color_control_back, i64 0, i64 %7
  store i24 %2, ptr %9, align 1
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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 = { noreturn 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 #2 = { noreturn 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)"}


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