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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_draw_rect_rgb = external hidden unnamed_addr constant [150 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_console_put_rgb(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) #0

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

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

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

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

27:                                               ; preds = %9
  %28 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 94, ptr noundef @.str.2)
  store i32 -2, ptr %10, align 4
  br label %87

29:                                               ; preds = %9
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TCOD_Console, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TCOD_Console, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !15
  call void @clamp_rect_(i32 noundef 0, i32 noundef 0, i32 noundef %32, i32 noundef %35, ptr noundef %12, ptr noundef %13, ptr noundef %14, ptr noundef %15)
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = add nsw i32 %36, %37
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TCOD_Console, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = icmp sle i32 %38, %41
  br i1 %42, label %43, label %52

43:                                               ; preds = %29
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TCOD_Console, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = icmp sle i32 %46, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  br label %53

52:                                               ; preds = %43, %29
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 98, ptr noundef @__PRETTY_FUNCTION__.TCOD_console_draw_rect_rgb) #5
  unreachable

53:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #6
  %54 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %54, ptr %20, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %83, %53
  %56 = load i32, ptr %20, align 4, !tbaa !9
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = add nsw i32 %57, %58
  %60 = icmp slt i32 %56, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %55
  store i32 2, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #6
  br label %86

62:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #6
  %63 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %63, ptr %22, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %79, %62
  %65 = load i32, ptr %22, align 4, !tbaa !9
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = load i32, ptr %14, align 4, !tbaa !9
  %68 = add nsw i32 %66, %67
  %69 = icmp slt i32 %65, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %64
  store i32 5, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #6
  br label %82

71:                                               ; preds = %64
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load i32, ptr %22, align 4, !tbaa !9
  %74 = load i32, ptr %20, align 4, !tbaa !9
  %75 = load i32, ptr %16, align 4, !tbaa !9
  %76 = load ptr, ptr %17, align 8, !tbaa !5
  %77 = load ptr, ptr %18, align 8, !tbaa !5
  %78 = load i32, ptr %19, align 4, !tbaa !9
  call void @TCOD_console_put_rgb(ptr noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75, ptr noundef %76, ptr noundef %77, i32 noundef %78)
  br label %79

79:                                               ; preds = %71
  %80 = load i32, ptr %22, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %22, align 4, !tbaa !9
  br label %64, !llvm.loop !16

82:                                               ; preds = %70
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %20, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %20, align 4, !tbaa !9
  br label %55, !llvm.loop !18

86:                                               ; preds = %61
  store i32 0, ptr %10, align 4
  br label %87

87:                                               ; preds = %86, %27
  %88 = load i32, ptr %10, align 4
  ret i32 %88
}

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

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

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

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 = { 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 #5 = { noreturn nounwind }
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 = !{!"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, !10, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_draw_rect_rgb = external hidden unnamed_addr constant [150 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @TCOD_console_put_rgb(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @TCOD_console_draw_rect_rgb(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %1, ptr %10, align 4, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !5
  store i32 %4, ptr %13, align 4, !tbaa !5
  %14 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %15, label %17

15:                                               ; preds = %9
  %16 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 94, ptr noundef nonnull @.str.2) #4
  br label %.loopexit

17:                                               ; preds = %9
  %18 = load i32, ptr %14, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %14, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !14
  call void @clamp_rect_(i32 noundef 0, i32 noundef 0, i32 noundef %18, i32 noundef %20, ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull %12, ptr noundef nonnull %13)
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = load i32, ptr %12, align 4, !tbaa !5
  %23 = add nsw i32 %22, %21
  %24 = load i32, ptr %14, align 8, !tbaa !9
  %.not20 = icmp sgt i32 %23, %24
  br i1 %.not20, label %31, label %25

25:                                               ; preds = %17
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = load i32, ptr %13, align 4, !tbaa !5
  %28 = add nsw i32 %27, %26
  %29 = load i32, ptr %19, align 4, !tbaa !14
  %.not21 = icmp sgt i32 %28, %29
  br i1 %.not21, label %31, label %.preheader

.preheader:                                       ; preds = %25
  %30 = icmp sgt i32 %27, 0
  br i1 %30, label %.lr.ph24, label %.loopexit

31:                                               ; preds = %25, %17
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 98, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_console_draw_rect_rgb) #5
  unreachable

.lr.ph24:                                         ; preds = %.preheader, %._crit_edge
  %32 = phi i32 [ %37, %._crit_edge ], [ %27, %.preheader ]
  %33 = phi i32 [ %38, %._crit_edge ], [ %26, %.preheader ]
  %34 = phi i32 [ %39, %._crit_edge ], [ %22, %.preheader ]
  %35 = phi i32 [ %40, %._crit_edge ], [ %21, %.preheader ]
  %.01723 = phi i32 [ %41, %._crit_edge ], [ %26, %.preheader ]
  %36 = icmp sgt i32 %34, 0
  br i1 %36, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %11, align 4, !tbaa !5
  %.pre25 = load i32, ptr %13, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph24
  %37 = phi i32 [ %.pre25, %._crit_edge.loopexit ], [ %32, %.lr.ph24 ]
  %38 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %33, %.lr.ph24 ]
  %39 = phi i32 [ %46, %._crit_edge.loopexit ], [ %34, %.lr.ph24 ]
  %40 = phi i32 [ %45, %._crit_edge.loopexit ], [ %35, %.lr.ph24 ]
  %41 = add nsw i32 %.01723, 1
  %42 = add nsw i32 %37, %38
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %.lr.ph24, label %.loopexit, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %.022 = phi i32 [ %44, %.lr.ph ], [ %35, %.lr.ph24 ]
  call void @TCOD_console_put_rgb(ptr noundef nonnull %14, i32 noundef %.022, i32 noundef %.01723, i32 noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %8)
  %44 = add nsw i32 %.022, 1
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = add nsw i32 %46, %45
  %48 = icmp slt i32 %44, %47
  br i1 %48, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %._crit_edge, %.preheader, %15
  %.018 = phi i32 [ -2, %15 ], [ 0, %.preheader ], [ 0, %._crit_edge ]
  ret i32 %.018
}

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

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

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

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 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!10, !6, i64 0}
!10 = !{!"TCOD_Console", !6, i64 0, !6, i64 4, !11, i64 8, !6, i64 16, !6, i64 20, !12, i64 24, !12, i64 27, !13, i64 30, !12, i64 31, !6, i64 36, !11, i64 40, !11, i64 48}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !6, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass