; LLVM IR from fcambus/logswan :: deps/hll (hll)

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #0

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @hll_merge(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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 4, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.HLL, ptr %8, i32 0, i32 0
  %10 = load i8, ptr %9, align 8, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.HLL, ptr %12, i32 0, i32 0
  %14 = load i8, ptr %13, align 8, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = icmp ne i32 %11, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %2
  %18 = call ptr @__errno_location() #4
  store i32 22, ptr %18, align 4, !tbaa !12
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %64

19:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %60, %19
  %21 = load i32, ptr %6, align 4, !tbaa !12
  %22 = zext i32 %21 to i64
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.HLL, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = icmp ult i64 %22, %25
  br i1 %26, label %27, label %63

27:                                               ; preds = %20
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.HLL, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load i32, ptr %6, align 4, !tbaa !12
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !16
  %35 = zext i8 %34 to i32
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.HLL, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i32, ptr %6, align 4, !tbaa !12
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !16
  %43 = zext i8 %42 to i32
  %44 = icmp sgt i32 %35, %43
  br i1 %44, label %45, label %59

45:                                               ; preds = %27
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.HLL, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = load i32, ptr %6, align 4, !tbaa !12
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !16
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.HLL, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = load i32, ptr %6, align 4, !tbaa !12
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  store i8 %52, ptr %58, align 1, !tbaa !16
  br label %59

59:                                               ; preds = %45, %27
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %6, align 4, !tbaa !12
  %62 = add i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !12
  br label %20, !llvm.loop !17

63:                                               ; preds = %20
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %64

64:                                               ; preds = %63, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

attributes #0 = { nounwind willreturn memory(none) "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 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(none) }

!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 = !{!"HLL", !7, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !6, i64 16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #0

; Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @hll_merge(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load i8, ptr %0, align 8, !tbaa !5
  %4 = load i8, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i8 %3, %4
  br i1 %.not, label %.preheader, label %9

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %.not16 = icmp eq i64 %6, 0
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  br label %11

9:                                                ; preds = %2
  %10 = tail call ptr @__errno_location() #2
  store i32 22, ptr %10, align 4, !tbaa !12
  br label %.loopexit

11:                                               ; preds = %.lr.ph, %22
  %12 = phi i64 [ %6, %.lr.ph ], [ %23, %22 ]
  %13 = phi i64 [ 0, %.lr.ph ], [ %25, %22 ]
  %.015 = phi i32 [ 0, %.lr.ph ], [ %24, %22 ]
  %14 = load ptr, ptr %7, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 %13
  %16 = load i8, ptr %15, align 1, !tbaa !15
  %17 = load ptr, ptr %8, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 %13
  %19 = load i8, ptr %18, align 1, !tbaa !15
  %20 = icmp ugt i8 %16, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %11
  store i8 %16, ptr %18, align 1, !tbaa !15
  %.pre = load i64, ptr %5, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %11, %21
  %23 = phi i64 [ %12, %11 ], [ %.pre, %21 ]
  %24 = add i32 %.015, 1
  %25 = zext i32 %24 to i64
  %26 = icmp ugt i64 %23, %25
  br i1 %26, label %11, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %22, %.preheader, %9
  %.013 = phi i32 [ -1, %9 ], [ 0, %.preheader ], [ 0, %22 ]
  ret i32 %.013
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nofree nosync nounwind memory(readwrite, inaccessiblemem: none) 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 willreturn memory(none) }

!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 = !{!"HLL", !7, i64 0, !9, i64 8, !10, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !9, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass