; LLVM IR from sslab-gatech/janus :: lkl/arch/h8300/lib/muldi3.ll_ (muldi3)

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

%union.DWunion = type { i64 }
%struct.DWstruct = type { i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i64 @__muldi3(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %union.DWunion, align 8
  %6 = alloca %union.DWunion, align 8
  %7 = alloca %union.DWunion, align 8
  %8 = alloca %union.DWunion, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %18 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %18, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %19 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %19, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  br label %20

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %21 = getelementptr inbounds %struct.DWstruct, ptr %5, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = and i32 %22, 65535
  store i32 %23, ptr %13, align 4, !tbaa !10
  %24 = getelementptr inbounds %struct.DWstruct, ptr %5, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = lshr i32 %25, 16
  store i32 %26, ptr %15, align 4, !tbaa !10
  %27 = getelementptr inbounds %struct.DWstruct, ptr %6, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = and i32 %28, 65535
  store i32 %29, ptr %14, align 4, !tbaa !10
  %30 = getelementptr inbounds %struct.DWstruct, ptr %6, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = lshr i32 %31, 16
  store i32 %32, ptr %16, align 4, !tbaa !10
  %33 = load i32, ptr %13, align 4, !tbaa !10
  %34 = load i32, ptr %14, align 4, !tbaa !10
  %35 = mul i32 %33, %34
  store i32 %35, ptr %9, align 4, !tbaa !10
  %36 = load i32, ptr %13, align 4, !tbaa !10
  %37 = load i32, ptr %16, align 4, !tbaa !10
  %38 = mul i32 %36, %37
  store i32 %38, ptr %10, align 4, !tbaa !10
  %39 = load i32, ptr %15, align 4, !tbaa !10
  %40 = load i32, ptr %14, align 4, !tbaa !10
  %41 = mul i32 %39, %40
  store i32 %41, ptr %11, align 4, !tbaa !10
  %42 = load i32, ptr %15, align 4, !tbaa !10
  %43 = load i32, ptr %16, align 4, !tbaa !10
  %44 = mul i32 %42, %43
  store i32 %44, ptr %12, align 4, !tbaa !10
  %45 = load i32, ptr %9, align 4, !tbaa !10
  %46 = lshr i32 %45, 16
  %47 = load i32, ptr %10, align 4, !tbaa !10
  %48 = add i32 %47, %46
  store i32 %48, ptr %10, align 4, !tbaa !10
  %49 = load i32, ptr %11, align 4, !tbaa !10
  %50 = load i32, ptr %10, align 4, !tbaa !10
  %51 = add i32 %50, %49
  store i32 %51, ptr %10, align 4, !tbaa !10
  %52 = load i32, ptr %10, align 4, !tbaa !10
  %53 = load i32, ptr %11, align 4, !tbaa !10
  %54 = icmp ult i32 %52, %53
  br i1 %54, label %55, label %58

55:                                               ; preds = %20
  %56 = load i32, ptr %12, align 4, !tbaa !10
  %57 = add i32 %56, 65536
  store i32 %57, ptr %12, align 4, !tbaa !10
  br label %58

58:                                               ; preds = %55, %20
  %59 = load i32, ptr %12, align 4, !tbaa !10
  %60 = load i32, ptr %10, align 4, !tbaa !10
  %61 = lshr i32 %60, 16
  %62 = add i32 %59, %61
  %63 = getelementptr inbounds %struct.DWstruct, ptr %8, i32 0, i32 0
  store i32 %62, ptr %63, align 8, !tbaa !9
  %64 = load i32, ptr %10, align 4, !tbaa !10
  %65 = and i32 %64, 65535
  %66 = mul i32 %65, 65536
  %67 = load i32, ptr %9, align 4, !tbaa !10
  %68 = and i32 %67, 65535
  %69 = add i32 %66, %68
  %70 = getelementptr inbounds %struct.DWstruct, ptr %8, i32 0, i32 1
  store i32 %69, ptr %70, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %71

71:                                               ; preds = %58
  br label %72

72:                                               ; preds = %71
  %73 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %73, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %74 = load i64, ptr %17, align 8, !tbaa !5
  store i64 %74, ptr %7, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.DWstruct, ptr %5, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = getelementptr inbounds %struct.DWstruct, ptr %6, i32 0, i32 0
  %78 = load i32, ptr %77, align 8, !tbaa !9
  %79 = mul i32 %76, %78
  %80 = getelementptr inbounds %struct.DWstruct, ptr %5, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.DWstruct, ptr %6, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = mul i32 %81, %83
  %85 = add i32 %79, %84
  %86 = getelementptr inbounds %struct.DWstruct, ptr %7, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !9
  %88 = add i32 %87, %85
  store i32 %88, ptr %86, align 8, !tbaa !9
  %89 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %89
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !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 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i64 @__muldi3(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.sroa.427.0.extract.shift = lshr i64 %0, 32
  %.sroa.427.0.extract.trunc = trunc nuw i64 %.sroa.427.0.extract.shift to i32
  %.sroa.423.0.extract.shift = lshr i64 %1, 32
  %.sroa.423.0.extract.trunc = trunc nuw i64 %.sroa.423.0.extract.shift to i32
  %3 = and i32 %.sroa.427.0.extract.trunc, 65535
  %4 = lshr i32 %.sroa.427.0.extract.trunc, 16
  %5 = and i32 %.sroa.423.0.extract.trunc, 65535
  %6 = lshr i32 %.sroa.423.0.extract.trunc, 16
  %7 = mul nuw i32 %5, %3
  %8 = mul nuw i32 %6, %3
  %9 = mul nuw i32 %5, %4
  %10 = mul nuw i32 %6, %4
  %11 = lshr i32 %7, 16
  %12 = add i32 %9, %8
  %13 = add i32 %12, %11
  %14 = icmp ult i32 %13, %9
  %15 = add nuw i32 %10, 65536
  %spec.select = select i1 %14, i32 %15, i32 %10
  %.sroa.022.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.026.0.extract.trunc = trunc i64 %0 to i32
  %16 = lshr i32 %13, 16
  %17 = shl i32 %13, 16
  %18 = and i32 %7, 65535
  %19 = or disjoint i32 %17, %18
  %20 = mul i32 %.sroa.427.0.extract.trunc, %.sroa.022.0.extract.trunc
  %21 = mul i32 %.sroa.423.0.extract.trunc, %.sroa.026.0.extract.trunc
  %22 = add i32 %21, %20
  %23 = add i32 %22, %16
  %24 = add i32 %23, %spec.select
  %.sroa.6.0.insert.ext = zext i32 %19 to i64
  %.sroa.6.0.insert.shift = shl nuw i64 %.sroa.6.0.insert.ext, 32
  %.sroa.020.0.insert.ext = zext i32 %24 to i64
  %.sroa.020.0.insert.insert = or disjoint i64 %.sroa.6.0.insert.shift, %.sroa.020.0.insert.ext
  ret i64 %.sroa.020.0.insert.insert
}

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


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