; 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_char(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 %32

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

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

19:                                               ; preds = %11
  %20 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %21 = load i8, ptr %20, align 8, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = icmp sle i32 %22, 127
  br i1 %23, label %24, label %28

24:                                               ; preds = %19
  %25 = getelementptr inbounds %struct.cmp_object_s, ptr %6, i32 0, i32 1
  %26 = load i8, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !11
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %32

28:                                               ; preds = %19
  br label %29

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

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

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, !7, i64 0}
!13 = !{!"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_char(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 %16

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

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

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

14:                                               ; preds = %10
  store i8 %12, ptr %1, align 1, !tbaa !9
  br label %16

15:                                               ; preds = %10, %5
  store i8 13, ptr %0, align 8, !tbaa !10
  br label %16

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


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