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

%struct.Add = type { i64, i32, i32, ptr }

@stderr = external global ptr, align 8
@mem = external dso_local global [262144 x i64], align 16
@addlist = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @left(i64 noundef) #2

declare i32 @right(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @findsym(i64 noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @fixadd() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca [8 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %4 = load ptr, ptr @addlist, align 8, !tbaa !5
  store ptr %4, ptr %1, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %82, %0
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %86

8:                                                ; preds = %5
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Add, ptr %9, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = call ptr @findsym(i64 noundef %11)
  store ptr %12, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %24

15:                                               ; preds = %8
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Add, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 0
  %20 = call i32 @unrad50(i64 noundef %18, ptr noundef %19)
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 0
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.4, ptr noundef %22) #4
  br label %82

24:                                               ; preds = %8
  %25 = load ptr, ptr %1, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Add, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %55

29:                                               ; preds = %24
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Add, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = call i32 @left(i64 noundef %35)
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds i64, ptr %37, i64 1
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = call i32 @right(i64 noundef %39)
  %41 = add i32 %36, %40
  %42 = load ptr, ptr %1, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Add, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = call i32 @right(i64 noundef %47)
  %49 = call i64 @fw(i32 noundef %41, i32 noundef %48)
  %50 = load ptr, ptr %1, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Add, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !14
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %53
  store i64 %49, ptr %54, align 8, !tbaa !15
  br label %81

55:                                               ; preds = %24
  %56 = load ptr, ptr %1, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Add, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !14
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !15
  %62 = call i32 @left(i64 noundef %61)
  %63 = load ptr, ptr %1, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Add, ptr %63, i32 0, i32 2
  %65 = load i32, ptr %64, align 4, !tbaa !14
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !15
  %69 = call i32 @right(i64 noundef %68)
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds i64, ptr %70, i64 1
  %72 = load i64, ptr %71, align 8, !tbaa !15
  %73 = call i32 @right(i64 noundef %72)
  %74 = add i32 %69, %73
  %75 = call i64 @fw(i32 noundef %62, i32 noundef %74)
  %76 = load ptr, ptr %1, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.Add, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !14
  %79 = zext i32 %78 to i64
  %80 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %79
  store i64 %75, ptr %80, align 8, !tbaa !15
  br label %81

81:                                               ; preds = %55, %29
  br label %82

82:                                               ; preds = %81, %15
  %83 = load ptr, ptr %1, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Add, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !16
  store ptr %85, ptr %1, align 8, !tbaa !5
  br label %5, !llvm.loop !17

86:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

declare i32 @unrad50(i64 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"Add", !11, i64 0, !12, i64 8, !12, i64 12, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !12, i64 12}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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
@mem = external dso_local local_unnamed_addr global [262144 x i64], align 16
@addlist = external dso_local local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @left(i64 noundef) local_unnamed_addr #2

declare i32 @right(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @findsym(i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local void @fixadd() local_unnamed_addr #3 {
  %1 = alloca [8 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %.016 = load ptr, ptr @addlist, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %47
  %.018 = phi ptr [ %.0, %47 ], [ %.016, %0 ]
  %2 = load i64, ptr %.018, align 8, !tbaa !9
  %3 = call ptr @findsym(i64 noundef %2)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %10

5:                                                ; preds = %.lr.ph
  %6 = load i64, ptr %.018, align 8, !tbaa !9
  %7 = call i32 @unrad50(i64 noundef %6, ptr noundef nonnull %1) #4
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.4, ptr noundef nonnull %1) #5
  br label %47

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.018, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %.not15 = icmp eq i32 %12, 0
  %13 = getelementptr inbounds i8, ptr %.018, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = call i32 @left(i64 noundef %17) #4
  br i1 %.not15, label %33, label %19

19:                                               ; preds = %10
  %20 = getelementptr inbounds i8, ptr %3, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = call i32 @right(i64 noundef %21) #4
  %23 = add i32 %22, %18
  %24 = load i32, ptr %13, align 4, !tbaa !14
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = call i32 @right(i64 noundef %27) #4
  %29 = call i64 @fw(i32 noundef %23, i32 noundef %28) #4
  %30 = load i32, ptr %13, align 4, !tbaa !14
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %31
  store i64 %29, ptr %32, align 8, !tbaa !15
  br label %47

33:                                               ; preds = %10
  %34 = load i32, ptr %13, align 4, !tbaa !14
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = call i32 @right(i64 noundef %37) #4
  %39 = getelementptr inbounds i8, ptr %3, i64 8
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = call i32 @right(i64 noundef %40) #4
  %42 = add i32 %41, %38
  %43 = call i64 @fw(i32 noundef %18, i32 noundef %42) #4
  %44 = load i32, ptr %13, align 4, !tbaa !14
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %45
  store i64 %43, ptr %46, align 8, !tbaa !15
  br label %47

47:                                               ; preds = %19, %33, %5
  %48 = getelementptr inbounds i8, ptr %.018, i64 16
  %.0 = load ptr, ptr %48, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %47, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret void
}

declare i32 @unrad50(i64 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 #4 = { nounwind }
attributes #5 = { 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, !11, i64 0}
!10 = !{!"Add", !11, i64 0, !12, i64 8, !12, i64 12, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !12, i64 12}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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