; LLVM IR from aap/pdp6 :: emu (apr)

; 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.IOBus = type { i64, i64, i64, i64, i64, i64, i32, [128 x %struct.Busdev] }
%struct.Busdev = type { ptr, ptr, i8 }

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

5:                                                ; preds = %19, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 128
  br i1 %7, label %8, label %22

8:                                                ; preds = %5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.IOBus, ptr %9, i32 0, i32 7
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [128 x %struct.Busdev], ptr %10, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.Busdev, ptr %13, i32 0, i32 2
  %15 = load i8, ptr %14, align 8, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = or i32 %17, %16
  store i32 %18, ptr %4, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %8
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !13

22:                                               ; preds = %5
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.IOBus, ptr %23, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = and i64 %25, -128
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = and i32 %27, 127
  %29 = sext i32 %28 to i64
  %30 = or i64 %26, %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.IOBus, ptr %31, i32 0, i32 3
  store i64 %30, ptr %32, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = { 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, !7, i64 16}
!12 = !{!"Busdev", !6, i64 0, !6, i64 8, !7, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !17, i64 24}
!16 = !{!"IOBus", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !10, i64 48, !7, i64 56}
!17 = !{!"long", !7, i64 0}


; 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.Busdev = type { ptr, ptr, i8 }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @recalc_req(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  br label %3

3:                                                ; preds = %3, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.3, %3 ]
  %.09 = phi i32 [ 0, %1 ], [ %19, %3 ]
  %4 = getelementptr inbounds [128 x %struct.Busdev], ptr %2, i64 0, i64 %indvars.iv, i32 2
  %5 = load i8, ptr %4, align 8, !tbaa !5
  %6 = zext i8 %5 to i32
  %7 = or i32 %.09, %6
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %8 = getelementptr inbounds [128 x %struct.Busdev], ptr %2, i64 0, i64 %indvars.iv.next, i32 2
  %9 = load i8, ptr %8, align 8, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = or i32 %7, %10
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %12 = getelementptr inbounds [128 x %struct.Busdev], ptr %2, i64 0, i64 %indvars.iv.next.1, i32 2
  %13 = load i8, ptr %12, align 8, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = or i32 %11, %14
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %16 = getelementptr inbounds [128 x %struct.Busdev], ptr %2, i64 0, i64 %indvars.iv.next.2, i32 2
  %17 = load i8, ptr %16, align 8, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = or i32 %15, %18
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 128
  br i1 %exitcond.not.3, label %20, label %3, !llvm.loop !10

20:                                               ; preds = %3
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load i64, ptr %21, align 8, !tbaa !12
  %23 = and i64 %22, -128
  %24 = and i32 %19, 127
  %25 = zext nneg i32 %24 to i64
  %26 = or disjoint i64 %23, %25
  store i64 %26, ptr %21, align 8, !tbaa !12
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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, !8, i64 16}
!6 = !{!"Busdev", !7, i64 0, !7, i64 8, !8, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 24}
!13 = !{!"IOBus", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !15, i64 48, !8, i64 56}
!14 = !{!"long", !8, i64 0}
!15 = !{!"int", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass