; LLVM IR from ziutek/emgo :: egroot/src/internal (equals)

; 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.string = type { ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @equals(ptr %0, i64 %1, ptr %2, i64 %3) #0 {
  %5 = alloca i8, align 1
  %6 = alloca %struct.string, align 8
  %7 = alloca %struct.string, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %10, align 8
  %11 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  store i64 %1, ptr %11, align 8
  %12 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %12, align 8
  %13 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  store i64 %3, ptr %13, align 8
  %14 = getelementptr inbounds %struct.string, ptr %6, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.string, ptr %7, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = icmp ne i64 %15, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i8 0, ptr %5, align 1
  br label %47

20:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %42, %20
  %22 = load i64, ptr %8, align 8, !tbaa !11
  %23 = getelementptr inbounds %struct.string, ptr %6, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %21
  %27 = getelementptr inbounds %struct.string, ptr %6, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = load i64, ptr %8, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = zext i8 %31 to i32
  %33 = getelementptr inbounds %struct.string, ptr %7, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = load i64, ptr %8, align 8, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = icmp ne i32 %32, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %26
  store i8 0, ptr %5, align 1
  store i32 1, ptr %9, align 4
  br label %46

41:                                               ; preds = %26
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %8, align 8, !tbaa !11
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %8, align 8, !tbaa !11
  br label %21, !llvm.loop !14

45:                                               ; preds = %21
  store i8 1, ptr %5, align 1
  store i32 1, ptr %9, align 4
  br label %46

46:                                               ; preds = %45, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %47

47:                                               ; preds = %46, %19
  %48 = load i8, ptr %5, align 1
  ret i8 %48
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local zeroext range(i8 0, 2) i8 @equals(ptr nocapture readonly %0, i64 %1, ptr nocapture readonly %2, i64 %3) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, %3
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %4
  %.not14 = icmp eq i64 %1, 0
  br i1 %.not14, label %.loopexit, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %6 = add nuw i64 %.011, 1
  %exitcond.not = icmp eq i64 %6, %1
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %5
  %.011 = phi i64 [ %6, %5 ], [ 0, %.preheader ]
  %7 = getelementptr inbounds i8, ptr %0, i64 %.011
  %8 = load i8, ptr %7, align 1, !tbaa !7
  %9 = getelementptr inbounds i8, ptr %2, i64 %.011
  %10 = load i8, ptr %9, align 1, !tbaa !7
  %.not10 = icmp eq i8 %8, %10
  br i1 %.not10, label %5, label %.loopexit

.loopexit:                                        ; preds = %5, %.lr.ph, %.preheader, %4
  %.1 = phi i8 [ 0, %4 ], [ 1, %.preheader ], [ 1, %5 ], [ 0, %.lr.ph ]
  ret i8 %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass