; LLVM IR from jovanlanik/wip :: dungeon.d/src (d_text)

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

; Function Attrs: nounwind uwtable
declare dso_local void @drawChar(i8 noundef signext, i32 noundef, i32 noundef, i32 noundef, i32 noundef, float noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @drawStr(i32 noundef %0, i32 noundef %1, float noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %63, %27, %4
  %13 = load ptr, ptr %8, align 8, !tbaa !11
  %14 = load i32, ptr %9, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !13
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %68

20:                                               ; preds = %12
  %21 = load ptr, ptr %8, align 8, !tbaa !11
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = sext i8 %25 to i32
  switch i32 %26, label %32 [
    i32 10, label %27
  ]

27:                                               ; preds = %20
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %11, align 4, !tbaa !5
  br label %12, !llvm.loop !14

32:                                               ; preds = %20
  %33 = call ptr @__ctype_b_loc() #4
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %8, align 8, !tbaa !11
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i16, ptr %34, i64 %41
  %43 = load i16, ptr %42, align 2, !tbaa !16
  %44 = zext i16 %43 to i32
  %45 = and i32 %44, 16384
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %54

47:                                               ; preds = %32
  %48 = load ptr, ptr %8, align 8, !tbaa !11
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !13
  %53 = sext i8 %52 to i32
  br label %55

54:                                               ; preds = %32
  br label %55

55:                                               ; preds = %54, %47
  %56 = phi i32 [ %53, %47 ], [ 127, %54 ]
  %57 = trunc i32 %56 to i8
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = load float, ptr %7, align 4, !tbaa !9
  call void @drawChar(i8 noundef signext %57, i32 noundef %58, i32 noundef %59, i32 noundef %60, i32 noundef %61, float noundef %62)
  br label %63

63:                                               ; preds = %55
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %9, align 4, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %10, align 4, !tbaa !5
  br label %12, !llvm.loop !14

68:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(none) "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 willreturn memory(none) }

!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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local void @drawChar(i8 noundef signext, i32 noundef, i32 noundef, i32 noundef, i32 noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @drawStr(i32 noundef %0, i32 noundef %1, float noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  br label %.outer

.outer:                                           ; preds = %9, %4
  %.017.ph = phi i64 [ %10, %9 ], [ 0, %4 ]
  %.0.ph = phi i32 [ %11, %9 ], [ 0, %4 ]
  %sext = shl i64 %.017.ph, 32
  %5 = ashr exact i64 %sext, 32
  br label %6

6:                                                ; preds = %.outer, %12
  %indvars.iv = phi i64 [ %5, %.outer ], [ %indvars.iv.next, %12 ]
  %.016 = phi i32 [ 0, %.outer ], [ %19, %12 ]
  %7 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv
  %8 = load i8, ptr %7, align 1, !tbaa !5
  switch i8 %8, label %12 [
    i8 0, label %20
    i8 10, label %9
  ]

9:                                                ; preds = %6
  %10 = add i64 %indvars.iv, 1
  %11 = add nuw nsw i32 %.0.ph, 1
  br label %.outer, !llvm.loop !8

12:                                               ; preds = %6
  %13 = tail call ptr @__ctype_b_loc() #2
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = sext i8 %8 to i64
  %16 = getelementptr inbounds i16, ptr %14, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !12
  %18 = and i16 %17, 16384
  %.not19 = icmp eq i16 %18, 0
  %spec.select = select i1 %.not19, i8 127, i8 %8
  tail call void @drawChar(i8 noundef signext %spec.select, i32 noundef %0, i32 noundef %1, i32 noundef %.016, i32 noundef %.0.ph, float noundef %2)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %19 = add nuw nsw i32 %.016, 1
  br label %6, !llvm.loop !8

20:                                               ; preds = %6
  ret void
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #1

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 nosync nounwind willreturn memory(none) "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 willreturn memory(none) }

!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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass