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

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

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_text_set_properties = external hidden unnamed_addr constant [72 x i8], 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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
define dso_local void @TCOD_text_set_properties(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  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 ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %13, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %11, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

16:                                               ; preds = %5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TCOD_Text, ptr %17, i32 0, i32 15
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  br label %23

22:                                               ; preds = %16, %5
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 149, ptr noundef @__PRETTY_FUNCTION__.TCOD_text_set_properties) #6
  unreachable

23:                                               ; preds = %21
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TCOD_Text, ptr %25, i32 0, i32 5
  store i32 %24, ptr %26, align 4, !tbaa !16
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %23
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = sdiv i32 %30, 2
  br label %33

32:                                               ; preds = %23
  br label %33

33:                                               ; preds = %32, %29
  %34 = phi i32 [ %31, %29 ], [ 0, %32 ]
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TCOD_Text, ptr %35, i32 0, i32 6
  store i32 %34, ptr %36, align 8, !tbaa !17
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TCOD_Text, ptr %38, i32 0, i32 7
  store i32 %37, ptr %39, align 4, !tbaa !18
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TCOD_Text, ptr %40, i32 0, i32 12
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %48

44:                                               ; preds = %33
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TCOD_Text, ptr %45, i32 0, i32 12
  %47 = load ptr, ptr %46, align 8, !tbaa !19
  call void @free(ptr noundef %47) #5
  br label %48

48:                                               ; preds = %44, %33
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call ptr @TCOD_strdup(ptr noundef %52)
  br label %55

54:                                               ; preds = %48
  br label %55

55:                                               ; preds = %54, %51
  %56 = phi ptr [ %53, %51 ], [ null, %54 ]
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TCOD_Text, ptr %57, i32 0, i32 12
  store ptr %56, ptr %58, align 8, !tbaa !19
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TCOD_Text, ptr %59, i32 0, i32 14
  store i32 0, ptr %60, align 4, !tbaa !20
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TCOD_Text, ptr %61, i32 0, i32 13
  store i32 0, ptr %62, align 8, !tbaa !21
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TCOD_Text, ptr %64, i32 0, i32 11
  store i32 %63, ptr %65, align 4, !tbaa !22
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %102

68:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %69, ptr %12, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %98, %68
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = load i8, ptr %71, align 1, !tbaa !23
  %73 = icmp ne i8 %72, 0
  br i1 %73, label %74, label %101

74:                                               ; preds = %70
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TCOD_Text, ptr %75, i32 0, i32 13
  %77 = load i32, ptr %76, align 8, !tbaa !21
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %76, align 8, !tbaa !21
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = load i8, ptr %79, align 1, !tbaa !23
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 10
  br i1 %82, label %91, label %83

83:                                               ; preds = %74
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.TCOD_Text, ptr %84, i32 0, i32 13
  %86 = load i32, ptr %85, align 8, !tbaa !21
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.TCOD_Text, ptr %87, i32 0, i32 2
  %89 = load i32, ptr %88, align 8, !tbaa !24
  %90 = icmp eq i32 %86, %89
  br i1 %90, label %91, label %98

91:                                               ; preds = %83, %74
  %92 = load ptr, ptr %11, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.TCOD_Text, ptr %92, i32 0, i32 13
  store i32 0, ptr %93, align 8, !tbaa !21
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.TCOD_Text, ptr %94, i32 0, i32 14
  %96 = load i32, ptr %95, align 4, !tbaa !20
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %95, align 4, !tbaa !20
  br label %98

98:                                               ; preds = %91, %83
  %99 = load ptr, ptr %12, align 8, !tbaa !5
  %100 = getelementptr inbounds i8, ptr %99, i32 1
  store ptr %100, ptr %12, align 8, !tbaa !5
  br label %70, !llvm.loop !25

101:                                              ; preds = %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %102

102:                                              ; preds = %101, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare ptr @TCOD_strdup(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = { "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 = { nounwind }
attributes #6 = { 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 = !{!"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, !6, i64 64}
!12 = !{!"TCOD_Text", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !6, i64 48, !10, i64 56, !10, i64 60, !6, i64 64, !13, i64 72, !10, i64 76, !10, i64 80, !14, i64 84, !14, i64 87, !15, i64 92, !13, i64 96, !6, i64 104}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!"float", !7, i64 0}
!16 = !{!12, !10, i64 20}
!17 = !{!12, !10, i64 24}
!18 = !{!12, !10, i64 28}
!19 = !{!12, !6, i64 48}
!20 = !{!12, !10, i64 60}
!21 = !{!12, !10, i64 56}
!22 = !{!12, !10, i64 44}
!23 = !{!7, !7, i64 0}
!24 = !{!12, !10, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_text_set_properties = external hidden unnamed_addr constant [72 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_text_set_properties(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %9, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not32 = icmp eq ptr %8, null
  br i1 %.not32, label %9, label %10

9:                                                ; preds = %6, %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 149, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_text_set_properties) #5
  unreachable

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %2, ptr %11, align 4, !tbaa !14
  %12 = icmp sgt i32 %2, 0
  %13 = lshr i32 %2, 1
  %spec.select = select i1 %12, i32 %13, i32 0
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %spec.select, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %1, ptr %15, align 4, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %.not33 = icmp eq ptr %17, null
  br i1 %.not33, label %19, label %18

18:                                               ; preds = %10
  tail call void @free(ptr noundef nonnull %17) #6
  br label %19

19:                                               ; preds = %18, %10
  %.not34 = icmp eq ptr %3, null
  br i1 %.not34, label %.thread, label %21

.thread:                                          ; preds = %19
  %20 = getelementptr inbounds i8, ptr %0, i64 44
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, i8 0, i64 16, i1 false)
  store i32 %4, ptr %20, align 4, !tbaa !18
  br label %.loopexit

21:                                               ; preds = %19
  %22 = tail call ptr @TCOD_strdup(ptr noundef nonnull %3) #6
  store ptr %22, ptr %16, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 0, ptr %23, align 4, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 0, ptr %24, align 8, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %4, ptr %25, align 4, !tbaa !18
  %26 = load i8, ptr %3, align 1, !tbaa !21
  %.not3536 = icmp eq i8 %26, 0
  br i1 %.not3536, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  br label %28

28:                                               ; preds = %.lr.ph, %39
  %29 = phi i32 [ 0, %.lr.ph ], [ %40, %39 ]
  %30 = phi i32 [ 0, %.lr.ph ], [ %41, %39 ]
  %.037 = phi ptr [ %3, %.lr.ph ], [ %42, %39 ]
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %24, align 8, !tbaa !20
  %32 = load i8, ptr %.037, align 1, !tbaa !21
  %33 = icmp eq i8 %32, 10
  br i1 %33, label %37, label %34

34:                                               ; preds = %28
  %35 = load i32, ptr %27, align 8, !tbaa !22
  %36 = icmp eq i32 %31, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %34, %28
  store i32 0, ptr %24, align 8, !tbaa !20
  %38 = add nsw i32 %29, 1
  store i32 %38, ptr %23, align 4, !tbaa !19
  br label %39

39:                                               ; preds = %37, %34
  %40 = phi i32 [ %38, %37 ], [ %29, %34 ]
  %41 = phi i32 [ 0, %37 ], [ %31, %34 ]
  %42 = getelementptr inbounds i8, ptr %.037, i64 1
  %43 = load i8, ptr %42, align 1, !tbaa !21
  %.not35 = icmp eq i8 %43, 0
  br i1 %.not35, label %.loopexit, label %28, !llvm.loop !23

.loopexit:                                        ; preds = %39, %21, %.thread
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

declare ptr @TCOD_strdup(ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 64}
!6 = !{!"TCOD_Text", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !10, i64 48, !7, i64 56, !7, i64 60, !10, i64 64, !11, i64 72, !7, i64 76, !7, i64 80, !12, i64 84, !12, i64 87, !13, i64 92, !11, i64 96, !10, i64 104}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"TCOD_ColorRGB", !8, i64 0, !8, i64 1, !8, i64 2}
!13 = !{!"float", !8, i64 0}
!14 = !{!6, !7, i64 20}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !7, i64 28}
!17 = !{!6, !10, i64 48}
!18 = !{!6, !7, i64 44}
!19 = !{!6, !7, i64 60}
!20 = !{!6, !7, i64 56}
!21 = !{!8, !8, i64 0}
!22 = !{!6, !7, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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