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

; 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.mrb_value = type { %union.anon, i32 }
%union.anon = type { double }
%struct.RArray = type { i32, ptr, ptr, %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { i64, %union.anon.1, ptr }
%union.anon.1 = type { i64 }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @ary_modify_check(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i32 } @mrb_nil_value() #3

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_ary_shift(ptr noundef %0, i64 %1, i32 %2) #2 {
  %4 = alloca %struct.mrb_value, align 8
  %5 = alloca %struct.mrb_value, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.mrb_value, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %13, align 8
  %14 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %2, ptr %14, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %15 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 8
  %19 = lshr i32 %18, 11
  %20 = and i32 %19, 7
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %3
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 8
  %25 = lshr i32 %24, 11
  %26 = and i32 %25, 7
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  br label %34

29:                                               ; preds = %3
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.RArray, ptr %30, i32 0, i32 3
  %32 = getelementptr inbounds %struct.anon, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %29, %22
  %35 = phi i64 [ %28, %22 ], [ %33, %29 ]
  store i64 %35, ptr %8, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ary_modify_check(ptr noundef %36, ptr noundef %37)
  %38 = load i64, ptr %8, align 8, !tbaa !10
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %34
  %41 = call { i64, i32 } @mrb_nil_value()
  %42 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %43 = extractvalue { i64, i32 } %41, 0
  store i64 %43, ptr %42, align 8
  %44 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %45 = extractvalue { i64, i32 } %41, 1
  store i32 %45, ptr %44, align 8
  store i32 1, ptr %10, align 4
  br label %137

46:                                               ; preds = %34
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %47, align 8
  %49 = lshr i32 %48, 11
  %50 = and i32 %49, 256
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %69

52:                                               ; preds = %46
  br label %53

53:                                               ; preds = %72, %52
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.RArray, ptr %54, i32 0, i32 3
  %56 = getelementptr inbounds %struct.anon, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.mrb_value, ptr %57, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %58, i64 16, i1 false), !tbaa.struct !12
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.RArray, ptr %59, i32 0, i32 3
  %61 = getelementptr inbounds %struct.anon, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.mrb_value, ptr %62, i32 1
  store ptr %63, ptr %61, align 8, !tbaa !9
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.RArray, ptr %64, i32 0, i32 3
  %66 = getelementptr inbounds %struct.anon, ptr %65, i32 0, i32 0
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = add nsw i64 %67, -1
  store i64 %68, ptr %66, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %9, i64 16, i1 false), !tbaa.struct !12
  store i32 1, ptr %10, align 4
  br label %137

69:                                               ; preds = %46
  %70 = load i64, ptr %8, align 8, !tbaa !10
  %71 = icmp sgt i64 %70, 10
  br i1 %71, label %72, label %75

72:                                               ; preds = %69
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ary_make_shared(ptr noundef %73, ptr noundef %74)
  br label %53

75:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i32, ptr %76, align 8
  %78 = lshr i32 %77, 11
  %79 = and i32 %78, 7
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %85

81:                                               ; preds = %75
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.RArray, ptr %82, i32 0, i32 3
  %84 = getelementptr inbounds [1 x %struct.mrb_value], ptr %83, i64 0, i64 0
  br label %90

85:                                               ; preds = %75
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.RArray, ptr %86, i32 0, i32 3
  %88 = getelementptr inbounds %struct.anon, ptr %87, i32 0, i32 2
  %89 = load ptr, ptr %88, align 8, !tbaa !9
  br label %90

90:                                               ; preds = %85, %81
  %91 = phi ptr [ %84, %81 ], [ %89, %85 ]
  store ptr %91, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %92 = load i64, ptr %8, align 8, !tbaa !10
  store i64 %92, ptr %12, align 8, !tbaa !10
  %93 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %93, i64 16, i1 false), !tbaa.struct !12
  br label %94

94:                                               ; preds = %98, %90
  %95 = load i64, ptr %12, align 8, !tbaa !10
  %96 = add nsw i64 %95, -1
  store i64 %96, ptr %12, align 8, !tbaa !10
  %97 = icmp ne i64 %96, 0
  br i1 %97, label %98, label %104

98:                                               ; preds = %94
  %99 = load ptr, ptr %11, align 8, !tbaa !5
  %100 = load ptr, ptr %11, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.mrb_value, ptr %100, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %99, ptr align 8 %101, i64 16, i1 false), !tbaa.struct !12
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.mrb_value, ptr %102, i32 1
  store ptr %103, ptr %11, align 8, !tbaa !5
  br label %94, !llvm.loop !15

104:                                              ; preds = %94
  br label %105

105:                                              ; preds = %104
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = load i32, ptr %106, align 8
  %108 = lshr i32 %107, 11
  %109 = and i32 %108, 7
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %127

111:                                              ; preds = %105
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = load i32, ptr %112, align 8
  %114 = lshr i32 %113, 11
  %115 = and i32 %114, -8
  %116 = load i64, ptr %8, align 8, !tbaa !10
  %117 = sub nsw i64 %116, 1
  %118 = trunc i64 %117 to i32
  %119 = add i32 %118, 1
  %120 = or i32 %115, %119
  %121 = load ptr, ptr %7, align 8, !tbaa !5
  %122 = load i32, ptr %121, align 8
  %123 = and i32 %120, 2097151
  %124 = shl i32 %123, 11
  %125 = and i32 %122, 2047
  %126 = or i32 %125, %124
  store i32 %126, ptr %121, align 8
  br label %133

