; LLVM IR from freakout42/macrocalc :: mc/nro (nrocmd)

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

%struct.page = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], [2 x i32], [2 x i32], [2 x i32], [200000 x i8], [200000 x i8], [200000 x i8], [200000 x i8] }

@pg = external global %struct.page, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @brek() #0

; Function Attrs: nounwind uwtable
define dso_local void @space(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @brek()
  %3 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %4 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 8), align 4, !tbaa !11
  %5 = icmp sgt i32 %3, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  br label %34

7:                                                ; preds = %1
  %8 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  call void (...) @phead()
  br label %11

11:                                               ; preds = %10, %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 8), align 4, !tbaa !11
  %14 = add nsw i32 %13, 1
  %15 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %16 = sub nsw i32 %14, %15
  %17 = icmp slt i32 %12, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %11
  %19 = load i32, ptr %2, align 4, !tbaa !5
  br label %25

20:                                               ; preds = %11
  %21 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 8), align 4, !tbaa !11
  %22 = add nsw i32 %21, 1
  %23 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %24 = sub nsw i32 %22, %23
  br label %25

25:                                               ; preds = %20, %18
  %26 = phi i32 [ %19, %18 ], [ %24, %20 ]
  call void (i32, ...) @skip(i32 noundef %26)
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %29 = add nsw i32 %28, %27
  store i32 %29, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %30 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !9
  %31 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 8), align 4, !tbaa !11
  %32 = icmp sgt i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %25
  call void (...) @pfoot()
  br label %34

34:                                               ; preds = %33, %25, %6
  ret void
}

declare void @phead(...) #1

declare void @skip(...) #1

declare void @pfoot(...) #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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"page", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 200080, !7, i64 400080, !7, i64 600080}
!11 = !{!10, !6, i64 32}


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

%struct.page = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], [2 x i32], [2 x i32], [2 x i32], [200000 x i8], [200000 x i8], [200000 x i8], [200000 x i8] }

@pg = external local_unnamed_addr global %struct.page, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @brek() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @space(i32 noundef %0) local_unnamed_addr #0 {
  tail call void @brek()
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 8), align 4, !tbaa !5
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 32), align 4, !tbaa !10
  %4 = icmp sgt i32 %2, %3
  br i1 %4, label %18, label %5

5:                                                ; preds = %1
  %6 = icmp eq i32 %2, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void (...) @phead() #3
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 32), align 4, !tbaa !10
  %.pre5 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 8), align 4, !tbaa !5
  br label %8

8:                                                ; preds = %7, %5
  %9 = phi i32 [ %.pre5, %7 ], [ %2, %5 ]
  %10 = phi i32 [ %.pre, %7 ], [ %3, %5 ]
  %11 = add nsw i32 %10, 1
  %12 = sub i32 %11, %9
  %. = tail call i32 @llvm.smin.i32(i32 %12, i32 %0)
  tail call void (i32, ...) @skip(i32 noundef %.) #3
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 8), align 4, !tbaa !5
  %14 = add nsw i32 %13, %0
  store i32 %14, ptr getelementptr inbounds (i8, ptr @pg, i64 8), align 4, !tbaa !5
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 32), align 4, !tbaa !10
  %16 = icmp sgt i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %8
  tail call void (...) @pfoot() #3
  br label %18

18:                                               ; preds = %1, %17, %8
  ret void
}

declare void @phead(...) local_unnamed_addr #1

declare void @skip(...) local_unnamed_addr #1

declare void @pfoot(...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 8}
!6 = !{!"page", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 200080, !8, i64 400080, !8, i64 600080}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass