; 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.Pulse = type { ptr, ptr }
%struct.Apr = type { %struct.Device, %struct.IOBus, %struct.Membus, i32, %struct.AprState, %struct.AprState, i32, i64, i64, i32, i32, i32, i8, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, ptr, ptr, i32, i8, [20 x %struct.TPulse], ptr, ptr }
%struct.Device = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.IOBus = type { i64, i64, i64, i64, i64, i64, i32, [128 x %struct.Busdev] }
%struct.Busdev = type { ptr, ptr, i8 }
%struct.Membus = type { i64, i64, i64, i64, i64, i64, ptr, [16 x ptr] }
%struct.AprState = type { i64, i64, i64 }
%struct.TPulse = type { ptr, ptr, i32 }

@it0 = external hidden global %struct.Pulse, align 8

; Function Attrs: nounwind uwtable
declare hidden void @aprcycle(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @pulse(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @apr_testinst(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.Apr, ptr %3, i32 0, i32 22
  store i8 0, ptr %4, align 1, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  call void @aprcycle(ptr noundef %5)
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.Apr, ptr %6, i32 0, i32 22
  store i8 1, ptr %7, align 1, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  call void @aprcycle(ptr noundef %8)
  br label %9

9:                                                ; preds = %14, %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Apr, ptr %10, i32 0, i32 182
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  call void @aprcycle(ptr noundef %15)
  br label %9, !llvm.loop !19

16:                                               ; preds = %9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Apr, ptr %17, i32 0, i32 9
  store i32 16, ptr %18, align 8, !tbaa !21
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  call void @pulse(ptr noundef %19, ptr noundef @it0, i32 noundef 1)
  br label %20

20:                                               ; preds = %25, %16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Apr, ptr %21, i32 0, i32 182
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %20
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @aprcycle(ptr noundef %26)
  br label %20, !llvm.loop !22

27:                                               ; preds = %20
  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" }

!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, !7, i64 3481}
!10 = !{!"Apr", !11, i64 0, !12, i64 64, !15, i64 3192, !14, i64 3376, !16, i64 3384, !16, i64 3408, !14, i64 3432, !13, i64 3440, !13, i64 3448, !14, i64 3456, !14, i64 3460, !14, i64 3464, !7, i64 3468, !17, i64 3470, !17, i64 3472, !7, i64 3474, !7, i64 3475, !7, i64 3476, !7, i64 3477, !7, i64 3478, !7, i64 3479, !7, i64 3480, !7, i64 3481, !7, i64 3482, !7, i64 3483, !7, i64 3484, !7, i64 3485, !7, i64 3486, !7, i64 3487, !7, i64 3488, !7, i64 3489, !7, i64 3490, !7, i64 3491, !7, i64 3492, !7, i64 3493, !7, i64 3494, !7, i64 3495, !7, i64 3496, !7, i64 3497, !7, i64 3498, !7, i64 3499, !7, i64 3500, !7, i64 3501, !7, i64 3502, !14, i64 3504, !14, i64 3508, !7, i64 3512, !7, i64 3513, !7, i64 3514, !7, i64 3515, !7, i64 3516, !7, i64 3517, !7, i64 3518, !7, i64 3519, !7, i64 3520, !7, i64 3521, !7, i64 3522, !7, i64 3523, !7, i64 3524, !7, i64 3525, !7, i64 3526, !7, i64 3527, !7, i64 3528, !7, i64 3529, !7, i64 3530, !7, i64 3531, !7, i64 3532, !7, i64 3533, !7, i64 3534, !7, i64 3535, !7, i64 3536, !7, i64 3537, !7, i64 3538, !7, i64 3539, !7, i64 3540, !7, i64 3541, !7, i64 3542, !7, i64 3543, !7, i64 3544, !7, i64 3545, !7, i64 3546, !7, i64 3547, !7, i64 3548, !7, i64 3549, !7, i64 3550, !7, i64 3551, !14, i64 3552, !7, i64 3556, !7, i64 3557, !7, i64 3558, !7, i64 3559, !7, i64 3560, !7, i64 3561, !7, i64 3562, !7, i64 3563, !7, i64 3564, !7, i64 3565, !7, i64 3566, !7, i64 3567, !7, i64 3568, !7, i64 3569, !7, i64 3570, !7, i64 3571, !7, i64 3572, !7, i64 3573, !7, i64 3574, !7, i64 3575, !7, i64 3576, !7, i64 3577, !7, i64 3578, !7, i64 3579, !7, i64 3580, !7, i64 3581, !7, i64 3582, !7, i64 3583, !7, i64 3584, !7, i64 3585, !7, i64 3586, !7, i64 3587, !7, i64 3588, !7, i64 3589, !7, i64 3590, !7, i64 3591, !7, i64 3592, !7, i64 3593, !7, i64 3594, !7, i64 3595, !7, i64 3596, !7, i64 3597, !7, i64 3598, !7, i64 3599, !7, i64 3600, !7, i64 3601, !7, i64 3602, !7, i64 3603, !7, i64 3604, !7, i64 3605, !7, i64 3606, !7, i64 3607, !7, i64 3608, !7, i64 3609, !7, i64 3610, !7, i64 3611, !7, i64 3612, !7, i64 3613, !7, i64 3614, !14, i64 3616, !14, i64 3620, !14, i64 3624, !7, i64 3628, !7, i64 3629, !7, i64 3630, !7, i64 3631, !7, i64 3632, !7, i64 3633, !7, i64 3634, !7, i64 3635, !7, i64 3636, !7, i64 3637, !7, i64 3638, !7, i64 3639, !7, i64 3640, !7, i64 3641, !7, i64 3642, !14, i64 3644, !7, i64 3648, !7, i64 3649, !7, i64 3650, !7, i64 3651, !7, i64 3652, !7, i64 3653, !7, i64 3654, !7, i64 3655, !7, i64 3656, !7, i64 3657, !7, i64 3658, !6, i64 3664, !6, i64 3672, !14, i64 3680, !7, i64 3684, !7, i64 3688, !6, i64 4168, !6, i64 4176}
!11 = !{!"Device", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!12 = !{!"IOBus", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !14, i64 48, !7, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"Membus", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !6, i64 48, !7, i64 56}
!16 = !{!"AprState", !13, i64 0, !13, i64 8, !13, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!10, !6, i64 4176}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !14, i64 3456}
!22 = distinct !{!22, !20}


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

@it0 = external hidden global %struct.Pulse, align 8

; Function Attrs: nounwind uwtable
declare hidden void @aprcycle(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @pulse(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @apr_testinst(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 3481
  store i8 0, ptr %2, align 1, !tbaa !5
  tail call void @aprcycle(ptr noundef %0)
  store i8 1, ptr %2, align 1, !tbaa !5
  tail call void @aprcycle(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 4176
  %4 = load ptr, ptr %3, align 8, !tbaa !17
  %.not11 = icmp eq ptr %4, null
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  tail call void @aprcycle(ptr noundef nonnull %0)
  %5 = load ptr, ptr %3, align 8, !tbaa !17
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 3456
  store i32 16, ptr %6, align 8, !tbaa !20
  tail call void @pulse(ptr noundef nonnull %0, ptr noundef nonnull @it0, i32 noundef 1)
  %7 = load ptr, ptr %3, align 8, !tbaa !17
  %.not1012 = icmp eq ptr %7, null
  br i1 %.not1012, label %._crit_edge15, label %.lr.ph14

.lr.ph14:                                         ; preds = %._crit_edge, %.lr.ph14
  tail call void @aprcycle(ptr noundef nonnull %0)
  %8 = load ptr, ptr %3, align 8, !tbaa !17
  %.not10 = icmp eq ptr %8, null
  br i1 %.not10, label %._crit_edge15, label %.lr.ph14, !llvm.loop !21

._crit_edge15:                                    ; preds = %.lr.ph14, %._crit_edge
  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" }

!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, !9, i64 3481}
!6 = !{!"Apr", !7, i64 0, !11, i64 64, !14, i64 3192, !13, i64 3376, !15, i64 3384, !15, i64 3408, !13, i64 3432, !12, i64 3440, !12, i64 3448, !13, i64 3456, !13, i64 3460, !13, i64 3464, !9, i64 3468, !16, i64 3470, !16, i64 3472, !9, i64 3474, !9, i64 3475, !9, i64 3476, !9, i64 3477, !9, i64 3478, !9, i64 3479, !9, i64 3480, !9, i64 3481, !9, i64 3482, !9, i64 3483, !9, i64 3484, !9, i64 3485, !9, i64 3486, !9, i64 3487, !9, i64 3488, !9, i64 3489, !9, i64 3490, !9, i64 3491, !9, i64 3492, !9, i64 3493, !9, i64 3494, !9, i64 3495, !9, i64 3496, !9, i64 3497, !9, i64 3498, !9, i64 3499, !9, i64 3500, !9, i64 3501, !9, i64 3502, !13, i64 3504, !13, i64 3508, !9, i64 3512, !9, i64 3513, !9, i64 3514, !9, i64 3515, !9, i64 3516, !9, i64 3517, !9, i64 3518, !9, i64 3519, !9, i64 3520, !9, i64 3521, !9, i64 3522, !9, i64 3523, !9, i64 3524, !9, i64 3525, !9, i64 3526, !9, i64 3527, !9, i64 3528, !9, i64 3529, !9, i64 3530, !9, i64 3531, !9, i64 3532, !9, i64 3533, !9, i64 3534, !9, i64 3535, !9, i64 3536, !9, i64 3537, !9, i64 3538, !9, i64 3539, !9, i64 3540, !9, i64 3541, !9, i64 3542, !9, i64 3543, !9, i64 3544, !9, i64 3545, !9, i64 3546, !9, i64 3547, !9, i64 3548, !9, i64 3549, !9, i64 3550, !9, i64 3551, !13, i64 3552, !9, i64 3556, !9, i64 3557, !9, i64 3558, !9, i64 3559, !9, i64 3560, !9, i64 3561, !9, i64 3562, !9, i64 3563, !9, i64 3564, !9, i64 3565, !9, i64 3566, !9, i64 3567, !9, i64 3568, !9, i64 3569, !9, i64 3570, !9, i64 3571, !9, i64 3572, !9, i64 3573, !9, i64 3574, !9, i64 3575, !9, i64 3576, !9, i64 3577, !9, i64 3578, !9, i64 3579, !9, i64 3580, !9, i64 3581, !9, i64 3582, !9, i64 3583, !9, i64 3584, !9, i64 3585, !9, i64 3586, !9, i64 3587, !9, i64 3588, !9, i64 3589, !9, i64 3590, !9, i64 3591, !9, i64 3592, !9, i64 3593, !9, i64 3594, !9, i64 3595, !9, i64 3596, !9, i64 3597, !9, i64 3598, !9, i64 3599, !9, i64 3600, !9, i64 3601, !9, i64 3602, !9, i64 3603, !9, i64 3604, !9, i64 3605, !9, i64 3606, !9, i64 3607, !9, i64 3608, !9, i64 3609, !9, i64 3610, !9, i64 3611, !9, i64 3612, !9, i64 3613, !9, i64 3614, !13, i64 3616, !13, i64 3620, !13, i64 3624, !9, i64 3628, !9, i64 3629, !9, i64 3630, !9, i64 3631, !9, i64 3632, !9, i64 3633, !9, i64 3634, !9, i64 3635, !9, i64 3636, !9, i64 3637, !9, i64 3638, !9, i64 3639, !9, i64 3640, !9, i64 3641, !9, i64 3642, !13, i64 3644, !9, i64 3648, !9, i64 3649, !9, i64 3650, !9, i64 3651, !9, i64 3652, !9, i64 3653, !9, i64 3654, !9, i64 3655, !9, i64 3656, !9, i64 3657, !9, i64 3658, !8, i64 3664, !8, i64 3672, !13, i64 3680, !9, i64 3684, !9, i64 3688, !8, i64 4168, !8, i64 4176}
!7 = !{!"Device", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"IOBus", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !13, i64 48, !9, i64 56}
!12 = !{!"long", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"Membus", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !8, i64 48, !9, i64 56}
!15 = !{!"AprState", !12, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!"short", !9, i64 0}
!17 = !{!6, !8, i64 4176}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !13, i64 3456}
!21 = distinct !{!21, !19}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass