; LLVM IR from cvra/robot-software :: lib/trace (trace)

; 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.trace_buffer_struct = type { i8, i64, i64, [200 x %struct.trace_event] }
%struct.trace_event = type { i32, %union.anon }
%union.anon = type { ptr }

@trace_buffer = external dso_local global %struct.trace_buffer_struct, align 8
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@trace_point_names = external global [0 x ptr], align 8
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; 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 @trace_print(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  store volatile i8 0, ptr @trace_buffer, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load volatile i64, ptr getelementptr inbounds (%struct.trace_buffer_struct, ptr @trace_buffer, i32 0, i32 2), align 8, !tbaa !13
  %9 = icmp eq i64 %8, 200
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = load volatile i64, ptr getelementptr inbounds (%struct.trace_buffer_struct, ptr @trace_buffer, i32 0, i32 1), align 8, !tbaa !14
  store i64 %11, ptr %6, align 8, !tbaa !15
  br label %13

12:                                               ; preds = %2
  store i64 0, ptr %6, align 8, !tbaa !15
  br label %13

13:                                               ; preds = %12, %10
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %14

14:                                               ; preds = %65, %13
  %15 = load i64, ptr %5, align 8, !tbaa !15
  %16 = load volatile i64, ptr getelementptr inbounds (%struct.trace_buffer_struct, ptr @trace_buffer, i32 0, i32 2), align 8, !tbaa !13
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %68

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %19 = load i64, ptr %6, align 8, !tbaa !15
  %20 = getelementptr inbounds [200 x %struct.trace_event], ptr getelementptr inbounds (%struct.trace_buffer_struct, ptr @trace_buffer, i32 0, i32 3), i64 0, i64 %19
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load volatile i32, ptr %23, align 8
  %25 = lshr i32 %24, 10
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load volatile i32, ptr %26, align 8
  %28 = and i32 %27, 255
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [0 x ptr], ptr @trace_point_names, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  call void (ptr, ptr, ...) %21(ptr noundef %22, ptr noundef @.str.1, i32 noundef %25, ptr noundef %31)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load volatile i32, ptr %32, align 8
  %34 = lshr i32 %33, 8
  %35 = and i32 %34, 3
  switch i32 %35, label %61 [
    i32 0, label %36
    i32 1, label %42
    i32 2, label %48
    i32 3, label %55
  ]

36:                                               ; preds = %18
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.trace_event, ptr %39, i32 0, i32 1
  %41 = load volatile ptr, ptr %40, align 8, !tbaa !16
  call void (ptr, ptr, ...) %37(ptr noundef %38, ptr noundef @.str.2, ptr noundef %41)
  br label %61

42:                                               ; preds = %18
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.trace_event, ptr %45, i32 0, i32 1
  %47 = load volatile ptr, ptr %46, align 8, !tbaa !16
  call void (ptr, ptr, ...) %43(ptr noundef %44, ptr noundef @.str.3, ptr noundef %47)
  br label %61

48:                                               ; preds = %18
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.trace_event, ptr %51, i32 0, i32 1
  %53 = load volatile float, ptr %52, align 8, !tbaa !16
  %54 = fpext float %53 to double
  call void (ptr, ptr, ...) %49(ptr noundef %50, ptr noundef @.str.4, double noundef %54)
  br label %61

55:                                               ; preds = %18
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.trace_event, ptr %58, i32 0, i32 1
  %60 = load volatile i32, ptr %59, align 8, !tbaa !16
  call void (ptr, ptr, ...) %56(ptr noundef %57, ptr noundef @.str.5, i32 noundef %60)
  br label %61

61:                                               ; preds = %55, %48, %42, %36, %18
  %62 = load i64, ptr %6, align 8, !tbaa !15
  %63 = add i64 %62, 1
  %64 = urem i64 %63, 200
  store i64 %64, ptr %6, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %65

65:                                               ; preds = %61
  %66 = load i64, ptr %5, align 8, !tbaa !15
  %67 = add i64 %66, 1
  store i64 %67, ptr %5, align 8, !tbaa !15
  br label %14, !llvm.loop !17

68:                                               ; preds = %14
  store volatile i8 1, ptr @trace_buffer, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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, !11, i64 0}
