; LLVM IR from ANL-CESAR/XSBench :: opencl (XSutils)

; 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.Inputs = type { i32, i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; 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 i64 @estimate_mem_usage(ptr noundef byval(%struct.Inputs) align 8 %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %7 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 2
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = mul i64 %8, 48
  store i64 %9, ptr %2, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %10 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = load i64, ptr %2, align 8, !tbaa !11
  %13 = mul i64 %11, %12
  store i64 %13, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %14 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = mul nsw i64 %15, %17
  %19 = mul i64 %18, 8
  %20 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = mul nsw i64 %21, %23
  %25 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = mul nsw i64 %24, %26
  %28 = mul i64 %27, 4
  %29 = add i64 %19, %28
  store i64 %29, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %30 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 6
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !12
  %35 = mul nsw i64 %32, %34
  %36 = mul i64 %35, 4
  store i64 %36, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %37 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 5
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %1
  %41 = load i64, ptr %3, align 8, !tbaa !11
  %42 = load i64, ptr %4, align 8, !tbaa !11
  %43 = add i64 %41, %42
  store i64 %43, ptr %6, align 8, !tbaa !11
  br label %55

44:                                               ; preds = %1
  %45 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 5
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = icmp eq i32 %46, 1
  br i1 %47, label %48, label %50

48:                                               ; preds = %44
  %49 = load i64, ptr %3, align 8, !tbaa !11
  store i64 %49, ptr %6, align 8, !tbaa !11
  br label %54

50:                                               ; preds = %44
  %51 = load i64, ptr %3, align 8, !tbaa !11
  %52 = load i64, ptr %5, align 8, !tbaa !11
  %53 = add i64 %51, %52
  store i64 %53, ptr %6, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %50, %48
  br label %55

55:                                               ; preds = %54, %40
  %56 = load i64, ptr %6, align 8, !tbaa !11
  %57 = uitofp i64 %56 to double
  %58 = fdiv double %57, 0x4130000000000000
  %59 = call double @llvm.ceil.f64(double %58)
  %60 = fptoui double %59 to i64
  store i64 %60, ptr %6, align 8, !tbaa !11
  %61 = load i64, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i64 %61
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #2

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 nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !10, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 36}
!14 = !{!6, !7, i64 32}


; 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.Inputs = type { i32, i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i64 @estimate_mem_usage(ptr nocapture noundef readonly byval(%struct.Inputs) align 8 %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = mul i64 %5, %3
  %7 = mul i64 %6, 48
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load i32, ptr %8, align 8, !tbaa !12
  switch i32 %9, label %14 [
    i32 0, label %10
    i32 1, label %21
  ]

10:                                               ; preds = %1
  %11 = shl i64 %5, 2
  %12 = add i64 %11, 56
  %13 = mul i64 %6, %12
  br label %21

14:                                               ; preds = %1
  %15 = getelementptr inbounds i8, ptr %0, i64 36
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = sext i32 %16 to i64
  %18 = shl i64 %5, 2
  %19 = mul i64 %18, %17
  %20 = add i64 %19, %7
  br label %21

21:                                               ; preds = %1, %14, %10
  %.0 = phi i64 [ %13, %10 ], [ %20, %14 ], [ %7, %1 ]
  %22 = uitofp i64 %.0 to double
  %23 = fmul double %22, 0x3EB0000000000000
  %24 = tail call double @llvm.ceil.f64(double %23)
  %25 = fptoui double %24 to i64
  ret i64 %25
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !10, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 32}
!13 = !{!6, !7, i64 36}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass