; LLVM IR from aap/pdp6 :: tools (ld6)

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

@mem = external dso_local global [262144 x i64], align 16
@locmin = external dso_local global i32, align 4
@locmax = external dso_local global i32, align 4
@start = external dso_local global i32, align 4
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @mustopen(ptr noundef, ptr noundef) #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

declare i64 @fw(i32 noundef, i32 noundef) #2

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @savesblk(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @mustopen(ptr noundef %7, ptr noundef @.str.10)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writewits(i64 noundef 23085449217, ptr noundef %9)
  %10 = load i32, ptr @locmax, align 4, !tbaa !9
  %11 = add i32 %10, 1
  %12 = load i32, ptr @locmin, align 4, !tbaa !9
  %13 = sub i32 %11, %12
  %14 = sub i32 0, %13
  %15 = load i32, ptr @locmin, align 4, !tbaa !9
  %16 = call i64 @fw(i32 noundef %14, i32 noundef %15)
  store i64 %16, ptr %5, align 8, !tbaa !11
  %17 = load i64, ptr %5, align 8, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writewits(i64 noundef %17, ptr noundef %18)
  %19 = load i32, ptr @locmin, align 4, !tbaa !9
  store i32 %19, ptr %6, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %39, %1
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr @locmax, align 4, !tbaa !9
  %23 = icmp ule i32 %21, %22
  br i1 %23, label %24, label %42

24:                                               ; preds = %20
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !11
  store i64 %28, ptr %4, align 8, !tbaa !11
  %29 = load i64, ptr %5, align 8, !tbaa !11
  %30 = shl i64 %29, 1
  %31 = load i64, ptr %5, align 8, !tbaa !11
  %32 = lshr i64 %31, 35
  %33 = or i64 %30, %32
  %34 = load i64, ptr %4, align 8, !tbaa !11
  %35 = add i64 %33, %34
  %36 = and i64 %35, 68719476735
  store i64 %36, ptr %5, align 8, !tbaa !11
  %37 = load i64, ptr %4, align 8, !tbaa !11
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writewits(i64 noundef %37, ptr noundef %38)
  br label %39

39:                                               ; preds = %24
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !9
  br label %20, !llvm.loop !13

42:                                               ; preds = %20
  %43 = load i64, ptr %5, align 8, !tbaa !11
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writewits(i64 noundef %43, ptr noundef %44)
  %45 = load i32, ptr @start, align 4, !tbaa !9
  %46 = call i64 @fw(i32 noundef 88064, i32 noundef %45)
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writewits(i64 noundef %46, ptr noundef %47)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call i32 @fclose(ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  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
  ret void
}

declare void @writewits(i64 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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

@mem = external dso_local local_unnamed_addr global [262144 x i64], align 16
@locmin = external dso_local local_unnamed_addr global i32, align 4
@locmax = external dso_local local_unnamed_addr global i32, align 4
@start = external dso_local local_unnamed_addr global i32, align 4
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1

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

declare i64 @fw(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @savesblk(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @mustopen(ptr noundef %0, ptr noundef nonnull @.str.10)
  tail call void @writewits(i64 noundef 23085449217, ptr noundef %2) #3
  %3 = load i32, ptr @locmax, align 4, !tbaa !5
  %.neg16 = xor i32 %3, -1
  %4 = load i32, ptr @locmin, align 4, !tbaa !5
  %.neg = add i32 %4, %.neg16
  %5 = tail call i64 @fw(i32 noundef %.neg, i32 noundef %4) #3
  tail call void @writewits(i64 noundef %5, ptr noundef %2) #3
  %6 = load i32, ptr @locmin, align 4, !tbaa !5
  %7 = load i32, ptr @locmax, align 4, !tbaa !5
  %.not17 = icmp ugt i32 %6, %7
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.019 = phi i32 [ %16, %.lr.ph ], [ %6, %1 ]
  %.01518 = phi i64 [ %15, %.lr.ph ], [ %5, %1 ]
  %8 = zext i32 %.019 to i64
  %9 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = shl i64 %.01518, 1
  %12 = lshr i64 %.01518, 35
  %13 = or i64 %11, %12
  %14 = add i64 %10, %13
  %15 = and i64 %14, 68719476735
  tail call void @writewits(i64 noundef %10, ptr noundef %2) #3
  %16 = add i32 %.019, 1
  %17 = load i32, ptr @locmax, align 4, !tbaa !5
  %.not = icmp ugt i32 %16, %17
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.015.lcssa = phi i64 [ %5, %1 ], [ %15, %.lr.ph ]
  tail call void @writewits(i64 noundef %.015.lcssa, ptr noundef %2) #3
  %18 = load i32, ptr @start, align 4, !tbaa !5
  %19 = tail call i64 @fw(i32 noundef 88064, i32 noundef %18) #3
  tail call void @writewits(i64 noundef %19, ptr noundef %2) #3
  %20 = tail call i32 @fclose(ptr noundef %2)
  ret void
}

declare void @writewits(i64 noundef, ptr 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 = { "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 = { 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 #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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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