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

; 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.Sym = type { i64, i32, %union.anon, ptr }
%union.anon = type { %struct.Value }
%struct.Value = type { i64, i32 }

@pass2 = external dso_local global i32, align 4
@numops = external dso_local global i32, align 4
@ops = external dso_local global [20 x ptr], align 16
@.str.44 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @err(i32 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @getsym(i64 noundef) #0

declare i64 @sixbit(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @splitop() #0

; Function Attrs: nounwind uwtable
define dso_local void @externOp() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %4 = load i32, ptr @pass2, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %7

6:                                                ; preds = %0
  store i32 1, ptr %3, align 4
  br label %44

7:                                                ; preds = %0
  call void @splitop()
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %40, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @numops, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %43

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [20 x ptr], ptr @ops, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = call i64 @sixbit(ptr noundef %16)
  %18 = call ptr @getsym(i64 noundef %17)
  store ptr %18, ptr %1, align 8, !tbaa !9
  %19 = load ptr, ptr %1, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Sym, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp sge i32 %21, 64
  br i1 %22, label %29, label %23

23:                                               ; preds = %12
  %24 = load ptr, ptr %1, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Sym, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = and i32 %26, 2
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %34

29:                                               ; preds = %23, %12
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [20 x ptr], ptr @ops, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  call void (i32, ptr, ...) @err(i32 noundef 0, ptr noundef @.str.44, ptr noundef %33)
  br label %39

34:                                               ; preds = %23
  %35 = load ptr, ptr %1, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.Sym, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = or i32 %37, 4
  store i32 %38, ptr %36, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %34, %29
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !14

43:                                               ; preds = %8
  store i32 0, ptr %3, align 4
  br label %44

44:                                               ; preds = %43, %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  %45 = load i32, ptr %3, align 4
  switch i32 %45, label %47 [
    i32 0, label %46
    i32 1, label %46
  ]

46:                                               ; preds = %44, %44
  ret void

47:                                               ; preds = %44
  unreachable
}

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 = !{!"int", !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, !6, i64 8}
!12 = !{!"Sym", !13, i64 0, !6, i64 8, !7, i64 16, !10, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@pass2 = external dso_local local_unnamed_addr global i32, align 4
@numops = external dso_local local_unnamed_addr global i32, align 4
@ops = external dso_local local_unnamed_addr global [20 x ptr], align 16
@.str.44 = external hidden unnamed_addr constant [32 x i8], align 1

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

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

declare i64 @sixbit(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @splitop() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @externOp() local_unnamed_addr #0 {
  %1 = load i32, ptr @pass2, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %2, label %.loopexit

2:                                                ; preds = %0
  tail call void @splitop()
  %3 = load i32, ptr @numops, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %2, %17
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ 0, %2 ]
  %5 = getelementptr inbounds [20 x ptr], ptr @ops, i64 0, i64 %indvars.iv
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = tail call i64 @sixbit(ptr noundef %6) #2
  %8 = tail call ptr @getsym(i64 noundef %7)
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp slt i32 %10, 64
  %12 = and i32 %10, 2
  %.not7 = icmp eq i32 %12, 0
  %or.cond = and i1 %11, %.not7
  br i1 %or.cond, label %15, label %13

13:                                               ; preds = %.lr.ph
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  tail call void (i32, ptr, ...) @err(i32 noundef 0, ptr noundef nonnull @.str.44, ptr noundef %14)
  br label %17

15:                                               ; preds = %.lr.ph
  %16 = or i32 %10, 4
  store i32 %16, ptr %9, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %13, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @numops, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %17, %2, %0
  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" }
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 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"Sym", !13, i64 0, !6, i64 8, !7, i64 16, !10, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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