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

@orows = external dso_local global i32, align 4
@ocols = external dso_local global i32, align 4
@flags = external dso_local global i64, align 8
@elem = external dso_local global ptr, align 8
@nelem = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @putfile() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = load ptr, ptr @elem, align 8, !tbaa !5
  store ptr %5, ptr %1, align 8, !tbaa !5
  %6 = load i64, ptr @flags, align 8, !tbaa !9
  %7 = and i64 %6, 1
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %9, label %41

9:                                                ; preds = %0
  store i32 0, ptr %2, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %37, %9
  %11 = load i32, ptr %2, align 4, !tbaa !11
  %12 = load i32, ptr @orows, align 4, !tbaa !11
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %40

14:                                               ; preds = %10
  %15 = load i32, ptr %2, align 4, !tbaa !11
  store i32 %15, ptr %3, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %31, %14
  %17 = load i32, ptr %3, align 4, !tbaa !11
  %18 = load i32, ptr @nelem, align 4, !tbaa !11
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %16
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !11
  %27 = load i32, ptr %2, align 4, !tbaa !11
  %28 = sub nsw i32 %26, %27
  %29 = load i32, ptr @orows, align 4, !tbaa !11
  %30 = sdiv i32 %28, %29
  call void @prints(ptr noundef %25, i32 noundef %30)
  br label %31

31:                                               ; preds = %20
  %32 = load i32, ptr @orows, align 4, !tbaa !11
  %33 = load i32, ptr %3, align 4, !tbaa !11
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %3, align 4, !tbaa !11
  br label %16, !llvm.loop !13

35:                                               ; preds = %16
  %36 = call i32 @putchar(i32 noundef 10)
  br label %37

37:                                               ; preds = %35
  %38 = load i32, ptr %2, align 4, !tbaa !11
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !11
  br label %10, !llvm.loop !15

40:                                               ; preds = %10
  br label %74

41:                                               ; preds = %0
  store i32 0, ptr %4, align 4, !tbaa !11
  store i32 0, ptr %2, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %70, %41
  %43 = load i32, ptr %2, align 4, !tbaa !11
  %44 = load i32, ptr @orows, align 4, !tbaa !11
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %46, label %73

46:                                               ; preds = %42
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %63, %46
  %48 = load i32, ptr %3, align 4, !tbaa !11
  %49 = load i32, ptr @ocols, align 4, !tbaa !11
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %68

51:                                               ; preds = %47
  %52 = load i32, ptr %4, align 4, !tbaa !11
  %53 = load i32, ptr @nelem, align 4, !tbaa !11
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %55, label %62

55:                                               ; preds = %51
  %56 = load ptr, ptr %1, align 8, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds ptr, ptr %56, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = load i32, ptr %3, align 4, !tbaa !11
  call void @prints(ptr noundef %60, i32 noundef %61)
  br label %62

62:                                               ; preds = %55, %51
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %3, align 4, !tbaa !11
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %3, align 4, !tbaa !11
  %66 = load i32, ptr %4, align 4, !tbaa !11
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !11
  br label %47, !llvm.loop !16

68:                                               ; preds = %47
  %69 = call i32 @putchar(i32 noundef 10)
  br label %70

70:                                               ; preds = %68
  %71 = load i32, ptr %2, align 4, !tbaa !11
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %2, align 4, !tbaa !11
  br label %42, !llvm.loop !17

73:                                               ; preds = %42
  br label %74

74:                                               ; preds = %73, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

; 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
declare dso_local void @prints(ptr noundef, i32 noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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

@orows = external dso_local local_unnamed_addr global i32, align 4
@ocols = external dso_local local_unnamed_addr global i32, align 4
@flags = external dso_local local_unnamed_addr global i64, align 8
@elem = external dso_local local_unnamed_addr global ptr, align 8
@nelem = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @putfile() local_unnamed_addr #0 {
  %1 = load ptr, ptr @elem, align 8, !tbaa !5
  %2 = load i64, ptr @flags, align 8, !tbaa !9
  %3 = and i64 %2, 1
  %.not = icmp eq i64 %3, 0
  %4 = load i32, ptr @orows, align 4, !tbaa !11
  %5 = icmp sgt i32 %4, 0
  br i1 %.not, label %.preheader21, label %.preheader23

.preheader23:                                     ; preds = %0
  br i1 %5, label %.preheader22, label %.loopexit

.preheader21:                                     ; preds = %0
  br i1 %5, label %.preheader, label %.loopexit

.preheader22:                                     ; preds = %.preheader23, %._crit_edge
  %6 = phi i32 [ %21, %._crit_edge ], [ %4, %.preheader23 ]
  %.01926 = phi i32 [ %20, %._crit_edge ], [ 0, %.preheader23 ]
  %7 = load i32, ptr @nelem, align 4, !tbaa !11
  %8 = icmp slt i32 %.01926, %7
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader22, %.lr.ph
  %9 = phi i32 [ %15, %.lr.ph ], [ %6, %.preheader22 ]
  %.01725 = phi i32 [ %16, %.lr.ph ], [ %.01926, %.preheader22 ]
  %10 = sext i32 %.01725 to i64
  %11 = getelementptr inbounds ptr, ptr %1, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = sub nsw i32 %.01725, %.01926
  %14 = sdiv i32 %13, %9
  tail call void @prints(ptr noundef %12, i32 noundef %14)
  %15 = load i32, ptr @orows, align 4, !tbaa !11
  %16 = add nsw i32 %15, %.01725
  %17 = load i32, ptr @nelem, align 4, !tbaa !11
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.preheader22
  %19 = tail call i32 @putchar(i32 noundef 10)
  %20 = add nuw nsw i32 %.01926, 1
  %21 = load i32, ptr @orows, align 4, !tbaa !11
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %.preheader22, label %.loopexit, !llvm.loop !15

.preheader:                                       ; preds = %.preheader21, %._crit_edge30
  %.032 = phi i32 [ %.1.lcssa, %._crit_edge30 ], [ 0, %.preheader21 ]
  %.12031 = phi i32 [ %40, %._crit_edge30 ], [ 0, %.preheader21 ]
  %23 = load i32, ptr @ocols, align 4, !tbaa !11
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph29.preheader, label %._crit_edge30

.lr.ph29.preheader:                               ; preds = %.preheader
  %25 = sext i32 %.032 to i64
  %.pre35 = load i32, ptr @nelem, align 4, !tbaa !11
  br label %.lr.ph29

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %33
  %26 = phi i32 [ %23, %.lr.ph29.preheader ], [ %34, %33 ]
  %27 = phi i32 [ %.pre35, %.lr.ph29.preheader ], [ %35, %33 ]
  %indvars.iv = phi i64 [ %25, %.lr.ph29.preheader ], [ %indvars.iv.next, %33 ]
  %.11827 = phi i32 [ 0, %.lr.ph29.preheader ], [ %36, %33 ]
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %.lr.ph29
  %31 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  tail call void @prints(ptr noundef %32, i32 noundef %.11827)
  %.pre = load i32, ptr @nelem, align 4, !tbaa !11
  %.pre36 = load i32, ptr @ocols, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %.lr.ph29, %30
  %34 = phi i32 [ %26, %.lr.ph29 ], [ %.pre36, %30 ]
  %35 = phi i32 [ %27, %.lr.ph29 ], [ %.pre, %30 ]
  %36 = add nuw nsw i32 %.11827, 1
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %37 = icmp slt i32 %36, %34
  br i1 %37, label %.lr.ph29, label %._crit_edge30.loopexit, !llvm.loop !16

._crit_edge30.loopexit:                           ; preds = %33
  %38 = trunc nsw i64 %indvars.iv.next to i32
  br label %._crit_edge30

._crit_edge30:                                    ; preds = %._crit_edge30.loopexit, %.preheader
  %.1.lcssa = phi i32 [ %.032, %.preheader ], [ %38, %._crit_edge30.loopexit ]
  %39 = tail call i32 @putchar(i32 noundef 10)
  %40 = add nuw nsw i32 %.12031, 1
  %41 = load i32, ptr @orows, align 4, !tbaa !11
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %.preheader, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %._crit_edge, %._crit_edge30, %.preheader23, %.preheader21
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @prints(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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