; 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_int(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 %51

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 %48 [
    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 %39
  ]

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

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

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

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 i32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %33, ptr %34, align 4, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %51

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 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %37, ptr %38, align 4, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %51

39:                                               ; preds = %11
  %40 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = icmp ule i32 %41, 2147483647
  br i1 %42, label %43, label %47

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

47:                                               ; preds = %39
  br label %48

48:                                               ; preds = %47, %11
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.cmp_ctx_s, ptr %49, i32 0, i32 0
  store i8 13, ptr %50, align 8, !tbaa !14
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %51

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

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 = !{!"int", !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_int(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 %32

5:                                                ; preds = %2
  %6 = load i8, ptr %3, align 8, !tbaa !5
  switch i8 %6, label %31 [
    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 %26
  ]

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 i32
  store i32 %10, ptr %1, align 4, !tbaa !10
  br label %32

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 i32
  store i32 %14, ptr %1, align 4, !tbaa !10
  br label %32

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 i32
  store i32 %18, ptr %1, align 4, !tbaa !10
  br label %32

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 i32
  store i32 %22, ptr %1, align 4, !tbaa !10
  br label %32

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

26:                                               ; preds = %5
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = icmp sgt i32 %28, -1
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  store i32 %28, ptr %1, align 4, !tbaa !10
  br label %32

31:                                               ; preds = %26, %5
  store i8 13, ptr %0, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %2, %31, %30, %23, %19, %15, %11, %7
  %.0 = phi i1 [ false, %31 ], [ true, %30 ], [ 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 = !{!"int", !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