; LLVM IR from AngelJumbo/lavat :: lavat (tb_print_ex)

; 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: 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
declare i32 @wcwidth(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @tb_set_cell(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @tb_extend_cell(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tb_print_ex(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %19 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %19, ptr %17, align 4, !tbaa !5
  %20 = load ptr, ptr %12, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %6
  %23 = load ptr, ptr %12, align 8, !tbaa !9
  store i64 0, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %22, %6
  br label %25

25:                                               ; preds = %80, %24
  %26 = load ptr, ptr %13, align 8, !tbaa !9
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %81

29:                                               ; preds = %25
  %30 = load ptr, ptr %13, align 8, !tbaa !9
  %31 = call i32 @tb_utf8_char_to_unicode(ptr noundef %15, ptr noundef %30)
  %32 = load ptr, ptr %13, align 8, !tbaa !9
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  store ptr %34, ptr %13, align 8, !tbaa !9
  %35 = load i32, ptr %15, align 4, !tbaa !5
  %36 = call i32 @wcwidth(i32 noundef %35) #3
  store i32 %36, ptr %16, align 4, !tbaa !5
  %37 = load i32, ptr %16, align 4, !tbaa !5
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %29
  store i32 1, ptr %16, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %39, %29
  %41 = load i32, ptr %16, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %57

43:                                               ; preds = %40
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %17, align 4, !tbaa !5
  %46 = icmp sgt i32 %44, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %43
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = load i32, ptr %15, align 4, !tbaa !5
  %52 = call i32 @tb_extend_cell(i32 noundef %49, i32 noundef %50, i32 noundef %51)
  store i32 %52, ptr %14, align 4, !tbaa !5
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %47
  %55 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %55, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %82

56:                                               ; preds = %47
  br label %68

57:                                               ; preds = %43, %40
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %15, align 4, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = call i32 @tb_set_cell(i32 noundef %58, i32 noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  store i32 %63, ptr %14, align 4, !tbaa !5
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %57
  %66 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %66, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %82

67:                                               ; preds = %57
  br label %68

68:                                               ; preds = %67, %56
  %69 = load i32, ptr %16, align 4, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = add nsw i32 %70, %69
  store i32 %71, ptr %8, align 4, !tbaa !5
  %72 = load ptr, ptr %12, align 8, !tbaa !9
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %80

74:                                               ; preds = %68
  %75 = load i32, ptr %16, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = load ptr, ptr %12, align 8, !tbaa !9
  %78 = load i64, ptr %77, align 8, !tbaa !11
  %79 = add i64 %78, %76
  store i64 %79, ptr %77, align 8, !tbaa !11
  br label %80

80:                                               ; preds = %74, %68
  br label %25, !llvm.loop !14

81:                                               ; preds = %25
  store i32 0, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %82

82:                                               ; preds = %81, %65, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %83 = load i32, ptr %7, align 4
  ret i32 %83
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tb_utf8_char_to_unicode(ptr noundef, ptr noundef) #2

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

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

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

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

; Function Attrs: nounwind
declare i32 @wcwidth(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @tb_set_cell(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @tb_extend_cell(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tb_print_ex(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %8, label %.thread

8:                                                ; preds = %6
  %9 = load i8, ptr %5, align 1, !tbaa !5
  %.not2831 = icmp eq i8 %9, 0
  br i1 %.not2831, label %._crit_edge, label %.lr.ph.split.us

.thread:                                          ; preds = %6
  store i64 0, ptr %4, align 8, !tbaa !8
  %10 = load i8, ptr %5, align 1, !tbaa !5
  %.not283142 = icmp eq i8 %10, 0
  br i1 %.not283142, label %._crit_edge, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %8, %26
  %.02333.us = phi ptr [ %13, %26 ], [ %5, %8 ]
  %.02432.us = phi i32 [ %27, %26 ], [ %0, %8 ]
  %11 = call i32 @tb_utf8_char_to_unicode(ptr noundef nonnull %7, ptr noundef nonnull %.02333.us)
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %.02333.us, i64 %12
  %14 = load i32, ptr %7, align 4, !tbaa !10
  %15 = call i32 @wcwidth(i32 noundef %14) #3
  %16 = icmp slt i32 %15, 0
  %spec.store.select.us = select i1 %16, i32 1, i32 %15
  %17 = icmp eq i32 %spec.store.select.us, 0
  %18 = icmp sgt i32 %.02432.us, %0
  %or.cond.us = select i1 %17, i1 %18, i1 false
  br i1 %or.cond.us, label %22, label %19

19:                                               ; preds = %.lr.ph.split.us
  %20 = load i32, ptr %7, align 4, !tbaa !10
  %21 = call i32 @tb_set_cell(i32 noundef %.02432.us, i32 noundef %1, i32 noundef %20, i32 noundef %2, i32 noundef %3)
  %.not29.us = icmp eq i32 %21, 0
  br i1 %.not29.us, label %26, label %._crit_edge

22:                                               ; preds = %.lr.ph.split.us
  %23 = add nsw i32 %.02432.us, -1
  %24 = load i32, ptr %7, align 4, !tbaa !10
  %25 = call i32 @tb_extend_cell(i32 noundef %23, i32 noundef %1, i32 noundef %24)
  %.not30.us = icmp eq i32 %25, 0
  br i1 %.not30.us, label %26, label %._crit_edge

26:                                               ; preds = %22, %19
  %27 = add nsw i32 %spec.store.select.us, %.02432.us
  %28 = load i8, ptr %13, align 1, !tbaa !5
  %.not28.us = icmp eq i8 %28, 0
  br i1 %.not28.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !12

.lr.ph.split:                                     ; preds = %.thread, %44
  %.02333 = phi ptr [ %31, %44 ], [ %5, %.thread ]
  %.02432 = phi i32 [ %45, %44 ], [ %0, %.thread ]
  %29 = call i32 @tb_utf8_char_to_unicode(ptr noundef nonnull %7, ptr noundef nonnull %.02333)
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %.02333, i64 %30
  %32 = load i32, ptr %7, align 4, !tbaa !10
  %33 = call i32 @wcwidth(i32 noundef %32) #3
  %34 = icmp slt i32 %33, 0
  %spec.store.select = select i1 %34, i32 1, i32 %33
  %35 = icmp eq i32 %spec.store.select, 0
  %36 = icmp sgt i32 %.02432, %0
  %or.cond = select i1 %35, i1 %36, i1 false
  br i1 %or.cond, label %37, label %41

37:                                               ; preds = %.lr.ph.split
  %38 = add nsw i32 %.02432, -1
  %39 = load i32, ptr %7, align 4, !tbaa !10
  %40 = call i32 @tb_extend_cell(i32 noundef %38, i32 noundef %1, i32 noundef %39)
  %.not30 = icmp eq i32 %40, 0
  br i1 %.not30, label %44, label %._crit_edge

41:                                               ; preds = %.lr.ph.split
  %42 = load i32, ptr %7, align 4, !tbaa !10
  %43 = call i32 @tb_set_cell(i32 noundef %.02432, i32 noundef %1, i32 noundef %42, i32 noundef %2, i32 noundef %3)
  %.not29 = icmp eq i32 %43, 0
  br i1 %.not29, label %44, label %._crit_edge

44:                                               ; preds = %41, %37
  %45 = add nsw i32 %spec.store.select, %.02432
  %46 = sext i32 %spec.store.select to i64
  %47 = load i64, ptr %4, align 8, !tbaa !8
  %48 = add i64 %47, %46
  store i64 %48, ptr %4, align 8, !tbaa !8
  %49 = load i8, ptr %31, align 1, !tbaa !5
  %.not28 = icmp eq i8 %49, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph.split, !llvm.loop !12

._crit_edge:                                      ; preds = %37, %41, %44, %22, %19, %26, %.thread, %8
  %.0 = phi i32 [ 0, %8 ], [ 0, %.thread ], [ 0, %26 ], [ %21, %19 ], [ %25, %22 ], [ 0, %44 ], [ %43, %41 ], [ %40, %37 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @tb_utf8_char_to_unicode(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass