; 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_bool(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 %28

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
  %15 = icmp ne i32 %14, 5
  br i1 %15, label %16, label %19

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.cmp_ctx_s, ptr %17, i32 0, i32 0
  store i8 13, ptr %18, align 8, !tbaa !11
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %28

19:                                               ; preds = %11
  %20 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %21 = load i8, ptr %20, align 8, !tbaa !13, !range !14, !noundef !15
  %22 = trunc i8 %21 to i1
  br i1 %22, label %23, label %25

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 1, ptr %24, align 1, !tbaa !16
  br label %27

25:                                               ; preds = %19
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %26, align 1, !tbaa !16
  br label %27

27:                                               ; preds = %25, %23
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %28

28:                                               ; preds = %27, %16, %10
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  %29 = load i1, ptr %3, align 1
  ret i1 %29
}

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 = !{!12, !7, i64 0}
!12 = !{!"cmp_ctx_s", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}


; 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_bool(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 %11

5:                                                ; preds = %2
  %6 = load i8, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i8 %6, 5
  br i1 %.not, label %8, label %7

7:                                                ; preds = %5
  store i8 13, ptr %0, align 8, !tbaa !9
  br label %11

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

11:                                               ; preds = %2, %8, %7
  %.0 = phi i1 [ false, %7 ], [ true, %8 ], [ 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 = !{!10, !7, i64 0}
!10 = !{!"cmp_ctx_s", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !7, i64 0}


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