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

; 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 dso_local global %struct.docctl, align 4
@pg = external dso_local global %struct.page, align 4
@sofile = external dso_local global [4 x ptr], align 16
@pout = 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
declare dso_local i32 @getlin(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @profile() #1 {
  %1 = alloca [200000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 200000, ptr %1) #3
  store i32 0, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  br label %2

2:                                                ; preds = %49, %0
  %3 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  %4 = icmp sge i32 %3, 0
  br i1 %4, label %5, label %52

5:                                                ; preds = %2
  br label %6

6:                                                ; preds = %38, %5
  %7 = getelementptr inbounds [200000 x i8], ptr %1, i64 0, i64 0
  %8 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [4 x ptr], ptr @sofile, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !10
  %12 = call i32 @getlin(ptr noundef %7, ptr noundef %11)
  %13 = icmp ne i32 %12, -1
  br i1 %13, label %14, label %39

14:                                               ; preds = %6
  %15 = getelementptr inbounds [200000 x i8], ptr %1, i64 0, i64 0
  %16 = load i8, ptr %15, align 16, !tbaa !12
  %17 = sext i8 %16 to i32
  %18 = load i8, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 13), align 1, !tbaa !13
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %14
  %22 = getelementptr inbounds [200000 x i8], ptr %1, i64 0, i64 0
  %23 = call i32 (ptr, ...) @comand(ptr noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = getelementptr inbounds [200000 x i8], ptr %1, i64 0, i64 0
  %27 = load ptr, ptr @pout, align 8, !tbaa !10
  call void (ptr, ptr, ...) @putlin(ptr noundef %26, ptr noundef %27)
  br label %28

28:                                               ; preds = %25, %21
  br label %38

29:                                               ; preds = %14
  %30 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 11), align 4, !tbaa !14
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = getelementptr inbounds [200000 x i8], ptr %1, i64 0, i64 0
  %34 = load ptr, ptr @pout, align 8, !tbaa !10
  call void (ptr, ptr, ...) @putlin(ptr noundef %33, ptr noundef %34)
  br label %37

35:                                               ; preds = %29
  %36 = getelementptr inbounds [200000 x i8], ptr %1, i64 0, i64 0
  call void (ptr, ...) @text(ptr noundef %36)
  br label %37

37:                                               ; preds = %35, %32
  br label %38

38:                                               ; preds = %37, %28
  br label %6, !llvm.loop !15

39:                                               ; preds = %6
  %40 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %39
  %43 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [4 x ptr], ptr @sofile, i64 0, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !10
  %47 = call i32 @fclose(ptr noundef %46)
  br label %48

48:                                               ; preds = %42, %39
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 16), align 4, !tbaa !5
  br label %2, !llvm.loop !17

52:                                               ; preds = %2
  %53 = load i32, ptr getelementptr inbounds (%struct.page, ptr @pg, i32 0, i32 2), align 4, !tbaa !18
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  call void (i32, ...) @space(i32 noundef 256)
  br label %56

56:                                               ; preds = %55, %52
  call void @llvm.lifetime.end.p0(i64 200000, ptr %1) #3
  ret void
}

declare i32 @comand(...) #2

declare void @putlin(...) #2

declare void @text(...) #2

declare i32 @fclose(ptr noundef) #2

declare void @space(...) #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 = { "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, !7, i64 60}
!6 = !{!"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}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!6, !8, i64 49}
!14 = !{!6, !7, i64 44}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !7, i64 8}
!19 = !{!"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}


; 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 dso_local local_unnamed_addr global %struct.docctl, align 4
@pg = external dso_local local_unnamed_addr global %struct.page, align 4
@sofile = external dso_local local_unnamed_addr global [4 x ptr], align 16
@pout = external dso_local local_unnamed_addr global ptr, align 8

; 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 uwtable
declare dso_local i32 @getlin(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @profile() local_unnamed_addr #1 {
  %1 = alloca [200000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 200000, ptr nonnull %1) #4
  store i32 0, ptr getelementptr inbounds (i8, ptr @dc, i64 60), align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %0, %28
  %2 = phi i32 [ 0, %0 ], [ %33, %28 ]
  %3 = zext nneg i32 %2 to i64
  %4 = getelementptr inbounds [4 x ptr], ptr @sofile, i64 0, i64 %3
  %5 = load ptr, ptr %4, align 8, !tbaa !10
  %6 = call i32 @getlin(ptr noundef nonnull %1, ptr noundef %5)
  %.not3 = icmp eq i32 %6, -1
  br i1 %.not3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %19
  %7 = load i8, ptr %1, align 16, !tbaa !12
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @dc, i64 49), align 1, !tbaa !13
  %9 = icmp eq i8 %7, %8
  br i1 %9, label %10, label %14

10:                                               ; preds = %.lr.ph
  %11 = call i32 (ptr, ...) @comand(ptr noundef nonnull %1) #4
  %.not2 = icmp eq i32 %11, 0
  br i1 %.not2, label %19, label %12

12:                                               ; preds = %10
  %13 = load ptr, ptr @pout, align 8, !tbaa !10
  call void (ptr, ptr, ...) @putlin(ptr noundef nonnull %1, ptr noundef %13) #4
  br label %19

14:                                               ; preds = %.lr.ph
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 44), align 4, !tbaa !14
  %.not1 = icmp eq i32 %15, 0
  br i1 %.not1, label %18, label %16

16:                                               ; preds = %14
  %17 = load ptr, ptr @pout, align 8, !tbaa !10
  call void (ptr, ptr, ...) @putlin(ptr noundef nonnull %1, ptr noundef %17) #4
  br label %19

18:                                               ; preds = %14
  call void (ptr, ...) @text(ptr noundef nonnull %1) #4
  br label %19

19:                                               ; preds = %16, %18, %10, %12
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 60), align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [4 x ptr], ptr @sofile, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !10
  %24 = call i32 @getlin(ptr noundef nonnull %1, ptr noundef %23)
  %.not = icmp eq i32 %24, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %19, %.preheader
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 60), align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %28, label %.thread

.thread:                                          ; preds = %._crit_edge
  %27 = add nsw i32 %25, -1
  store i32 %27, ptr getelementptr inbounds (i8, ptr @dc, i64 60), align 4, !tbaa !5
  br label %.loopexit

28:                                               ; preds = %._crit_edge
  %29 = zext nneg i32 %25 to i64
  %30 = getelementptr inbounds [4 x ptr], ptr @sofile, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !10
  %32 = call i32 @fclose(ptr noundef %31)
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 60), align 4, !tbaa !5
  %33 = add nsw i32 %.pre, -1
  store i32 %33, ptr getelementptr inbounds (i8, ptr @dc, i64 60), align 4, !tbaa !5
  %34 = icmp sgt i32 %.pre, 0
  br i1 %34, label %.preheader, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %28, %.thread
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @pg, i64 8), align 4, !tbaa !18
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %.loopexit
  call void (i32, ...) @space(i32 noundef 256) #4
  br label %38

38:                                               ; preds = %37, %.loopexit
  call void @llvm.lifetime.end.p0(i64 200000, ptr nonnull %1) #4
  ret void
}

declare i32 @comand(...) local_unnamed_addr #2

declare void @putlin(...) local_unnamed_addr #2

declare void @text(...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

declare void @space(...) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = { nofree 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 #4 = { 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 60}
!6 = !{!"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}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!6, !8, i64 49}
!14 = !{!6, !7, i64 44}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !7, i64 8}
!19 = !{!"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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SimplifyCFGPass