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

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

@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1

; 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 { i64, i32 } @mrb_ary_new_from_values(ptr noundef, i64 noundef, ptr noundef) #1

; 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) #2

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

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

17:                                               ; preds = %3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call i32 @mrb_intern_static(ptr noundef %19, ptr noundef @.str.7, i64 noundef 4)
  %21 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %22 = load i64, ptr %21, align 8
  %23 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %24 = load i32, ptr %23, align 8
  %25 = call zeroext i8 @mrb_respond_to(ptr noundef %18, i64 %22, i32 %24, i32 noundef %20)
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %34, label %27

27:                                               ; preds = %17
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call { i64, i32 } @mrb_ary_new_from_values(ptr noundef %28, i64 noundef 1, ptr noundef %5)
  %30 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %31 = extractvalue { i64, i32 } %29, 0
  store i64 %31, ptr %30, align 8
  %32 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %33 = extractvalue { i64, i32 } %29, 1
  store i32 %33, ptr %32, align 8
  store i32 1, ptr %8, align 4
  br label %70

34:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %37 = load i64, ptr %36, align 8
  %38 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %39 = load i32, ptr %38, align 8
  %40 = call { i64, i32 } (ptr, i64, i32, ptr, i64, ...) @mrb_funcall(ptr noundef %35, i64 %37, i32 %39, ptr noundef @.str.7, i64 noundef 0)
  %41 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 0
  %42 = extractvalue { i64, i32 } %40, 0
  store i64 %42, ptr %41, align 8
  %43 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 1
  %44 = extractvalue { i64, i32 } %40, 1
  store i32 %44, ptr %43, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %9, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  %45 = getelementptr inbounds %struct.mrb_value, ptr %7, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %59

48:                                               ; preds = %34
  %49 = getelementptr inbounds %struct.mrb_value, ptr %7, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !13
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %59, label %52

52:                                               ; preds = %48
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = call { i64, i32 } @mrb_ary_new_from_values(ptr noundef %53, i64 noundef 1, ptr noundef %5)
  %55 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %56 = extractvalue { i64, i32 } %54, 0
  store i64 %56, ptr %55, align 8
  %57 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %58 = extractvalue { i64, i32 } %54, 1
  store i32 %58, ptr %57, align 8
  store i32 1, ptr %8, align 4
  br label %70

59:                                               ; preds = %48, %34
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 0
  %62 = load i64, ptr %61, align 8
  %63 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 1
  %64 = load i32, ptr %63, align 8
  %65 = call { i64, i32 } @mrb_ensure_array_type(ptr noundef %60, i64 %62, i32 %64)
  %66 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  %67 = extractvalue { i64, i32 } %65, 0
  store i64 %67, ptr %66, align 8
  %68 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  %69 = extractvalue { i64, i32 } %65, 1
  store i32 %69, ptr %68, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !12
  store i32 1, ptr %8, align 4
  br label %70

70:                                               ; preds = %59, %52, %27, %16
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  %71 = load { i64, i32 }, ptr %4, align 8
  ret { i64, i32 } %71
}

declare zeroext i8 @mrb_respond_to(ptr noundef, i64, i32, i32 noundef) #3

declare i32 @mrb_intern_static(ptr noundef, ptr noundef, i64 noundef) #3

declare { i64, i32 } @mrb_funcall(ptr noundef, i64, i32, ptr noundef, i64 noundef, ...) #3

declare { i64, i32 } @mrb_ensure_array_type(ptr noundef, i64, i32) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !11, i64 8}
!10 = !{!"mrb_value", !7, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{i64 0, i64 8, !13, i64 8, i64 4, !14}
!13 = !{!7, !7, i64 0}
!14 = !{!11, !11, 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"

%struct.mrb_value = type { %union.anon, i32 }
%union.anon = type { double }

@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @mrb_ary_new_from_values(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_ary_splat(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %4 = alloca %struct.mrb_value, align 8
  store i64 %1, ptr %4, align 8
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %2, ptr %5, align 8
  %6 = icmp eq i32 %2, 14
  br i1 %6, label %26, label %7

7:                                                ; preds = %3
  %8 = tail call i32 @mrb_intern_static(ptr noundef %0, ptr noundef nonnull @.str.7, i64 noundef 4) #2
  %9 = tail call zeroext i8 @mrb_respond_to(ptr noundef %0, i64 %1, i32 %2, i32 noundef %8) #2
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %10, label %14

10:                                               ; preds = %7
  %11 = call { i64, i32 } @mrb_ary_new_from_values(ptr noundef %0, i64 noundef 1, ptr noundef nonnull %4)
  %12 = extractvalue { i64, i32 } %11, 0
  %13 = extractvalue { i64, i32 } %11, 1
  br label %26

14:                                               ; preds = %7
  %15 = tail call { i64, i32 } (ptr, i64, i32, ptr, i64, ...) @mrb_funcall(ptr noundef %0, i64 %1, i32 %2, ptr noundef nonnull @.str.7, i64 noundef 0) #2
  %16 = extractvalue { i64, i32 } %15, 0
  %17 = extractvalue { i64, i32 } %15, 1
  %18 = icmp ne i32 %17, 0
  %19 = icmp ne i64 %16, 0
  %or.cond = select i1 %18, i1 true, i1 %19
  br i1 %or.cond, label %24, label %20

20:                                               ; preds = %14
  %21 = call { i64, i32 } @mrb_ary_new_from_values(ptr noundef %0, i64 noundef 1, ptr noundef nonnull %4)
  %22 = extractvalue { i64, i32 } %21, 0
  %23 = extractvalue { i64, i32 } %21, 1
  br label %26

24:                                               ; preds = %14
  %25 = tail call { i64, i32 } @mrb_ensure_array_type(ptr noundef %0, i64 %16, i32 %17) #2
  br label %26

26:                                               ; preds = %3, %24, %20, %10
  %.sroa.012.0 = phi i64 [ %16, %24 ], [ %22, %20 ], [ %12, %10 ], [ %1, %3 ]
  %.sroa.513.0 = phi i32 [ %17, %24 ], [ %23, %20 ], [ %13, %10 ], [ 14, %3 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.012.0, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.513.0, 1
  ret { i64, i32 } %.fca.1.insert
}

declare zeroext i8 @mrb_respond_to(ptr noundef, i64, i32, i32 noundef) local_unnamed_addr #1

declare i32 @mrb_intern_static(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare { i64, i32 } @mrb_funcall(ptr noundef, i64, i32, ptr noundef, i64 noundef, ...) local_unnamed_addr #1

declare { i64, i32 } @mrb_ensure_array_type(ptr noundef, i64, i32) local_unnamed_addr #1

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


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