; 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_internal_context_t = type { i32, i32, i8, i8, i8, i32, i32, i32, [512 x i8], [512 x i8], ptr, ptr, ptr, i32, i8, i32, i32, i32, i32, i32, i32, ptr, %struct.TCOD_ColorRGB, i8, %struct.TCOD_key_t, i8, i8, i8, ptr, ptr }
%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_ctx = external dso_local global %struct.TCOD_internal_context_t, align 8

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_console_set_custom_font(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call ptr @strncpy(ptr noundef getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 8), ptr noundef %12, i64 noundef 511) #4
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = and i32 %14, 11
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = or i32 %18, 1
  store i32 %19, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %17, %4
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = and i32 %21, 2
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i8
  store i8 %24, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 3), align 1, !tbaa !11
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = and i32 %25, 4
  %27 = icmp ne i32 %26, 0
  %28 = zext i1 %27 to i8
  store i8 %28, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 4), align 2, !tbaa !16
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = and i32 %29, 8
  %31 = icmp ne i32 %30, 0
  %32 = zext i1 %31 to i8
  store i8 %32, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 2), align 8, !tbaa !17
  %33 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %33, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 5), align 4, !tbaa !18
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %36, label %42

36:                                               ; preds = %20
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %40, ptr @TCOD_ctx, align 8, !tbaa !19
  %41 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %41, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 1), align 4, !tbaa !20
  br label %49

42:                                               ; preds = %36, %20
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = and i32 %43, 8
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  store i32 32, ptr %8, align 4, !tbaa !9
  store i32 32, ptr @TCOD_ctx, align 8, !tbaa !19
  store i32 8, ptr %9, align 4, !tbaa !9
  store i32 8, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 1), align 4, !tbaa !20
  br label %48

47:                                               ; preds = %42
  store i32 16, ptr %8, align 4, !tbaa !9
  store i32 16, ptr @TCOD_ctx, align 8, !tbaa !19
  store i32 16, ptr %9, align 4, !tbaa !9
  store i32 16, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 1), align 4, !tbaa !20
  br label %48

48:                                               ; preds = %47, %46
  br label %49

49:                                               ; preds = %48, %39
  %50 = load i8, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 2), align 8, !tbaa !17, !range !21, !noundef !22
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  store i8 1, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 3), align 1, !tbaa !11
  br label %53

53:                                               ; preds = %52, %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = call ptr @TCOD_tileset_load(ptr noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef 0, ptr noundef null)
  store ptr %57, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %61, label %60

60:                                               ; preds = %53
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

61:                                               ; preds = %53
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  call void @TCOD_set_default_tileset(ptr noundef %62)
  call void @TCOD_sys_decode_font_()
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %61, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %64 = load i32, ptr %5, align 4
  ret i32 %64
}

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #2

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

declare void @TCOD_set_default_tileset(ptr noundef) #3

declare void @TCOD_sys_decode_font_() #3

attributes #0 = { 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 = { 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 = { "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 = !{!"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, !13, i64 9}
!12 = !{!"TCOD_internal_context_t", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 9, !13, i64 10, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 536, !6, i64 1048, !6, i64 1056, !6, i64 1064, !10, i64 1072, !13, i64 1076, !10, i64 1080, !10, i64 1084, !10, i64 1088, !10, i64 1092, !10, i64 1096, !10, i64 1100, !6, i64 1104, !14, i64 1112, !7, i64 1115, !15, i64 1116, !13, i64 1164, !13, i64 1165, !13, i64 1166, !6, i64 1168, !6, i64 1176}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!"TCOD_key_t", !10, i64 0, !7, i64 4, !7, i64 5, !13, i64 37, !13, i64 38, !13, i64 39, !13, i64 40, !13, i64 41, !13, i64 42, !13, i64 43, !13, i64 44}
!16 = !{!12, !13, i64 10}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !10, i64 12}
!19 = !{!12, !10, i64 0}
!20 = !{!12, !10, i64 4}
!21 = !{i8 0, i8 2}
!22 = !{}


; 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_internal_context_t = type { i32, i32, i8, i8, i8, i32, i32, i32, [512 x i8], [512 x i8], ptr, ptr, ptr, i32, i8, i32, i32, i32, i32, i32, i32, ptr, %struct.TCOD_ColorRGB, i8, %struct.TCOD_key_t, i8, i8, i8, ptr, ptr }
%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_ctx = external dso_local global %struct.TCOD_internal_context_t, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @TCOD_console_set_custom_font(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @TCOD_ctx, i64 24), ptr noundef nonnull dereferenceable(1) %0, i64 noundef 511) #3
  %6 = and i32 %1, 11
  %.not = icmp eq i32 %6, 0
  %7 = zext i1 %.not to i32
  %spec.select = or disjoint i32 %7, %1
  %8 = trunc i32 %spec.select to i8
  %9 = lshr i8 %8, 1
  %10 = and i8 %9, 1
  store i8 %10, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 9), align 1, !tbaa !5
  %11 = lshr i8 %8, 2
  %12 = and i8 %11, 1
  store i8 %12, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 10), align 2, !tbaa !14
  %13 = and i32 %1, 8
  %.lobit = lshr exact i32 %13, 3
  %14 = trunc nuw nsw i32 %.lobit to i8
  store i8 %14, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 8), align 8, !tbaa !15
  store i32 %spec.select, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 12), align 4, !tbaa !16
  %15 = icmp sgt i32 %2, 0
  %16 = icmp sgt i32 %3, 0
  %or.cond = and i1 %15, %16
  br i1 %or.cond, label %18, label %17

17:                                               ; preds = %4
  %.not24 = icmp eq i32 %13, 0
  br i1 %.not24, label %.thread, label %18

.thread:                                          ; preds = %17
  store i32 16, ptr @TCOD_ctx, align 8, !tbaa !17
  store i32 16, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 4), align 4, !tbaa !18
  br label %21

18:                                               ; preds = %17, %4
  %.sink30 = phi i32 [ %2, %4 ], [ 32, %17 ]
  %.sink = phi i32 [ %3, %4 ], [ 8, %17 ]
  store i32 %.sink30, ptr @TCOD_ctx, align 8, !tbaa !17
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 4), align 4, !tbaa !18
  %19 = trunc nuw i32 %.lobit to i1
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  store i8 1, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 9), align 1, !tbaa !5
  br label %21

21:                                               ; preds = %.thread, %20, %18
  %.01829 = phi i32 [ 16, %.thread ], [ %.sink, %20 ], [ %.sink, %18 ]
  %.01928 = phi i32 [ 16, %.thread ], [ %.sink30, %20 ], [ %.sink30, %18 ]
  %22 = tail call ptr @TCOD_tileset_load(ptr noundef %0, i32 noundef %.01928, i32 noundef %.01829, i32 noundef 0, ptr noundef null) #3
  %.not25 = icmp eq ptr %22, null
  br i1 %.not25, label %24, label %23

23:                                               ; preds = %21
  tail call void @TCOD_set_default_tileset(ptr noundef nonnull %22) #3
  tail call void @TCOD_sys_decode_font_() #3
  br label %24

24:                                               ; preds = %21, %23
  %.0 = phi i32 [ 0, %23 ], [ -1, %21 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #1

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

declare void @TCOD_set_default_tileset(ptr noundef) local_unnamed_addr #2

declare void @TCOD_sys_decode_font_() 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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, !10, i64 9}
!6 = !{!"TCOD_internal_context_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9, !10, i64 10, !7, i64 12, !7, i64 16, !7, i64 20, !8, i64 24, !8, i64 536, !11, i64 1048, !11, i64 1056, !11, i64 1064, !7, i64 1072, !10, i64 1076, !7, i64 1080, !7, i64 1084, !7, i64 1088, !7, i64 1092, !7, i64 1096, !7, i64 1100, !11, i64 1104, !12, i64 1112, !8, i64 1115, !13, i64 1116, !10, i64 1164, !10, i64 1165, !10, i64 1166, !11, i64 1168, !11, i64 1176}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"TCOD_ColorRGB", !8, i64 0, !8, i64 1, !8, i64 2}
!13 = !{!"TCOD_key_t", !7, i64 0, !8, i64 4, !8, i64 5, !10, i64 37, !10, i64 38, !10, i64 39, !10, i64 40, !10, i64 41, !10, i64 42, !10, i64 43, !10, i64 44}
!14 = !{!6, !10, i64 10}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 12}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !7, i64 4}


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