127:                                              ; preds = %105
  %128 = load i64, ptr %8, align 8, !tbaa !10
  %129 = sub nsw i64 %128, 1
  %130 = load ptr, ptr %7, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.RArray, ptr %130, i32 0, i32 3
  %132 = getelementptr inbounds %struct.anon, ptr %131, i32 0, i32 0
  store i64 %129, ptr %132, align 8, !tbaa !9
  br label %133

133:                                              ; preds = %127, %111
  br label %134

134:                                              ; preds = %133
  br label %135

135:                                              ; preds = %134
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %136

136:                                              ; preds = %135
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %9, i64 16, i1 false), !tbaa.struct !12
  store i32 1, ptr %10, align 4
  br label %137

137:                                              ; preds = %136, %53, %40
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %138 = load { i64, i32 }, ptr %4, align 8
  ret { i64, i32 } %138
}

; Function Attrs: nounwind uwtable
declare hidden void @ary_make_shared(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { inlinehint 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 #4 = { 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 = !{!"long", !7, i64 0}
!12 = !{i64 0, i64 8, !9, i64 8, i64 4, !13}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 hidden void @ary_modify_check(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i32 } @mrb_nil_value() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_ary_shift(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %.sroa.0.0..sroa.0.0..cast = inttoptr i64 %1 to ptr
  %4 = load i32, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  %5 = lshr i32 %4, 11
  %6 = and i32 %5, 7
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %10, label %7

7:                                                ; preds = %3
  %8 = add nsw i32 %6, -1
  %9 = zext nneg i32 %8 to i64
  br label %13

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 24
  %12 = load i64, ptr %11, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %10, %7
  %14 = phi i64 [ %9, %7 ], [ %12, %10 ]
  tail call void @ary_modify_check(ptr noundef %0, ptr noundef nonnull %.sroa.0.0..sroa.0.0..cast)
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %20

16:                                               ; preds = %13
  %17 = tail call { i64, i32 } @mrb_nil_value()
  %18 = extractvalue { i64, i32 } %17, 0
  %19 = extractvalue { i64, i32 } %17, 1
  br label %54

20:                                               ; preds = %13
  %21 = load i32, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  %22 = and i32 %21, 524288
  %.not43 = icmp eq i32 %22, 0
  br i1 %.not43, label %30, label %23

23:                                               ; preds = %20, %32
  %24 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 24
  %25 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %.sroa.033.0.copyload = load i64, ptr %26, align 8, !tbaa !5
  %.sroa.635.0..sroa_idx = getelementptr inbounds i8, ptr %26, i64 8
  %.sroa.635.0.copyload = load i32, ptr %.sroa.635.0..sroa_idx, align 8, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  store ptr %27, ptr %25, align 8, !tbaa !5
  %28 = load i64, ptr %24, align 8, !tbaa !5
  %29 = add nsw i64 %28, -1
  store i64 %29, ptr %24, align 8, !tbaa !5
  br label %54

30:                                               ; preds = %20
  %31 = icmp sgt i64 %14, 10
  br i1 %31, label %32, label %33

32:                                               ; preds = %30
  tail call void @ary_make_shared(ptr noundef %0, ptr noundef nonnull %.sroa.0.0..sroa.0.0..cast)
  br label %23

33:                                               ; preds = %30
  %34 = and i32 %21, 14336
  %.not44 = icmp eq i32 %34, 0
  br i1 %.not44, label %37, label %35

35:                                               ; preds = %33
  %36 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 24
  br label %40

37:                                               ; preds = %33
  %38 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 40
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %37, %35
  %41 = phi ptr [ %36, %35 ], [ %39, %37 ]
  %.sroa.033.0.copyload34 = load i64, ptr %41, align 8, !tbaa !5
  %.sroa.635.0..0..sroa_idx = getelementptr inbounds i8, ptr %41, i64 8
  %.sroa.635.0.copyload36 = load i32, ptr %.sroa.635.0..0..sroa_idx, align 8, !tbaa !8
  %42 = add nsw i64 %14, -1
  %.not4547 = icmp eq i64 %42, 0
  br i1 %.not4547, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %40
  %scevgep = getelementptr i8, ptr %41, i64 16
  %43 = shl i64 %14, 4
  %44 = add i64 %43, -16
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %41, ptr align 8 %scevgep, i64 %44, i1 false)
  %.pre = load i32, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %40
  %45 = phi i32 [ %.pre, %.lr.ph.preheader ], [ %21, %40 ]
  %46 = and i32 %45, 14336
  %.not46 = icmp eq i32 %46, 0
  br i1 %.not46, label %52, label %47

47:                                               ; preds = %._crit_edge
  %48 = trunc i64 %14 to i32
  %49 = shl i32 %48, 11
  %50 = and i32 %45, -14337
  %51 = or i32 %50, %49
  store i32 %51, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  br label %54

52:                                               ; preds = %._crit_edge
  %53 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 24
  store i64 %42, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %47, %52, %23, %16
  %.sroa.4.0 = phi i32 [ %19, %16 ], [ %.sroa.635.0.copyload, %23 ], [ %.sroa.635.0.copyload36, %52 ], [ %.sroa.635.0.copyload36, %47 ]
  %.sroa.027.0 = phi i64 [ %18, %16 ], [ %.sroa.033.0.copyload, %23 ], [ %.sroa.033.0.copyload34, %52 ], [ %.sroa.033.0.copyload34, %47 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.027.0, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.4.0, 1
  ret { i64, i32 } %.fca.1.insert
}

; Function Attrs: nounwind uwtable
declare hidden void @ary_make_shared(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass