; LLVM IR from libtcod/libtcod :: src/libtcod (namegen_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"

@.str.3 = external hidden unnamed_addr constant [2 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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 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
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @namegen_populate_list(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #8
  store i64 %14, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %15 = load i64, ptr %7, align 8, !tbaa !11
  %16 = add i64 %15, 1
  store i64 %16, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %17 = load i64, ptr %8, align 8, !tbaa !11
  %18 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %17) #9
  store ptr %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %141, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %10, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  store ptr %22, ptr %11, align 8, !tbaa !5
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = sext i8 %24 to i32
  %26 = icmp sge i32 %25, 97
  br i1 %26, label %27, label %32

27:                                               ; preds = %19
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = sext i8 %29 to i32
  %31 = icmp sle i32 %30, 122
  br i1 %31, label %52, label %32

32:                                               ; preds = %27, %19
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = sext i8 %34 to i32
  %36 = icmp sge i32 %35, 65
  br i1 %36, label %37, label %42

37:                                               ; preds = %32
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = icmp sle i32 %40, 90
  br i1 %41, label %52, label %42

42:                                               ; preds = %37, %32
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 39
  br i1 %46, label %52, label %47

47:                                               ; preds = %42
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 45
  br i1 %51, label %52, label %56

52:                                               ; preds = %47, %42, %37, %27
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = call ptr @strncat(ptr noundef %53, ptr noundef %54, i64 noundef 1) #7
  br label %140

56:                                               ; preds = %47
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load i8, ptr %57, align 1, !tbaa !13
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 47
  br i1 %60, label %61, label %79

61:                                               ; preds = %56
  %62 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %63 = trunc i8 %62 to i1
  %64 = zext i1 %63 to i32
  %65 = icmp eq i32 %64, 1
  br i1 %65, label %66, label %71

66:                                               ; preds = %61
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %11, align 8, !tbaa !5
  %70 = call ptr @strncat(ptr noundef %67, ptr noundef %68, i64 noundef 2) #7
  br label %76

71:                                               ; preds = %61
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i32 1
  store ptr %74, ptr %11, align 8, !tbaa !5
  %75 = call ptr @strncat(ptr noundef %72, ptr noundef %74, i64 noundef 1) #7
  br label %76

76:                                               ; preds = %71, %66
  %77 = load i64, ptr %10, align 8, !tbaa !11
  %78 = add i64 %77, 1
  store i64 %78, ptr %10, align 8, !tbaa !11
  br label %139

79:                                               ; preds = %56
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load i8, ptr %80, align 1, !tbaa !13
  %82 = sext i8 %81 to i32
  %83 = icmp eq i32 %82, 95
  br i1 %83, label %84, label %97

84:                                               ; preds = %79
  %85 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %86 = trunc i8 %85 to i1
  %87 = zext i1 %86 to i32
  %88 = icmp eq i32 %87, 1
  br i1 %88, label %89, label %93

89:                                               ; preds = %84
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = call ptr @strncat(ptr noundef %90, ptr noundef %91, i64 noundef 1) #7
  br label %96

93:                                               ; preds = %84
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = call ptr @strcat(ptr noundef %94, ptr noundef @.str.3) #7
  br label %96

96:                                               ; preds = %93, %89
  br label %138

97:                                               ; preds = %79
  %98 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %99 = trunc i8 %98 to i1
  %100 = zext i1 %99 to i32
  %101 = icmp eq i32 %100, 1
  br i1 %101, label %102, label %126

102:                                              ; preds = %97
  %103 = load ptr, ptr %11, align 8, !tbaa !5
  %104 = load i8, ptr %103, align 1, !tbaa !13
  %105 = sext i8 %104 to i32
  %106 = icmp eq i32 %105, 36
  br i1 %106, label %122, label %107

107:                                              ; preds = %102
  %108 = load ptr, ptr %11, align 8, !tbaa !5
  %109 = load i8, ptr %108, align 1, !tbaa !13
  %110 = sext i8 %109 to i32
  %111 = icmp eq i32 %110, 37
  br i1 %111, label %122, label %112

112:                                              ; preds = %107
  %113 = load ptr, ptr %11, align 8, !tbaa !5
  %114 = load i8, ptr %113, align 1, !tbaa !13
  %115 = sext i8 %114 to i32
  %116 = icmp sge i32 %115, 48
  br i1 %116, label %117, label %126

117:                                              ; preds = %112
  %118 = load ptr, ptr %11, align 8, !tbaa !5
  %119 = load i8, ptr %118, align 1, !tbaa !13
  %120 = sext i8 %119 to i32
  %121 = icmp sle i32 %120, 57
  br i1 %121, label %122, label %126

122:                                              ; preds = %117, %107, %102
  %123 = load ptr, ptr %9, align 8, !tbaa !5
  %124 = load ptr, ptr %11, align 8, !tbaa !5
  %125 = call ptr @strncat(ptr noundef %123, ptr noundef %124, i64 noundef 1) #7
  br label %137

126:                                              ; preds = %117, %112, %97
  %127 = load ptr, ptr %9, align 8, !tbaa !5
  %128 = call i64 @strlen(ptr noundef %127) #8
  %129 = icmp ugt i64 %128, 0
  br i1 %129, label %130, label %136

130:                                              ; preds = %126
  %131 = load ptr, ptr %5, align 8, !tbaa !5
  %132 = load ptr, ptr %9, align 8, !tbaa !5
  %133 = call ptr @TCOD_strdup(ptr noundef %132)
  call void @TCOD_list_push(ptr noundef %131, ptr noundef %133)
  %134 = load ptr, ptr %9, align 8, !tbaa !5
  %135 = load i64, ptr %8, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 1 %134, i8 0, i64 %135, i1 false)
  br label %136

136:                                              ; preds = %130, %126
  br label %137

137:                                              ; preds = %136, %122
  br label %138

138:                                              ; preds = %137, %96
  br label %139

139:                                              ; preds = %138, %76
  br label %140

140:                                              ; preds = %139, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %141

141:                                              ; preds = %140
  %142 = load i64, ptr %10, align 8, !tbaa !11
  %143 = add i64 %142, 1
  store i64 %143, ptr %10, align 8, !tbaa !11
  %144 = load i64, ptr %7, align 8, !tbaa !11
  %145 = icmp ule i64 %143, %144
  br i1 %145, label %19, label %146, !llvm.loop !16

146:                                              ; preds = %141
  %147 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %147) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

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

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

declare void @TCOD_list_push(ptr noundef, ptr noundef) #5

declare ptr @TCOD_strdup(ptr noundef) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #4 = { nounwind willreturn memory(read) "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 = { "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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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.3 = external hidden unnamed_addr constant [2 x i8], align 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 #0

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

; Function Attrs: nounwind uwtable
define dso_local void @namegen_populate_list(ptr nocapture noundef readonly %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %5 = add i64 %4, 1
  %6 = tail call noalias ptr @calloc(i64 noundef 1, i64 noundef %5) #8
  br label %7

7:                                                ; preds = %37, %3
  %.0 = phi i64 [ 0, %3 ], [ %38, %37 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %.0
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = and i8 %9, -33
  %11 = add i8 %10, -65
  %or.cond46 = icmp ult i8 %11, 26
  br i1 %or.cond46, label %13, label %12

12:                                               ; preds = %7
  switch i8 %9, label %28 [
    i8 39, label %13
    i8 45, label %13
    i8 47, label %15
    i8 95, label %23
  ]

13:                                               ; preds = %12, %12, %7
  %14 = tail call ptr @strncat(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %8, i64 noundef 1) #9
  br label %37

15:                                               ; preds = %12
  br i1 %2, label %16, label %18

16:                                               ; preds = %15
  %17 = tail call ptr @strncat(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %8, i64 noundef 2) #9
  br label %21

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %8, i64 1
  %20 = tail call ptr @strncat(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %19, i64 noundef 1) #9
  br label %21

21:                                               ; preds = %18, %16
  %22 = add i64 %.0, 1
  br label %37

23:                                               ; preds = %12
  br i1 %2, label %24, label %26

24:                                               ; preds = %23
  %25 = tail call ptr @strncat(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %8, i64 noundef 1) #9
  br label %37

26:                                               ; preds = %23
  %27 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str.3) #9
  br label %37

28:                                               ; preds = %12
  br i1 %2, label %29, label %34

29:                                               ; preds = %28
  %30 = and i8 %9, -2
  %switch = icmp eq i8 %30, 36
  %31 = add i8 %9, -48
  %or.cond45 = icmp ult i8 %31, 10
  %or.cond47 = or i1 %switch, %or.cond45
  br i1 %or.cond47, label %32, label %34

32:                                               ; preds = %29
  %33 = tail call ptr @strncat(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %8, i64 noundef 1) #9
  br label %37

34:                                               ; preds = %29, %28
  %char0 = load i8, ptr %6, align 1
  %.not = icmp eq i8 %char0, 0
  br i1 %.not, label %37, label %35

35:                                               ; preds = %34
  %36 = tail call ptr @TCOD_strdup(ptr noundef nonnull %6) #9
  tail call void @TCOD_list_push(ptr noundef %1, ptr noundef %36) #9
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %6, i8 0, i64 %5, i1 false)
  br label %37

37:                                               ; preds = %21, %32, %35, %34, %24, %26, %13
  %.1 = phi i64 [ %.0, %13 ], [ %22, %21 ], [ %.0, %24 ], [ %.0, %26 ], [ %.0, %32 ], [ %.0, %35 ], [ %.0, %34 ]
  %38 = add i64 %.1, 1
  %.not43 = icmp ugt i64 %38, %4
  br i1 %.not43, label %39, label %7, !llvm.loop !8

39:                                               ; preds = %37
  tail call void @free(ptr noundef %6) #9
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

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

declare void @TCOD_list_push(ptr noundef, ptr noundef) local_unnamed_addr #5

declare ptr @TCOD_strdup(ptr noundef) local_unnamed_addr #5

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

attributes #0 = { 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 #1 = { 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 #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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #5 = { "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 #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind allocsize(0,1) }
attributes #9 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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