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

; 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.cmp_object_s = type { i8, %union.cmp_object_data_u }
%union.cmp_object_data_u = type { i64 }
%struct.cmp_ctx_s = type { i8, ptr, ptr, 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 dso_local zeroext i1 @cmp_read_object(ptr noundef, ptr noundef) #1

; 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 zeroext i1 @cmp_read_long(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.cmp_object_s, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call zeroext i1 @cmp_read_object(ptr noundef %8, ptr noundef %6)
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

11:                                               ; preds = %2
  %12 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 0
  %13 = load i8, ptr %12, align 8, !tbaa !9
  %14 = zext i8 %13 to i32
  switch i32 %14, label %58 [
    i32 0, label %15
    i32 34, label %15
    i32 18, label %15
    i32 14, label %20
    i32 19, label %25
    i32 15, label %30
    i32 20, label %35
    i32 16, label %40
    i32 21, label %45
    i32 17, label %49
  ]

15:                                               ; preds = %11, %11, %11
  %16 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %17 = load i8, ptr %16, align 8, !tbaa !11
  %18 = sext i8 %17 to i64
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %18, ptr %19, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

20:                                               ; preds = %11
  %21 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %22 = load i8, ptr %21, align 8, !tbaa !11
  %23 = zext i8 %22 to i64
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %23, ptr %24, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

25:                                               ; preds = %11
  %26 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %27 = load i16, ptr %26, align 8, !tbaa !11
  %28 = sext i16 %27 to i64
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %28, ptr %29, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

30:                                               ; preds = %11
  %31 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %32 = load i16, ptr %31, align 8, !tbaa !11
  %33 = zext i16 %32 to i64
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %33, ptr %34, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

35:                                               ; preds = %11
  %36 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %38, ptr %39, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

40:                                               ; preds = %11
  %41 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = zext i32 %42 to i64
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %43, ptr %44, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

45:                                               ; preds = %11
  %46 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %47, ptr %48, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

49:                                               ; preds = %11
  %50 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = icmp ule i64 %51, 9223372036854775807
  br i1 %52, label %53, label %57

53:                                               ; preds = %49
  %54 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %55, ptr %56, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

57:                                               ; preds = %49
  br label %58

58:                                               ; preds = %57, %11
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.cmp_ctx_s, ptr %59, i32 0, i32 0
  store i8 13, ptr %60, align 8, !tbaa !14
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

61:                                               ; preds = %58, %53, %45, %40, %35, %30, %25, %20, %15, %10
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  %62 = load i1, ptr %3, align 1
  ret i1 %62
}

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, !7, i64 0}
!10 = !{!"cmp_object_s", !7, i64 0, !7, i64 8}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"cmp_ctx_s", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}


; 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.cmp_object_s = type { i8, %union.cmp_object_data_u }
%union.cmp_object_data_u = type { i64 }

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cmp_read_object(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 noundef zeroext i1 @cmp_read_long(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca %struct.cmp_object_s, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  %4 = call zeroext i1 @cmp_read_object(ptr noundef %0, ptr noundef nonnull %3)
  br i1 %4, label %5, label %40

5:                                                ; preds = %2
  %6 = load i8, ptr %3, align 8, !tbaa !5
  switch i8 %6, label %39 [
    i8 0, label %7
    i8 34, label %7
    i8 18, label %7
    i8 14, label %11
    i8 19, label %15
    i8 15, label %19
    i8 20, label %23
    i8 16, label %27
    i8 21, label %31
    i8 17, label %34
  ]

7:                                                ; preds = %5, %5, %5
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  %9 = load i8, ptr %8, align 8, !tbaa !9
  %10 = sext i8 %9 to i64
  store i64 %10, ptr %1, align 8, !tbaa !10
  br label %40

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  %13 = load i8, ptr %12, align 8, !tbaa !9
  %14 = zext i8 %13 to i64
  store i64 %14, ptr %1, align 8, !tbaa !10
  br label %40

15:                                               ; preds = %5
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = load i16, ptr %16, align 8, !tbaa !9
  %18 = sext i16 %17 to i64
  store i64 %18, ptr %1, align 8, !tbaa !10
  br label %40

19:                                               ; preds = %5
  %20 = getelementptr inbounds i8, ptr %3, i64 8
  %21 = load i16, ptr %20, align 8, !tbaa !9
  %22 = zext i16 %21 to i64
  store i64 %22, ptr %1, align 8, !tbaa !10
  br label %40

23:                                               ; preds = %5
  %24 = getelementptr inbounds i8, ptr %3, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %1, align 8, !tbaa !10
  br label %40

27:                                               ; preds = %5
  %28 = getelementptr inbounds i8, ptr %3, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = zext i32 %29 to i64
  store i64 %30, ptr %1, align 8, !tbaa !10
  br label %40

31:                                               ; preds = %5
  %32 = getelementptr inbounds i8, ptr %3, i64 8
  %33 = load i64, ptr %32, align 8, !tbaa !9
  store i64 %33, ptr %1, align 8, !tbaa !10
  br label %40

34:                                               ; preds = %5
  %35 = getelementptr inbounds i8, ptr %3, i64 8
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = icmp sgt i64 %36, -1
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i64 %36, ptr %1, align 8, !tbaa !10
  br label %40

39:                                               ; preds = %34, %5
  store i8 13, ptr %0, align 8, !tbaa !12
  br label %40

40:                                               ; preds = %2, %39, %38, %31, %27, %23, %19, %15, %11, %7
  %.0 = phi i1 [ false, %39 ], [ true, %38 ], [ true, %31 ], [ true, %27 ], [ true, %23 ], [ true, %19 ], [ true, %15 ], [ true, %11 ], [ true, %7 ], [ false, %2 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  ret i1 %.0
}

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"cmp_object_s", !7, i64 0, !7, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"cmp_ctx_s", !7, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!14 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass