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

; 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.docctl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i32, i32, i32, [26 x i32] }
%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] }

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

; Function Attrs: nounwind uwtable
declare dso_local void @skip(i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @phead() #0 {
  %1 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 1), align 4, !tbaa !5
  store i32 %1, ptr @pg, align 4, !tbaa !10
  %2 = load i32, ptr @pg, align 4, !tbaa !10
  %3 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 10), align 4, !tbaa !11
  %4 = icmp sge i32 %2, %3
  br i1 %4, label %5, label %10

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

9:                                                ; preds = %5
  store i32 1, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 14), align 4, !tbaa !13
  br label %11

10:                                               ; preds = %5, %0
  store i32 0, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 14), align 4, !tbaa !13
  br label %11

11:                                               ; preds = %10, %9
  %12 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 1), align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 1), align 4, !tbaa !5
  %14 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 14), align 4, !tbaa !13
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %32

16:                                               ; preds = %11
  %17 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 4), align 4, !tbaa !15
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %30

19:                                               ; preds = %16
  %20 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 4), align 4, !tbaa !15
  %21 = sub nsw i32 %20, 1
  call void @skip(i32 noundef %21)
  %22 = load i32, ptr @pg, align 4, !tbaa !10
  %23 = srem i32 %22, 2
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = load i32, ptr @pg, align 4, !tbaa !10
  call void @puttl(ptr noundef getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 16), ptr noundef getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 12), i32 noundef %26)
  br label %29

27:                                               ; preds = %19
  %28 = load i32, ptr @pg, align 4, !tbaa !10
  call void @puttl(ptr noundef getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 17), ptr noundef getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 13), i32 noundef %28)
  br label %29

29:                                               ; preds = %27, %25
  br label %30

30:                                               ; preds = %29, %16
  %31 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 5), align 4, !tbaa !16
  call void @skip(i32 noundef %31)
  br label %32

32:                                               ; preds = %30, %11
  %33 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 4), align 4, !tbaa !15
  %34 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 5), align 4, !tbaa !16
  %35 = add nsw i32 %33, %34
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !17
  ret void
}

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

!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 4}
!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 0}
!11 = !{!6, !7, i64 40}
!12 = !{!6, !7, i64 44}
!13 = !{!14, !7, i64 52}
!14 = !{!"docctl", !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 49, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !7, i64 20}
!17 = !{!6, !7, i64 8}


; 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.docctl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i32, i32, i32, [26 x i32] }
%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] }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @phead() local_unnamed_addr #0 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 4), align 4, !tbaa !5
  store i32 %1, ptr @pg, align 4, !tbaa !10
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 40), align 4, !tbaa !11
  %.not = icmp slt i32 %1, %2
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 44), align 4
  %.not2 = icmp sgt i32 %1, %3
  %or.cond = select i1 %.not, i1 true, i1 %.not2
  %4 = add nsw i32 %1, 1
  br i1 %or.cond, label %.critedge, label %5

.critedge:                                        ; preds = %0
  store i32 0, ptr getelementptr inbounds (i8, ptr @dc, i64 52), align 4, !tbaa !12
  store i32 %4, ptr getelementptr inbounds (i8, ptr @pg, i64 4), align 4, !tbaa !5
  br label %17

5:                                                ; preds = %0
  store i32 1, ptr getelementptr inbounds (i8, ptr @dc, i64 52), align 4, !tbaa !12
  store i32 %4, ptr getelementptr inbounds (i8, ptr @pg, i64 4), align 4, !tbaa !5
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 16), align 4, !tbaa !14
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %8, label %15

8:                                                ; preds = %5
  %9 = add nsw i32 %6, -1
  tail call void @skip(i32 noundef %9)
  %10 = load i32, ptr @pg, align 4, !tbaa !10
  %11 = and i32 %10, 1
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  tail call void @puttl(ptr noundef nonnull getelementptr inbounds (i8, ptr @pg, i64 80), ptr noundef nonnull getelementptr inbounds (i8, ptr @pg, i64 48), i32 noundef %10)
  br label %15

14:                                               ; preds = %8
  tail call void @puttl(ptr noundef nonnull getelementptr inbounds (i8, ptr @pg, i64 200080), ptr noundef nonnull getelementptr inbounds (i8, ptr @pg, i64 56), i32 noundef %10)
  br label %15

15:                                               ; preds = %13, %14, %5
  %16 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 20), align 4, !tbaa !15
  tail call void @skip(i32 noundef %16)
  br label %17

17:                                               ; preds = %.critedge, %15
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 16), align 4, !tbaa !14
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 20), align 4, !tbaa !15
  %20 = add i32 %18, 1
  %21 = add i32 %20, %19
  store i32 %21, ptr getelementptr inbounds (i8, ptr @pg, i64 8), align 4, !tbaa !16
  ret void
}

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

!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 4}
!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 0}
!11 = !{!6, !7, i64 40}
!12 = !{!13, !7, i64 52}
!13 = !{!"docctl", !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 49, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 20}
!16 = !{!6, !7, i64 8}


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