; LLVM IR from libxsmm/libxsmm :: src (generator_rv64_instructions)

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

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@libxsmm_ninit = external global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@.str.54 = external hidden unnamed_addr constant [93 x i8], align 1
@__func__.libxsmm_rv64_instruction_alu_set_imm64 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

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

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

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

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

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

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

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

15:                                               ; preds = %3
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.54) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !9
  %20 = icmp ult i32 1, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %15
  %22 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  br label %24

23:                                               ; preds = %15
  br label %24

24:                                               ; preds = %23, %21
  %25 = phi i32 [ %22, %21 ], [ 1, %23 ]
  call void @libxsmm_handle_error(ptr noundef %18, i32 noundef 90000, ptr noundef @__func__.libxsmm_rv64_instruction_alu_set_imm64, ptr noundef @.str.1, i32 noundef 1257, i32 noundef %25)
  store i32 1, ptr %10, align 4
  br label %105

26:                                               ; preds = %3
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = icmp ule i32 %27, 31
  br i1 %28, label %40, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.55) #4
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !9
  %34 = icmp ult i32 1, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %29
  %36 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  br label %38

37:                                               ; preds = %29
  br label %38

38:                                               ; preds = %37, %35
  %39 = phi i32 [ %36, %35 ], [ 1, %37 ]
  call void @libxsmm_handle_error(ptr noundef %32, i32 noundef 90000, ptr noundef @__func__.libxsmm_rv64_instruction_alu_set_imm64, ptr noundef @.str.1, i32 noundef 1263, i32 noundef %39)
  store i32 1, ptr %10, align 4
  br label %105

40:                                               ; preds = %26
  %41 = load i64, ptr %6, align 8, !tbaa !11
  %42 = icmp ule i64 %41, 2047
  br i1 %42, label %43, label %48

43:                                               ; preds = %40
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = load i64, ptr %6, align 8, !tbaa !11
  %47 = trunc i64 %46 to i32
  call void @libxsmm_rv64_instruction_alu_move_imm12(ptr noundef %44, i32 noundef %45, i32 noundef %47)
  br label %104

48:                                               ; preds = %40
  %49 = load i64, ptr %6, align 8, !tbaa !11
  %50 = icmp ule i64 %49, 524287
  br i1 %50, label %51, label %56

51:                                               ; preds = %48
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = load i64, ptr %6, align 8, !tbaa !11
  %55 = trunc i64 %54 to i32
  call void @libxsmm_rv64_instruction_alu_move_imm20(ptr noundef %52, i32 noundef %53, i32 noundef %55)
  br label %103

56:                                               ; preds = %48
  %57 = load i64, ptr %6, align 8, !tbaa !11
  %58 = icmp ule i64 %57, 2147483647
  br i1 %58, label %59, label %64

59:                                               ; preds = %56
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = load i64, ptr %6, align 8, !tbaa !11
  %63 = trunc i64 %62 to i32
  call void @libxsmm_rv64_instruction_alu_move_imm32(ptr noundef %60, i32 noundef %61, i32 noundef %63)
  br label %102

64:                                               ; preds = %56
  store i64 -9007199254740992, ptr %7, align 8, !tbaa !13
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %87, %64
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = icmp slt i32 %66, 5
  br i1 %67, label %68, label %90

68:                                               ; preds = %65
  %69 = load i64, ptr %6, align 8, !tbaa !11
  %70 = load i64, ptr %7, align 8, !tbaa !13
  %71 = and i64 %69, %70
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = mul nsw i32 11, %72
  %74 = sub nsw i32 53, %73
  %75 = zext i32 %74 to i64
  %76 = lshr i64 %71, %75
  %77 = trunc i64 %76 to i32
  store i32 %77, ptr %8, align 4, !tbaa !9
  %78 = load i64, ptr %7, align 8, !tbaa !13
  %79 = lshr i64 %78, 11
  store i64 %79, ptr %7, align 8, !tbaa !13
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = load i32, ptr %5, align 4, !tbaa !9
  call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %80, i32 noundef 4115, i32 noundef %81, i32 noundef %82, i32 noundef 11)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = load i32, ptr %5, align 4, !tbaa !9
  %86 = load i32, ptr %8, align 4, !tbaa !9
  call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %83, i32 noundef 19, i32 noundef %84, i32 noundef %85, i32 noundef %86)
  br label %87

87:                                               ; preds = %68
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %9, align 4, !tbaa !9
  br label %65, !llvm.loop !17

90:                                               ; preds = %65
  store i64 511, ptr %7, align 8, !tbaa !13
  %91 = load i64, ptr %6, align 8, !tbaa !11
  %92 = load i64, ptr %7, align 8, !tbaa !13
  %93 = and i64 %91, %92
  %94 = trunc i64 %93 to i32
  store i32 %94, ptr %8, align 4, !tbaa !9
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = load i32, ptr %5, align 4, !tbaa !9
  %97 = load i32, ptr %5, align 4, !tbaa !9
  call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %95, i32 noundef 4115, i32 noundef %96, i32 noundef %97, i32 noundef 9)
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = load i32, ptr %5, align 4, !tbaa !9
  %100 = load i32, ptr %5, align 4, !tbaa !9
  %101 = load i32, ptr %8, align 4, !tbaa !9
  call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef %98, i32 noundef 19, i32 noundef %99, i32 noundef %100, i32 noundef %101)
  br label %102

102:                                              ; preds = %90, %59
  br label %103

103:                                              ; preds = %102, %51
  br label %104

104:                                              ; preds = %103, %43
  store i32 0, ptr %10, align 4
  br label %105

105:                                              ; preds = %104, %38, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %106 = load i32, ptr %10, align 4
  switch i32 %106, label %108 [
    i32 0, label %107
    i32 1, label %107
  ]

107:                                              ; preds = %105, %105
  ret void

108:                                              ; preds = %105
  unreachable
}

attributes #0 = { 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 #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 28}
!16 = !{!"libxsmm_generated_code", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@libxsmm_ninit = external local_unnamed_addr global i32, align 4
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@.str.54 = external hidden unnamed_addr constant [93 x i8], align 1
@__func__.libxsmm_rv64_instruction_alu_set_imm64 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_rv64_instruction_alu_set_imm64(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp ult i32 %5, 3001
  br i1 %6, label %7, label %14

7:                                                ; preds = %3
  %8 = load ptr, ptr @stderr, align 8, !tbaa !11
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.54) #3
  %10 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %11 = icmp ugt i32 %10, 1
  %12 = load i32, ptr @libxsmm_verbosity, align 4
  %13 = select i1 %11, i32 %12, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_rv64_instruction_alu_set_imm64, ptr noundef nonnull @.str.1, i32 noundef 1257, i32 noundef %13) #4
  br label %51

14:                                               ; preds = %3
  %15 = icmp ult i32 %1, 32
  br i1 %15, label %23, label %16

16:                                               ; preds = %14
  %17 = load ptr, ptr @stderr, align 8, !tbaa !11
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.55) #3
  %19 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %20 = icmp ugt i32 %19, 1
  %21 = load i32, ptr @libxsmm_verbosity, align 4
  %22 = select i1 %20, i32 %21, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_rv64_instruction_alu_set_imm64, ptr noundef nonnull @.str.1, i32 noundef 1263, i32 noundef %22) #4
  br label %51

23:                                               ; preds = %14
  %24 = icmp ult i64 %2, 2048
  br i1 %24, label %25, label %27

25:                                               ; preds = %23
  %26 = trunc nuw nsw i64 %2 to i32
  tail call void @libxsmm_rv64_instruction_alu_move_imm12(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %26)
  br label %51

27:                                               ; preds = %23
  %28 = icmp ult i64 %2, 524288
  br i1 %28, label %29, label %31

29:                                               ; preds = %27
  %30 = trunc nuw nsw i64 %2 to i32
  tail call void @libxsmm_rv64_instruction_alu_move_imm20(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %30)
  br label %51

31:                                               ; preds = %27
  %32 = icmp ult i64 %2, 2147483648
  br i1 %32, label %49, label %.preheader.preheader

.preheader.preheader:                             ; preds = %31
  %33 = lshr i64 %2, 53
  %34 = trunc nuw nsw i64 %33 to i32
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 4115, i32 noundef %1, i32 noundef %1, i32 noundef 11)
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 19, i32 noundef %1, i32 noundef %1, i32 noundef %34)
  %35 = lshr i64 %2, 42
  %36 = trunc nuw nsw i64 %35 to i32
  %37 = and i32 %36, 2047
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 4115, i32 noundef %1, i32 noundef %1, i32 noundef 11)
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 19, i32 noundef %1, i32 noundef %1, i32 noundef %37)
  %38 = lshr i64 %2, 31
  %39 = trunc i64 %38 to i32
  %40 = and i32 %39, 2047
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 4115, i32 noundef %1, i32 noundef %1, i32 noundef 11)
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 19, i32 noundef %1, i32 noundef %1, i32 noundef %40)
  %41 = trunc i64 %2 to i32
  %42 = lshr i32 %41, 20
  %43 = and i32 %42, 2047
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 4115, i32 noundef %1, i32 noundef %1, i32 noundef 11)
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 19, i32 noundef %1, i32 noundef %1, i32 noundef %43)
  %44 = trunc i64 %2 to i32
  %45 = lshr i32 %44, 9
  %46 = and i32 %45, 2047
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 4115, i32 noundef %1, i32 noundef %1, i32 noundef 11)
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 19, i32 noundef %1, i32 noundef %1, i32 noundef %46)
  %47 = trunc i64 %2 to i32
  %48 = and i32 %47, 511
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 4115, i32 noundef %1, i32 noundef %1, i32 noundef 9)
  tail call void @libxsmm_rv64_instruction_alu_compute_imm12(ptr noundef nonnull %0, i32 noundef 19, i32 noundef %1, i32 noundef %1, i32 noundef %48)
  br label %51

49:                                               ; preds = %31
  %50 = trunc nuw nsw i64 %2 to i32
  tail call void @libxsmm_rv64_instruction_alu_move_imm32(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %50)
  br label %51

51:                                               ; preds = %25, %49, %.preheader.preheader, %29, %16, %7
  ret void
}

attributes #0 = { nofree 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 #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 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 = { cold nounwind }
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, !10, i64 28}
!6 = !{!"libxsmm_generated_code", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass