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

; 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(ptr noundef, ptr noundef) #2

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

declare void @mrb_free(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_ary_clear(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 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %8, align 8
  %9 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %2, ptr %9, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ary_modify(ptr noundef %12, ptr noundef %13)
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 8
  %16 = lshr i32 %15, 11
  %17 = and i32 %16, 256
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %34

19:                                               ; preds = %3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.RArray, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds %struct.anon, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  call void @mrb_ary_decref(ptr noundef %20, ptr noundef %24)
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 8
  %27 = lshr i32 %26, 11
  %28 = and i32 %27, -257
  %29 = load i32, ptr %25, align 8
  %30 = and i32 %28, 2097151
  %31 = shl i32 %30, 11
  %32 = and i32 %29, 2047
  %33 = or i32 %32, %31
  store i32 %33, ptr %25, align 8
  br label %47

34:                                               ; preds = %3
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 8
  %37 = lshr i32 %36, 11
  %38 = and i32 %37, 7
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %46, label %40

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.RArray, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  call void @mrb_free(ptr noundef %41, ptr noundef %45)
  br label %46

46:                                               ; preds = %40, %34
  br label %47

47:                                               ; preds = %46, %19
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 8
  %50 = lshr i32 %49, 11
  %51 = and i32 %50, -8
  %52 = or i32 %51, 1
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 8
  %55 = and i32 %52, 2097151
  %56 = shl i32 %55, 11
  %57 = and i32 %54, 2047
  %58 = or i32 %57, %56
  store i32 %58, ptr %53, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %59 = load { i64, i32 }, ptr %4, align 8
  ret { i64, i32 } %59
}

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 = { "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 = !{i64 0, i64 8, !9, i64 8, i64 4, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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(ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare void @mrb_free(ptr noundef, ptr noundef) local_unnamed_addr #1

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

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 32
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  tail call void @mrb_ary_decref(ptr noundef %0, ptr noundef %8)
  %9 = load i32, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  %10 = and i32 %9, -524289
  br label %16

11:                                               ; preds = %3
  %12 = and i32 %4, 14336
  %.not13 = icmp eq i32 %12, 0
  br i1 %.not13, label %13, label %16

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %.sroa.0.0..sroa.0.0..cast, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  tail call void @mrb_free(ptr noundef %0, ptr noundef %15) #2
  %.pre = load i32, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  br label %16

16:                                               ; preds = %11, %13, %6
  %17 = phi i32 [ %4, %11 ], [ %.pre, %13 ], [ %10, %6 ]
  %18 = and i32 %17, -14337
  %19 = or disjoint i32 %18, 2048
  store i32 %19, ptr %.sroa.0.0..sroa.0.0..cast, align 8
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %1, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %2, 1
  ret { i64, i32 } %.fca.1.insert
}

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass