; LLVM IR from cvra/robot-software :: master-firmware/src/can (bus_enumerator)

; 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.bus_enumerator_t = type { ptr, ptr, i16, i16, i16 }
%struct.bus_enumerator_entry_t = type { ptr, i8, ptr }

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @midpoint(i16 noundef zeroext, i16 noundef zeroext) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

; 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 @bus_enumerator_update_node_info(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call zeroext i16 @index_by_str_id(ptr noundef %11, ptr noundef %12)
  store i16 %13, ptr %7, align 2, !tbaa !10
  %14 = load i16, ptr %7, align 2, !tbaa !10
  %15 = zext i16 %14 to i32
  %16 = icmp ne i32 %15, 65535
  br i1 %16, label %17, label %110

17:                                               ; preds = %3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.bus_enumerator_t, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load i16, ptr %7, align 2, !tbaa !10
  %22 = zext i16 %21 to i64
  %23 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %23, i32 0, i32 1
  %25 = load i8, ptr %24, align 8, !tbaa !14
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %26, 255
  br i1 %27, label %28, label %110

28:                                               ; preds = %17
  %29 = load i8, ptr %6, align 1, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.bus_enumerator_t, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = load i16, ptr %7, align 2, !tbaa !10
  %34 = zext i16 %33 to i64
  %35 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %35, i32 0, i32 1
  store i8 %29, ptr %36, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  store i16 0, ptr %8, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.bus_enumerator_t, ptr %37, i32 0, i32 4
  %39 = load i16, ptr %38, align 4, !tbaa !16
  store i16 %39, ptr %9, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  br label %40

40:                                               ; preds = %69, %28
  %41 = load i16, ptr %8, align 2, !tbaa !10
  %42 = zext i16 %41 to i32
  %43 = load i16, ptr %9, align 2, !tbaa !10
  %44 = zext i16 %43 to i32
  %45 = icmp ne i32 %42, %44
  br i1 %45, label %46, label %70

46:                                               ; preds = %40
  %47 = load i16, ptr %8, align 2, !tbaa !10
  %48 = load i16, ptr %9, align 2, !tbaa !10
  %49 = call zeroext i16 @midpoint(i16 noundef zeroext %47, i16 noundef zeroext %48)
  store i16 %49, ptr %10, align 2, !tbaa !10
  %50 = load i8, ptr %6, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bus_enumerator_t, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load i16, ptr %10, align 2, !tbaa !10
  %56 = zext i16 %55 to i64
  %57 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %57, i32 0, i32 1
  %59 = load i8, ptr %58, align 8, !tbaa !14
  %60 = zext i8 %59 to i32
  %61 = icmp sgt i32 %51, %60
  br i1 %61, label %62, label %67

62:                                               ; preds = %46
  %63 = load i16, ptr %10, align 2, !tbaa !10
  %64 = zext i16 %63 to i32
  %65 = add nsw i32 %64, 1
  %66 = trunc i32 %65 to i16
  store i16 %66, ptr %8, align 2, !tbaa !10
  br label %69

67:                                               ; preds = %46
  %68 = load i16, ptr %10, align 2, !tbaa !10
  store i16 %68, ptr %9, align 2, !tbaa !10
  br label %69

69:                                               ; preds = %67, %62
  br label %40, !llvm.loop !18

70:                                               ; preds = %40
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.bus_enumerator_t, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  %74 = load i16, ptr %8, align 2, !tbaa !10
  %75 = zext i16 %74 to i32
  %76 = add nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %73, i64 %77
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.bus_enumerator_t, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = load i16, ptr %8, align 2, !tbaa !10
  %83 = zext i16 %82 to i64
  %84 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %81, i64 %83
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.bus_enumerator_t, ptr %85, i32 0, i32 4
  %87 = load i16, ptr %86, align 4, !tbaa !16
  %88 = zext i16 %87 to i32
  %89 = load i16, ptr %8, align 2, !tbaa !10
  %90 = zext i16 %89 to i32
  %91 = sub nsw i32 %88, %90
  %92 = sext i32 %91 to i64
  %93 = mul i64 %92, 24
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %78, ptr align 8 %84, i64 %93, i1 false)
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.bus_enumerator_t, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !17
  %97 = load i16, ptr %8, align 2, !tbaa !10
  %98 = zext i16 %97 to i64
  %99 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %96, i64 %98
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.bus_enumerator_t, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !12
  %103 = load i16, ptr %7, align 2, !tbaa !10
  %104 = zext i16 %103 to i64
  %105 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %102, i64 %104
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %99, ptr align 8 %105, i64 24, i1 false)
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.bus_enumerator_t, ptr %106, i32 0, i32 4
  %108 = load i16, ptr %107, align 4, !tbaa !16
  %109 = add i16 %108, 1
  store i16 %109, ptr %107, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  br label %110

110:                                              ; preds = %70, %17, %3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @index_by_str_id(ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 18, !11, i64 20}
!14 = !{!15, !7, i64 8}
!15 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16}
!16 = !{!13, !11, i64 20}
!17 = !{!13, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.bus_enumerator_entry_t = type { ptr, i8, ptr }

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @midpoint(i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local void @bus_enumerator_update_node_info(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i16 @index_by_str_id(ptr noundef %0, ptr noundef %1)
  %.not = icmp eq i16 %4, -1
  br i1 %.not, label %36, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = zext i16 %4 to i64
  %8 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %6, i64 %7, i32 1
  %9 = load i8, ptr %8, align 8, !tbaa !11
  %10 = icmp eq i8 %9, -1
  br i1 %10, label %11, label %36

11:                                               ; preds = %5
  store i8 %2, ptr %8, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  %13 = load i16, ptr %12, align 4, !tbaa !13
  %.not3132 = icmp eq i16 %13, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %.not3132, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %11
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !14
  br label %._crit_edge

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.034 = phi i16 [ %.1, %.lr.ph ], [ 0, %11 ]
  %.02833 = phi i16 [ %.129, %.lr.ph ], [ %13, %11 ]
  %14 = tail call zeroext i16 @midpoint(i16 noundef zeroext %.034, i16 noundef zeroext %.02833)
  %15 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !14
  %16 = zext i16 %14 to i64
  %17 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %15, i64 %16, i32 1
  %18 = load i8, ptr %17, align 8, !tbaa !11
  %19 = icmp ult i8 %18, %2
  %20 = add i16 %14, 1
  %.129 = select i1 %19, i16 %.02833, i16 %14
  %.1 = select i1 %19, i16 %20, i16 %.034
  %.not31 = icmp eq i16 %.1, %.129
  br i1 %.not31, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre35 = load i16, ptr %12, align 4, !tbaa !13
  %21 = zext i16 %.129 to i64
  %22 = zext i16 %.pre35 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.._crit_edge_crit_edge, %._crit_edge.loopexit
  %23 = phi i64 [ 0, %.._crit_edge_crit_edge ], [ %22, %._crit_edge.loopexit ]
  %24 = phi ptr [ %.pre, %.._crit_edge_crit_edge ], [ %15, %._crit_edge.loopexit ]
  %.0.lcssa = phi i64 [ 0, %.._crit_edge_crit_edge ], [ %21, %._crit_edge.loopexit ]
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %24, i64 %.0.lcssa
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  %28 = sub nsw i64 %23, %.0.lcssa
  %29 = mul nsw i64 %28, 24
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %27, ptr align 8 %26, i64 %29, i1 false)
  %30 = load ptr, ptr %25, align 8, !tbaa !14
  %31 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %30, i64 %.0.lcssa
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.bus_enumerator_entry_t, ptr %32, i64 %7
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %31, ptr noundef nonnull align 8 dereferenceable(24) %33, i64 24, i1 false)
  %34 = load i16, ptr %12, align 4, !tbaa !13
  %35 = add i16 %34, 1
  store i16 %35, ptr %12, align 4, !tbaa !13
  br label %36

36:                                               ; preds = %._crit_edge, %5, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @index_by_str_id(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !8, i64 8}
!12 = !{!"", !7, i64 0, !8, i64 8, !7, i64 16}
!13 = !{!6, !10, i64 20}
!14 = !{!6, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass