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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @riscv_decode_offset_from_jal_instruction(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = inttoptr i64 %4 to ptr
  store ptr %5, ptr %3, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !9
  %7 = load i32, ptr %6, align 4
  %8 = and i32 %7, 127
  %9 = icmp ne i32 %8, 111
  br i1 %9, label %10, label %17

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !9
  %12 = load i32, ptr %11, align 4
  %13 = lshr i32 %12, 7
  %14 = and i32 %13, 31
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %10
  call void @abort() #4
  unreachable

17:                                               ; preds = %10, %1
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = load i32, ptr %18, align 4
  %20 = shl i32 %19, 1
  %21 = ashr i32 %20, 22
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = load i32, ptr %22, align 4
  %24 = shl i32 %23, 11
  %25 = ashr i32 %24, 31
  %26 = shl i32 %25, 10
  %27 = or i32 %21, %26
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = load i32, ptr %28, align 4
  %30 = shl i32 %29, 12
  %31 = ashr i32 %30, 24
  %32 = shl i32 %31, 11
  %33 = or i32 %27, %32
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = load i32, ptr %34, align 4
  %36 = ashr i32 %35, 31
  %37 = shl i32 %36, 19
  %38 = or i32 %33, %37
  %39 = shl i32 %38, 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i32 %39
}

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

; Function Attrs: noreturn nounwind
declare void @abort() #2

; 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 = { noreturn nounwind "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 = { nounwind }
attributes #4 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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
define dso_local range(i32 0, -1) i32 @riscv_decode_offset_from_jal_instruction(i64 noundef %0) local_unnamed_addr #0 {
  %2 = inttoptr i64 %0 to ptr
  %3 = load i32, ptr %2, align 4
  %4 = and i32 %3, 127
  %.not = icmp eq i32 %4, 111
  %5 = and i32 %3, 3968
  %.not6 = icmp eq i32 %5, 0
  %or.cond = or i1 %.not, %.not6
  br i1 %or.cond, label %7, label %6

6:                                                ; preds = %1
  tail call void @abort() #2
  unreachable

7:                                                ; preds = %1
  %8 = shl i32 %3, 1
  %9 = ashr i32 %8, 22
  %10 = shl i32 %3, 11
  %11 = ashr i32 %10, 21
  %12 = and i32 %11, 2147482624
  %13 = shl i32 %3, 12
  %14 = ashr i32 %13, 13
  %15 = and i32 %14, 2147481600
  %16 = ashr i32 %3, 12
  %17 = and i32 %16, 2146959360
  %18 = or i32 %17, %9
  %19 = or i32 %18, %12
  %20 = or i32 %19, %15
  %21 = shl i32 %20, 1
  ret i32 %21
}

; Function Attrs: noreturn nounwind
declare void @abort() 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 = { noreturn nounwind "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 = { noreturn 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass