; 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_short(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 %42

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 %39 [
    i32 0, label %15
    i32 34, label %15
    i32 18, label %15
    i32 14, label %20
    i32 19, label %25
    i32 15, label %29
  ]

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 i16
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  store i16 %18, ptr %19, align 2, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %42

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 i16
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store i16 %23, ptr %24, align 2, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %42

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 = load ptr, ptr %5, align 8, !tbaa !5
  store i16 %27, ptr %28, align 2, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %42

29:                                               ; preds = %11
  %30 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %31 = load i16, ptr %30, align 8, !tbaa !11
  %32 = zext i16 %31 to i32
  %33 = icmp sle i32 %32, 32767
  br i1 %33, label %34, label %38

34:                                               ; preds = %29
  %35 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %36 = load i16, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  store i16 %36, ptr %37, align 2, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %42

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %38, %11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.cmp_ctx_s, ptr %40, i32 0, i32 0
  store i8 13, ptr %41, align 8, !tbaa !14
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %42

42:                                               ; preds = %39, %34, %25, %20, %15, %10
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  %43 = load i1, ptr %3, align 1
  ret i1 %43
}

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 = !{!"short", !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_short(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 %24

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

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 i16
  store i16 %10, ptr %1, align 2, !tbaa !10
  br label %24

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 i16
  store i16 %14, ptr %1, align 2, !tbaa !10
  br label %24

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

18:                                               ; preds = %5
  %19 = getelementptr inbounds i8, ptr %3, i64 8
  %20 = load i16, ptr %19, align 8, !tbaa !9
  %21 = icmp sgt i16 %20, -1
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  store i16 %20, ptr %1, align 2, !tbaa !10
  br label %24

23:                                               ; preds = %18, %5
  store i8 13, ptr %0, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %2, %23, %22, %15, %11, %7
  %.0 = phi i1 [ false, %23 ], [ true, %22 ], [ 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 = !{!"short", !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