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

; 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.Ptr = type { %struct.Device, ptr, i32, i64, i64, i8, i8, i8, i32, i32 }
%struct.Device = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @ptr_setmotor(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.Ptr, ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %25

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Ptr, ptr %13, i32 0, i32 2
  store i32 %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Ptr, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %11
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ptr_setbusy(ptr noundef %20, i32 noundef 0)
  br label %21

21:                                               ; preds = %19, %11
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Ptr, ptr %22, i32 0, i32 6
  store i8 1, ptr %23, align 1, !tbaa !15
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  call void @recalc_ptr_req(ptr noundef %24)
  br label %25

25:                                               ; preds = %21, %10
  ret void
}

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

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

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 72}
!12 = !{!"Ptr", !13, i64 0, !6, i64 64, !10, i64 72, !14, i64 80, !14, i64 88, !7, i64 96, !7, i64 97, !7, i64 98, !10, i64 100, !10, i64 104}
!13 = !{!"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}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !7, i64 97}


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

; Function Attrs: nounwind uwtable
define dso_local void @ptr_setmotor(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, %1
  br i1 %5, label %10, label %6

6:                                                ; preds = %2
  store i32 %1, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %8, label %7

7:                                                ; preds = %6
  tail call void @ptr_setbusy(ptr noundef nonnull %0, i32 noundef 0)
  br label %8

8:                                                ; preds = %7, %6
  %9 = getelementptr inbounds i8, ptr %0, i64 97
  store i8 1, ptr %9, align 1, !tbaa !13
  tail call void @recalc_ptr_req(ptr noundef nonnull %0)
  br label %10

10:                                               ; preds = %2, %8
  ret void
}

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

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

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, !11, i64 72}
!6 = !{!"Ptr", !7, i64 0, !8, i64 64, !11, i64 72, !12, i64 80, !12, i64 88, !9, i64 96, !9, i64 97, !9, i64 98, !11, i64 100, !11, i64 104}
!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 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!6, !9, i64 97}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass