; LLVM IR from Nonoum/ECL :: ECL_common (ECL_JH_Read_E2)

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

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

; 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
declare dso_local zeroext i8 @ECL_JH_Read(ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ECL_JH_Read_E2(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 0, ptr %4, align 1, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !10
  br label %7

7:                                                ; preds = %31, %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call zeroext i8 @ECL_JH_Read(ptr noundef %8, i8 noundef zeroext 3)
  store i8 %9, ptr %5, align 1, !tbaa !9
  %10 = load i8, ptr %5, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = and i32 %11, 3
  %13 = load i8, ptr %4, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = shl i32 %12, %14
  %16 = load i32, ptr %3, align 4, !tbaa !10
  %17 = or i32 %16, %15
  store i32 %17, ptr %3, align 4, !tbaa !10
  %18 = load i8, ptr %5, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = and i32 %19, 4
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %7
  store i32 2, ptr %6, align 4
  br label %28

23:                                               ; preds = %7
  %24 = load i8, ptr %4, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = add nsw i32 %25, 2
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %4, align 1, !tbaa !9
  store i32 0, ptr %6, align 4
  br label %28

28:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  %29 = load i32, ptr %6, align 4
  switch i32 %29, label %37 [
    i32 0, label %30
    i32 2, label %35
  ]

30:                                               ; preds = %28
  br label %31

31:                                               ; preds = %30
  %32 = load i8, ptr %4, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = icmp slt i32 %33, 32
  br i1 %34, label %7, label %35, !llvm.loop !12

35:                                               ; preds = %31, %28
  %36 = load i32, ptr %3, align 4, !tbaa !10
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %36

37:                                               ; preds = %28
  unreachable
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nounwind uwtable
declare dso_local zeroext i8 @ECL_JH_Read(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ECL_JH_Read_E2(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %2, %1
  %.09 = phi i8 [ 0, %1 ], [ %.1, %2 ]
  %.08 = phi i32 [ 0, %1 ], [ %8, %2 ]
  %3 = tail call zeroext i8 @ECL_JH_Read(ptr noundef %0, i8 noundef zeroext 3)
  %4 = zext i8 %3 to i32
  %5 = and i32 %4, 3
  %6 = zext nneg i8 %.09 to i32
  %7 = shl i32 %5, %6
  %8 = or i32 %7, %.08
  %9 = and i32 %4, 4
  %.not = icmp ne i32 %9, 0
  %10 = add nuw nsw i8 %.09, 2
  %.1 = select i1 %.not, i8 %10, i8 %.09
  %11 = icmp ult i8 %.1, 32
  %or.cond = select i1 %.not, i1 %11, i1 false
  br i1 %or.cond, label %2, label %12, !llvm.loop !5

12:                                               ; preds = %2
  ret i32 %8
}

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

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass