; 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.16 = external hidden unnamed_addr constant [3 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @namegen_word_prune_spaces(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr %4, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %12, %1
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 0
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = sext i8 %9 to i32
  %11 = icmp eq i32 %10, 32
  br i1 %11, label %12, label %18

12:                                               ; preds = %6
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 1
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i64 @strlen(ptr noundef %16) #5
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %13, ptr align 1 %15, i64 %17, i1 false)
  br label %6, !llvm.loop !10

18:                                               ; preds = %6
  br label %19

19:                                               ; preds = %23, %18
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call ptr @strstr(ptr noundef %20, ptr noundef @.str.16) #5
  store ptr %21, ptr %3, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i64 @strlen(ptr noundef %27) #5
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %24, ptr align 1 %26, i64 %28, i1 false)
  br label %19, !llvm.loop !12

29:                                               ; preds = %19
  br label %30

30:                                               ; preds = %39, %29
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i64 @strlen(ptr noundef %32) #5
  %34 = sub i64 %33, 1
  %35 = getelementptr inbounds i8, ptr %31, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 32
  br i1 %38, label %39, label %45

39:                                               ; preds = %30
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = call i64 @strlen(ptr noundef %41) #5
  %43 = sub i64 %42, 1
  %44 = getelementptr inbounds i8, ptr %40, i64 %43
  store i8 0, ptr %44, align 1, !tbaa !9
  br label %30, !llvm.loop !13

45:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


; 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.16 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @namegen_word_prune_spaces(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = icmp eq i8 %2, 32
  br i1 %3, label %.lr.ph, label %.preheader13

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 1
  br label %6

.preheader13:                                     ; preds = %6, %1
  %5 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.16) #3
  %.not14 = icmp eq ptr %5, null
  br i1 %.not14, label %.preheader, label %.lr.ph15

6:                                                ; preds = %.lr.ph, %6
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %0, ptr nonnull align 1 %4, i64 %7, i1 false)
  %8 = load i8, ptr %0, align 1, !tbaa !5
  %9 = icmp eq i8 %8, 32
  br i1 %9, label %6, label %.preheader13, !llvm.loop !8

.preheader:                                       ; preds = %.lr.ph15, %.preheader13
  %invariant.gep = getelementptr i8, ptr %0, i64 -1
  %10 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %gep16 = getelementptr i8, ptr %invariant.gep, i64 %10
  %11 = load i8, ptr %gep16, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 32
  br i1 %12, label %.lr.ph18, label %._crit_edge

.lr.ph15:                                         ; preds = %.preheader13, %.lr.ph15
  %13 = phi ptr [ %16, %.lr.ph15 ], [ %5, %.preheader13 ]
  %14 = getelementptr inbounds i8, ptr %13, i64 1
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %13) #3
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %13, ptr nonnull align 1 %14, i64 %15, i1 false)
  %16 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.16) #3
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.preheader, label %.lr.ph15, !llvm.loop !10

.lr.ph18:                                         ; preds = %.preheader, %.lr.ph18
  %gep17 = phi ptr [ %gep, %.lr.ph18 ], [ %gep16, %.preheader ]
  store i8 0, ptr %gep17, align 1, !tbaa !5
  %17 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %gep = getelementptr i8, ptr %invariant.gep, i64 %17
  %18 = load i8, ptr %gep, align 1, !tbaa !5
  %19 = icmp eq i8 %18, 32
  br i1 %19, label %.lr.ph18, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph18, %.preheader
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { nofree nounwind memory(readwrite, inaccessiblemem: none) 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind willreturn memory(read) }

!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"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass