; LLVM IR from aap/pdp6 :: misc (rim2mem)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@pc = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@mem = external dso_local global [262144 x i64], align 16
@maxmem = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @rimword() #0

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

7:                                                ; preds = %74, %0
  %8 = call i64 @rimword()
  store i64 %8, ptr %3, align 8, !tbaa !5
  store i64 %8, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = icmp eq i64 %9, -1
  br i1 %10, label %11, label %14

11:                                               ; preds = %7
  %12 = load ptr, ptr @stderr, align 8, !tbaa !9
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str) #3
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %76

14:                                               ; preds = %7
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = and i64 %15, 68585259008
  %17 = icmp eq i64 %16, 23085449216
  br i1 %17, label %18, label %22

18:                                               ; preds = %14
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = and i64 %19, 262143
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr @pc, align 4, !tbaa !11
  br label %75

22:                                               ; preds = %14
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = add i64 %23, 1
  %25 = and i64 %24, 262143
  store i64 %25, ptr %5, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %45, %22
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = and i64 %27, 34359738368
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %48

30:                                               ; preds = %26
  %31 = call i64 @rimword()
  store i64 %31, ptr %2, align 8, !tbaa !5
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = icmp eq i64 %32, -1
  br i1 %33, label %34, label %37

34:                                               ; preds = %30
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.1) #3
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %76

37:                                               ; preds = %30
  %38 = load i64, ptr %2, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = add i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %39
  store i64 %38, ptr %41, align 8, !tbaa !5
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = add i64 %43, %42
  store i64 %44, ptr %4, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %37
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = add i64 %46, 262144
  store i64 %47, ptr %3, align 8, !tbaa !5
  br label %26, !llvm.loop !13

48:                                               ; preds = %26
  %49 = load i64, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr @maxmem, align 4, !tbaa !11
  %51 = zext i32 %50 to i64
  %52 = icmp ugt i64 %49, %51
  br i1 %52, label %53, label %56

53:                                               ; preds = %48
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = trunc i64 %54 to i32
  store i32 %55, ptr @maxmem, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %53, %48
  %57 = call i64 @rimword()
  store i64 %57, ptr %2, align 8, !tbaa !5
  %58 = load i64, ptr %2, align 8, !tbaa !5
  %59 = icmp eq i64 %58, -1
  br i1 %59, label %60, label %63

60:                                               ; preds = %56
  %61 = load ptr, ptr @stderr, align 8, !tbaa !9
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str.2) #3
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %76

63:                                               ; preds = %56
  %64 = load i64, ptr %4, align 8, !tbaa !5
  %65 = load i64, ptr %2, align 8, !tbaa !5
  %66 = add i64 %64, %65
  %67 = and i64 %66, 68719476735
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %69, label %74

69:                                               ; preds = %63
  %70 = load ptr, ptr @stderr, align 8, !tbaa !9
  %71 = load i64, ptr %4, align 8, !tbaa !5
  %72 = load i64, ptr %2, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.3, i64 noundef %71, i64 noundef %72) #3
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %76

74:                                               ; preds = %63
  br label %7

75:                                               ; preds = %18
  store i32 1, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %76

76:                                               ; preds = %75, %69, %60, %34, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %77 = load i32, ptr %1, align 4
  ret i32 %77
}

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


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@pc = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@mem = external dso_local local_unnamed_addr global [262144 x i64], align 16
@maxmem = external dso_local local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @rimword() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @readrim() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %39, %0
  %2 = tail call i64 @rimword()
  %3 = icmp eq i64 %2, -1
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str) #2
  br label %45

7:                                                ; preds = %1
  %8 = and i64 %2, 68585259008
  %9 = icmp eq i64 %8, 23085449216
  br i1 %9, label %10, label %13

10:                                               ; preds = %7
  %11 = trunc i64 %2 to i32
  %12 = and i32 %11, 262143
  store i32 %12, ptr @pc, align 4, !tbaa !9
  br label %45

13:                                               ; preds = %7
  %14 = add nuw i64 %2, 1
  %15 = and i64 %14, 262143
  %16 = and i64 %2, 34359738368
  %.not35 = icmp eq i64 %16, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %22
  %.038 = phi i64 [ %23, %22 ], [ %15, %13 ]
  %.01937 = phi i64 [ %25, %22 ], [ %2, %13 ]
  %.02036 = phi i64 [ %26, %22 ], [ %2, %13 ]
  %17 = tail call i64 @rimword()
  %18 = icmp eq i64 %17, -1
  br i1 %18, label %19, label %22

19:                                               ; preds = %.lr.ph
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.1) #2
  br label %45

22:                                               ; preds = %.lr.ph
  %23 = add i64 %.038, 1
  %24 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %.038
  store i64 %17, ptr %24, align 8, !tbaa !11
  %25 = add i64 %17, %.01937
  %26 = add i64 %.02036, 262144
  %27 = and i64 %26, 34359738368
  %.not = icmp eq i64 %27, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %22, %13
  %.019.lcssa = phi i64 [ %2, %13 ], [ %25, %22 ]
  %.0.lcssa = phi i64 [ %15, %13 ], [ %23, %22 ]
  %28 = load i32, ptr @maxmem, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = icmp ugt i64 %.0.lcssa, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %._crit_edge
  %32 = trunc i64 %.0.lcssa to i32
  store i32 %32, ptr @maxmem, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %31, %._crit_edge
  %34 = tail call i64 @rimword()
  %35 = icmp eq i64 %34, -1
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str.2) #2
  br label %45

39:                                               ; preds = %33
  %40 = add i64 %34, %.019.lcssa
  %41 = and i64 %40, 68719476735
  %.not25 = icmp eq i64 %41, 0
  br i1 %.not25, label %1, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.3, i64 noundef %.019.lcssa, i64 noundef %34) #2
  br label %45

45:                                               ; preds = %10, %42, %36, %19, %4
  %.021 = phi i32 [ 0, %4 ], [ 1, %10 ], [ 0, %19 ], [ 0, %36 ], [ 0, %42 ]
  ret i32 %.021
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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 = { 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 #2 = { cold 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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