; LLVM IR from holzschu/ios_system :: text_cmds/rs (rs)

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

@osep = external dso_local global i8, align 1
@flags = external dso_local global i64, align 8
@colwidths = external dso_local global ptr, align 8

; 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 uwtable
define dso_local void @prints(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %6, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %12, %2
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %6, align 8, !tbaa !5
  br label %8, !llvm.loop !12

15:                                               ; preds = %8
  %16 = load i64, ptr @flags, align 8, !tbaa !14
  %17 = and i64 %16, 16
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  br label %33

20:                                               ; preds = %15
  %21 = load ptr, ptr @colwidths, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i16, ptr %21, i64 %23
  %25 = load i16, ptr %24, align 2, !tbaa !16
  %26 = sext i16 %25 to i64
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = ptrtoint ptr %27 to i64
  %30 = ptrtoint ptr %28 to i64
  %31 = sub i64 %29, %30
  %32 = sub nsw i64 %26, %31
  br label %33

33:                                               ; preds = %20, %19
  %34 = phi i64 [ 1, %19 ], [ %32, %20 ]
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %5, align 4, !tbaa !9
  %36 = load i64, ptr @flags, align 8, !tbaa !14
  %37 = and i64 %36, 512
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %49

39:                                               ; preds = %33
  br label %40

40:                                               ; preds = %44, %39
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr %5, align 4, !tbaa !9
  %43 = icmp sgt i32 %41, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %40
  %45 = load i8, ptr @osep, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = call i32 @putchar(i32 noundef %46)
  br label %40, !llvm.loop !18

48:                                               ; preds = %40
  br label %49

49:                                               ; preds = %48, %33
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %50, ptr %6, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %60, %49
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %63

55:                                               ; preds = %51
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = call i32 @putchar(i32 noundef %58)
  br label %60

60:                                               ; preds = %55
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %6, align 8, !tbaa !5
  br label %51, !llvm.loop !19

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %68, %63
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr %5, align 4, !tbaa !9
  %67 = icmp sgt i32 %65, 0
  br i1 %67, label %68, label %72

68:                                               ; preds = %64
  %69 = load i8, ptr @osep, align 1, !tbaa !11
  %70 = sext i8 %69 to i32
  %71 = call i32 @putchar(i32 noundef %70)
  br label %64, !llvm.loop !20

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

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !13}
!19 = distinct !{!19, !13}
!20 = distinct !{!20, !13}


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

@osep = external dso_local local_unnamed_addr global i8, align 1
@flags = external dso_local local_unnamed_addr global i64, align 8
@colwidths = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local void @prints(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %3, %2
  %.0 = phi ptr [ %0, %2 ], [ %5, %3 ]
  %4 = load i8, ptr %.0, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  %5 = getelementptr inbounds i8, ptr %.0, i64 1
  br i1 %.not, label %6, label %3, !llvm.loop !8

6:                                                ; preds = %3
  %7 = load i64, ptr @flags, align 8, !tbaa !10
  %8 = and i64 %7, 16
  %.not14 = icmp eq i64 %8, 0
  br i1 %.not14, label %9, label %.thread

9:                                                ; preds = %6
  %10 = load ptr, ptr @colwidths, align 8, !tbaa !12
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds i16, ptr %10, i64 %11
  %13 = load i16, ptr %12, align 2, !tbaa !14
  %14 = sext i16 %13 to i64
  %15 = ptrtoint ptr %.0 to i64
  %16 = ptrtoint ptr %0 to i64
  %.neg = sub i64 %16, %15
  %17 = add i64 %.neg, %14
  %18 = trunc i64 %17 to i32
  %19 = and i64 %7, 512
  %.not15 = icmp eq i64 %19, 0
  br i1 %.not15, label %.loopexit, label %.preheader18

.thread:                                          ; preds = %6
  %20 = and i64 %7, 512
  %.not1524 = icmp eq i64 %20, 0
  br i1 %.not1524, label %.loopexit, label %.lr.ph.preheader

.preheader18:                                     ; preds = %9
  %21 = add nsw i32 %18, -1
  %22 = icmp sgt i32 %18, 0
  br i1 %22, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.thread, %.preheader18
  %.ph = phi i32 [ 0, %.thread ], [ %21, %.preheader18 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %23 = phi i32 [ %27, %.lr.ph ], [ %.ph, %.lr.ph.preheader ]
  %24 = load i8, ptr @osep, align 1, !tbaa !5
  %25 = sext i8 %24 to i32
  %26 = tail call i32 @putchar(i32 noundef %25)
  %27 = add nsw i32 %23, -1
  %.not25 = icmp eq i32 %23, 0
  br i1 %.not25, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph, %.thread, %.preheader18, %9
  %.112 = phi i32 [ %18, %9 ], [ %21, %.preheader18 ], [ 1, %.thread ], [ -1, %.lr.ph ]
  %28 = load i8, ptr %0, align 1, !tbaa !5
  %.not1619 = icmp eq i8 %28, 0
  br i1 %.not1619, label %.preheader, label %.lr.ph21

.preheader:                                       ; preds = %.lr.ph21, %.loopexit
  %29 = icmp sgt i32 %.112, 0
  br i1 %29, label %.lr.ph23, label %._crit_edge

.lr.ph21:                                         ; preds = %.loopexit, %.lr.ph21
  %30 = phi i8 [ %34, %.lr.ph21 ], [ %28, %.loopexit ]
  %.120 = phi ptr [ %33, %.lr.ph21 ], [ %0, %.loopexit ]
  %31 = sext i8 %30 to i32
  %32 = tail call i32 @putchar(i32 noundef %31)
  %33 = getelementptr inbounds i8, ptr %.120, i64 1
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %.not16 = icmp eq i8 %34, 0
  br i1 %.not16, label %.preheader, label %.lr.ph21, !llvm.loop !17

.lr.ph23:                                         ; preds = %.preheader, %.lr.ph23
  %.222 = phi i32 [ %35, %.lr.ph23 ], [ %.112, %.preheader ]
  %35 = add nsw i32 %.222, -1
  %36 = load i8, ptr @osep, align 1, !tbaa !5
  %37 = sext i8 %36 to i32
  %38 = tail call i32 @putchar(i32 noundef %37)
  %39 = icmp ugt i32 %.222, 1
  br i1 %39, label %.lr.ph23, label %._crit_edge, !llvm.loop !18

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

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { inlinehint nofree 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" }

!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 = !{!"long", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !6, i64 0}
!16 = distinct !{!16, !9}
!17 = distinct !{!17, !9}
!18 = distinct !{!18, !9}


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