; LLVM IR from devantler/software-engineering-f22-shared :: IOT/BudgetManagementExcercise-03-28/ESP-Project/components/components/nghttp (p)

; 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
define dso_local zeroext i8 @mrb_ident_p(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %46, %2
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %7, align 4
  br label %49

13:                                               ; preds = %8
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %14, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = or i32 %18, 32
  %20 = sub i32 %19, 97
  %21 = icmp ult i32 %20, 26
  br i1 %21, label %45, label %22

22:                                               ; preds = %13
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = sub i32 %27, 48
  %29 = icmp ult i32 %28, 10
  br i1 %29, label %45, label %30

30:                                               ; preds = %22
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %35, 95
  br i1 %36, label %45, label %37

37:                                               ; preds = %30
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %38, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = icmp ule i32 %42, 127
  br i1 %43, label %44, label %45

44:                                               ; preds = %37
  store i8 0, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %49

45:                                               ; preds = %37, %30, %22, %13
  br label %46

46:                                               ; preds = %45
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %6, align 8, !tbaa !9
  br label %8, !llvm.loop !12

49:                                               ; preds = %44, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %50 = load i32, ptr %7, align 4
  switch i32 %50, label %54 [
    i32 2, label %51
    i32 1, label %52
  ]

51:                                               ; preds = %49
  store i8 1, ptr %3, align 1
  br label %52

52:                                               ; preds = %51, %49
  %53 = load i8, ptr %3, align 1
  ret i8 %53

54:                                               ; preds = %49
  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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local zeroext range(i8 0, 2) i8 @mrb_ident_p(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not22 = icmp slt i64 %1, 1
  br i1 %.not22, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %4 = sext i8 %3 to i32
  %5 = or i32 %4, 32
  %6 = add nsw i32 %5, -123
  %7 = icmp ult i32 %6, -26
  %8 = add nsw i32 %4, -58
  %9 = icmp ult i32 %8, -10
  %or.cond.not2127 = select i1 %7, i1 %9, i1 false
  %10 = icmp ne i8 %3, 95
  %or.cond16.not1828 = and i1 %10, %or.cond.not2127
  %11 = icmp sgt i8 %3, -1
  %or.cond1729 = and i1 %11, %or.cond16.not1828
  br i1 %or.cond1729, label %._crit_edge, label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0122330 = phi i64 [ %12, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %12 = add nuw nsw i64 %.0122330, 1
  %exitcond = icmp eq i64 %12, %1
  br i1 %exitcond, label %._crit_edge.loopexit.loopexit, label %.lr.ph, !llvm.loop !8

.lr.ph:                                           ; preds = %.lr.ph31
  %13 = getelementptr inbounds i8, ptr %0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = sext i8 %14 to i32
  %16 = or i32 %15, 32
  %17 = add nsw i32 %16, -123
  %18 = icmp ult i32 %17, -26
  %19 = add nsw i32 %15, -58
  %20 = icmp ult i32 %19, -10
  %or.cond.not21 = select i1 %18, i1 %20, i1 false
  %21 = icmp ne i8 %14, 95
  %or.cond16.not18 = and i1 %21, %or.cond.not21
  %22 = icmp sgt i8 %14, -1
  %or.cond17 = and i1 %22, %or.cond16.not18
  br i1 %or.cond17, label %._crit_edge.loopexit.loopexit, label %.lr.ph31, !llvm.loop !8

._crit_edge.loopexit.loopexit:                    ; preds = %.lr.ph, %.lr.ph31
  %.not.le = icmp sge i64 %12, %1
  %23 = zext i1 %.not.le to i8
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %._crit_edge.loopexit.loopexit, %2
  %.not.lcssa = phi i8 [ 1, %2 ], [ 0, %.lr.ph.preheader ], [ %23, %._crit_edge.loopexit.loopexit ]
  ret i8 %.not.lcssa
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass