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

; 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 }
%struct.TCOD_key_t = type { i32, i8, [32 x i8], i8, i8, i8, i8, i8, i8, i8, i8 }

@TCOD_black = external constant %struct.TCOD_ColorRGB, 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TCOD_console_flush() #2

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_credits() #2 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.TCOD_key_t, align 4
  %6 = alloca i32, align 4
  %7 = alloca i24, align 4
  %8 = alloca i24, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #4
  store i8 0, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %9 = call i32 @TCOD_console_get_width(ptr noundef null)
  %10 = sdiv i32 %9, 2
  %11 = sub nsw i32 %10, 6
  store i32 %11, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %12 = call i32 @TCOD_console_get_height(ptr noundef null)
  %13 = sdiv i32 %12, 2
  store i32 %13, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 260, ptr %4, align 4, !tbaa !9
  call void @TCOD_sys_save_fps()
  call void @TCOD_sys_set_fps(i32 noundef 25)
  br label %14

14:                                               ; preds = %53, %0
  %15 = load i8, ptr %1, align 1, !tbaa !5, !range !11, !noundef !12
  %16 = trunc i8 %15 to i1
  %17 = xor i1 %16, true
  br i1 %17, label %18, label %54

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #4
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = call zeroext i1 @TCOD_console_credits_render(i32 noundef %19, i32 noundef %20, i1 noundef zeroext false)
  %22 = zext i1 %21 to i8
  store i8 %22, ptr %1, align 1, !tbaa !5
  %23 = call i32 @TCOD_sys_check_for_event(i32 noundef 1, ptr noundef %5, ptr noundef null)
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 260
  br i1 %25, label %26, label %33

26:                                               ; preds = %18
  %27 = getelementptr inbounds %struct.TCOD_key_t, ptr %5, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = sub nsw i32 %31, 10
  store i32 %32, ptr %4, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %30, %26, %18
  %34 = call i32 @TCOD_console_flush()
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 3, ptr %6, align 4
  br label %51

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 260
  br i1 %39, label %40, label %50

40:                                               ; preds = %37
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 10
  store i32 %42, ptr %4, align 4, !tbaa !9
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = trunc i32 %43 to i8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 1 @TCOD_black, i64 3, i1 false)
  %45 = load i24, ptr %7, align 4
  call void @TCOD_console_set_fade(i8 noundef zeroext %44, i24 %45)
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %40
  store i8 1, ptr %1, align 1, !tbaa !5
  br label %49

49:                                               ; preds = %48, %40
  br label %50

50:                                               ; preds = %49, %37
  store i32 0, ptr %6, align 4
  br label %51

51:                                               ; preds = %50, %36
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #4
  %52 = load i32, ptr %6, align 4
  switch i32 %52, label %56 [
    i32 0, label %53
    i32 3, label %54
  ]

53:                                               ; preds = %51
  br label %14, !llvm.loop !15

54:                                               ; preds = %51, %14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 1 @TCOD_black, i64 3, i1 false)
  %55 = load i24, ptr %8, align 4
  call void @TCOD_console_set_fade(i8 noundef zeroext -1, i24 %55)
  call void @TCOD_sys_restore_fps()
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #4
  ret void

56:                                               ; preds = %51
  unreachable
}

declare i32 @TCOD_console_get_width(ptr noundef) #3

declare i32 @TCOD_console_get_height(ptr noundef) #3

declare void @TCOD_sys_save_fps() #3

declare void @TCOD_sys_set_fps(i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @TCOD_console_credits_render(i32 noundef, i32 noundef, i1 noundef zeroext) #2

declare i32 @TCOD_sys_check_for_event(i32 noundef, ptr noundef, ptr noundef) #3

declare void @TCOD_console_set_fade(i8 noundef zeroext, i24) #3

declare void @TCOD_sys_restore_fps() #3

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

!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 = !{!"_Bool", !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 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !10, i64 0}
!14 = !{!"TCOD_key_t", !10, i64 0, !7, i64 4, !7, i64 5, !6, i64 37, !6, i64 38, !6, i64 39, !6, i64 40, !6, i64 41, !6, i64 42, !6, i64 43, !6, i64 44}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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 }
%struct.TCOD_key_t = type { i32, i8, [32 x i8], i8, i8, i8, i8, i8, i8, i8, i8 }

@TCOD_black = external local_unnamed_addr constant %struct.TCOD_ColorRGB, 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: nounwind uwtable
declare dso_local i32 @TCOD_console_flush() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_console_credits() local_unnamed_addr #1 {
  %1 = alloca %struct.TCOD_key_t, align 4
  %2 = tail call i32 @TCOD_console_get_width(ptr noundef null) #3
  %3 = sdiv i32 %2, 2
  %4 = add nsw i32 %3, -6
  %5 = tail call i32 @TCOD_console_get_height(ptr noundef null) #3
  %6 = sdiv i32 %5, 2
  tail call void @TCOD_sys_save_fps() #3
  tail call void @TCOD_sys_set_fps(i32 noundef 25) #3
  %.0.copyload3 = load i24, ptr @TCOD_black, align 1
  br label %.outer

.outer:                                           ; preds = %17, %0
  %.01527.ph = phi i32 [ %18, %17 ], [ 260, %0 ]
  %7 = icmp eq i32 %.01527.ph, 260
  br label %8

8:                                                ; preds = %.outer, %21
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #3
  %9 = call zeroext i1 @TCOD_console_credits_render(i32 noundef %4, i32 noundef %6, i1 noundef zeroext false)
  %10 = call i32 @TCOD_sys_check_for_event(i32 noundef 1, ptr noundef nonnull %1, ptr noundef null) #3
  %11 = load i32, ptr %1, align 4
  %12 = call i32 @TCOD_console_flush()
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %.thread, label %14

.thread:                                          ; preds = %8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #3
  br label %.loopexit

14:                                               ; preds = %8
  %15 = icmp ne i32 %11, 0
  %or.cond = select i1 %7, i1 %15, i1 false
  %spec.select = select i1 %or.cond, i32 250, i32 %.01527.ph
  %16 = icmp slt i32 %spec.select, 260
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = add nsw i32 %spec.select, -10
  %19 = trunc i32 %18 to i8
  call void @TCOD_console_set_fade(i8 noundef zeroext %19, i24 %.0.copyload3) #3
  %20 = icmp eq i32 %18, 0
  %spec.select22 = select i1 %20, i1 true, i1 %9
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #3
  br i1 %spec.select22, label %.loopexit, label %.outer

21:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #3
  br i1 %9, label %.loopexit, label %8

.loopexit:                                        ; preds = %17, %21, %.thread
  call void @TCOD_console_set_fade(i8 noundef zeroext -1, i24 %.0.copyload3) #3
  call void @TCOD_sys_restore_fps() #3
  ret void
}

declare i32 @TCOD_console_get_width(ptr noundef) local_unnamed_addr #2

declare i32 @TCOD_console_get_height(ptr noundef) local_unnamed_addr #2

declare void @TCOD_sys_save_fps() local_unnamed_addr #2

declare void @TCOD_sys_set_fps(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @TCOD_console_credits_render(i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #1

declare i32 @TCOD_sys_check_for_event(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @TCOD_console_set_fade(i8 noundef zeroext, i24) local_unnamed_addr #2

declare void @TCOD_sys_restore_fps() local_unnamed_addr #2

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


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