!10 = !{!"trace_buffer_struct", !11, i64 0, !12, i64 8, !12, i64 16, !7, i64 24}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 16}
!14 = !{!10, !12, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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.trace_buffer_struct = type { i8, i64, i64, [200 x %struct.trace_event] }
%struct.trace_event = type { i32, %union.anon }
%union.anon = type { ptr }

@trace_buffer = external dso_local global %struct.trace_buffer_struct, align 8
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@trace_point_names = external local_unnamed_addr global [0 x ptr], align 8
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @trace_print(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  store volatile i8 0, ptr @trace_buffer, align 8, !tbaa !5
  %3 = load volatile i64, ptr getelementptr inbounds (i8, ptr @trace_buffer, i64 16), align 8, !tbaa !11
  %4 = icmp eq i64 %3, 200
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = load volatile i64, ptr getelementptr inbounds (i8, ptr @trace_buffer, i64 8), align 8, !tbaa !12
  br label %7

7:                                                ; preds = %2, %5
  %.020 = phi i64 [ %6, %5 ], [ 0, %2 ]
  %8 = load volatile i64, ptr getelementptr inbounds (i8, ptr @trace_buffer, i64 16), align 8, !tbaa !11
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %30
  %.022 = phi i64 [ %33, %30 ], [ 0, %7 ]
  %.121 = phi i64 [ %32, %30 ], [ %.020, %7 ]
  %9 = getelementptr inbounds [200 x %struct.trace_event], ptr getelementptr inbounds (i8, ptr @trace_buffer, i64 24), i64 0, i64 %.121
  %10 = load volatile i32, ptr %9, align 8
  %11 = lshr i32 %10, 10
  %12 = load volatile i32, ptr %9, align 8
  %13 = and i32 %12, 255
  %14 = zext nneg i32 %13 to i64
  %15 = getelementptr inbounds [0 x ptr], ptr @trace_point_names, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  tail call void (ptr, ptr, ...) %0(ptr noundef %1, ptr noundef nonnull @.str.1, i32 noundef %11, ptr noundef %16) #1
  %17 = load volatile i32, ptr %9, align 8
  %18 = lshr i32 %17, 8
  %19 = and i32 %18, 3
  %20 = getelementptr inbounds i8, ptr %9, i64 8
  switch i32 %19, label %default.unreachable23 [
    i32 0, label %21
    i32 1, label %23
    i32 2, label %25
    i32 3, label %28
  ]

21:                                               ; preds = %.lr.ph
  %22 = load volatile ptr, ptr %20, align 8, !tbaa !15
  tail call void (ptr, ptr, ...) %0(ptr noundef %1, ptr noundef nonnull @.str.2, ptr noundef %22) #1
  br label %30

23:                                               ; preds = %.lr.ph
  %24 = load volatile ptr, ptr %20, align 8, !tbaa !15
  tail call void (ptr, ptr, ...) %0(ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef %24) #1
  br label %30

25:                                               ; preds = %.lr.ph
  %26 = load volatile float, ptr %20, align 8, !tbaa !15
  %27 = fpext float %26 to double
  tail call void (ptr, ptr, ...) %0(ptr noundef %1, ptr noundef nonnull @.str.4, double noundef %27) #1
  br label %30

28:                                               ; preds = %.lr.ph
  %29 = load volatile i32, ptr %20, align 8, !tbaa !15
  tail call void (ptr, ptr, ...) %0(ptr noundef %1, ptr noundef nonnull @.str.5, i32 noundef %29) #1
  br label %30

default.unreachable23:                            ; preds = %.lr.ph
  unreachable

30:                                               ; preds = %28, %25, %23, %21
  %31 = add i64 %.121, 1
  %32 = urem i64 %31, 200
  %33 = add nuw i64 %.022, 1
  %34 = load volatile i64, ptr getelementptr inbounds (i8, ptr @trace_buffer, i64 16), align 8, !tbaa !11
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %30, %7
  store volatile i8 1, ptr @trace_buffer, align 8, !tbaa !5
  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 = { 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, !7, i64 0}
!6 = !{!"trace_buffer_struct", !7, i64 0, !10, i64 8, !10, i64 16, !8, i64 24}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass