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

; 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 }
%struct.TCOD_Console = type { i32, i32, ptr, i32, i32, %struct.TCOD_ColorRGB, %struct.TCOD_ColorRGB, i8, %struct.TCOD_ColorRGB, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [54 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@TCOD_ctx = external global %struct.TCOD_internal_context_t, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @TCOD_console_new(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %13, label %10

10:                                               ; preds = %2
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %10, %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 75, i32 noundef %14, i32 noundef %15)
  store ptr null, ptr %3, align 8
  br label %53

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 56) #5
  store ptr %18, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %23, label %21

21:                                               ; preds = %17
  %22 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 80, ptr noundef @.str.3)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %52

23:                                               ; preds = %17
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.TCOD_Console, ptr %25, i32 0, i32 0
  store i32 %24, ptr %26, align 8, !tbaa !11
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.TCOD_Console, ptr %28, i32 0, i32 1
  store i32 %27, ptr %29, align 4, !tbaa !15
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = mul nsw i32 %30, %31
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.TCOD_Console, ptr %33, i32 0, i32 9
  store i32 %32, ptr %34, align 4, !tbaa !16
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = call zeroext i1 @TCOD_console_init_(ptr noundef %35)
  %37 = load ptr, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 12), align 8, !tbaa !17
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %50

39:                                               ; preds = %23
  %40 = load ptr, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 12), align 8, !tbaa !17
  %41 = getelementptr inbounds %struct.TCOD_Console, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 4, !tbaa !20
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.TCOD_Console, ptr %43, i32 0, i32 4
  store i32 %42, ptr %44, align 4, !tbaa !20
  %45 = load ptr, ptr getelementptr inbounds (%struct.TCOD_internal_context_t, ptr @TCOD_ctx, i32 0, i32 12), align 8, !tbaa !17
  %46 = getelementptr inbounds %struct.TCOD_Console, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 8, !tbaa !21
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.TCOD_Console, ptr %48, i32 0, i32 3
  store i32 %47, ptr %49, align 8, !tbaa !21
  br label %50

50:                                               ; preds = %39, %23
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %51, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %52

52:                                               ; preds = %50, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %53

53:                                               ; preds = %52, %13
  %54 = load ptr, ptr %3, align 8
  ret ptr %54
}

declare i32 @TCOD_set_errorf(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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @TCOD_console_init_(ptr noundef) #0

; 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 = { "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 = { nounwind allocsize(0,1) "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 = { nounwind allocsize(0,1) }

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


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

@.str = external hidden unnamed_addr constant [54 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@TCOD_ctx = external local_unnamed_addr global %struct.TCOD_internal_context_t, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @TCOD_console_new(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = or i32 %1, %0
  %or.cond.not = icmp sgt i32 %3, -1
  br i1 %or.cond.not, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 75, i32 noundef %0, i32 noundef %1) #3
  br label %20

6:                                                ; preds = %2
  %7 = tail call noalias dereferenceable_or_null(56) ptr @calloc(i64 noundef 1, i64 noundef 56) #4
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %10

8:                                                ; preds = %6
  %9 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 80, ptr noundef nonnull @.str.3) #3
  br label %20

10:                                               ; preds = %6
  store i32 %0, ptr %7, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 %1, ptr %11, align 4, !tbaa !13
  %12 = mul nsw i32 %1, %0
  %13 = getelementptr inbounds i8, ptr %7, i64 36
  store i32 %12, ptr %13, align 4, !tbaa !14
  %14 = tail call zeroext i1 @TCOD_console_init_(ptr noundef nonnull %7)
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @TCOD_ctx, i64 1064), align 8, !tbaa !15
  %.not21 = icmp eq ptr %15, null
  br i1 %.not21, label %20, label %16

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %15, i64 16
  %18 = getelementptr inbounds i8, ptr %7, i64 16
  %19 = load <2 x i32>, ptr %17, align 8, !tbaa !18
  store <2 x i32> %19, ptr %18, align 8, !tbaa !18
  br label %20

20:                                               ; preds = %8, %16, %10, %4
  %.1 = phi ptr [ null, %4 ], [ null, %8 ], [ %7, %16 ], [ %7, %10 ]
  ret ptr %.1
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @TCOD_console_init_(ptr noundef) local_unnamed_addr #0

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 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #4 = { nounwind allocsize(0,1) }

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


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