; LLVM IR from MidnightBlueLabs/TETRA_crypto :: common (build_iv)

; 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.FrameNumbers = type { i8, i8, i8, i16, i8 }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.build_iv = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @build_iv(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.FrameNumbers, ptr %3, i32 0, i32 0
  %5 = load i8, ptr %4, align 2, !tbaa !9
  %6 = zext i8 %5 to i32
  %7 = icmp sle i32 1, %6
  br i1 %7, label %8, label %15

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.FrameNumbers, ptr %9, i32 0, i32 0
  %11 = load i8, ptr %10, align 2, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp sle i32 %12, 4
  br i1 %13, label %14, label %15

14:                                               ; preds = %8
  br label %16

15:                                               ; preds = %8, %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 21, ptr noundef @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

16:                                               ; preds = %14
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.FrameNumbers, ptr %17, i32 0, i32 1
  %19 = load i8, ptr %18, align 1, !tbaa !12
  %20 = zext i8 %19 to i32
  %21 = icmp sle i32 1, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.FrameNumbers, ptr %23, i32 0, i32 1
  %25 = load i8, ptr %24, align 1, !tbaa !12
  %26 = zext i8 %25 to i32
  %27 = icmp sle i32 %26, 18
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  br label %30

29:                                               ; preds = %22, %16
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 22, ptr noundef @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

30:                                               ; preds = %28
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.FrameNumbers, ptr %31, i32 0, i32 2
  %33 = load i8, ptr %32, align 2, !tbaa !13
  %34 = zext i8 %33 to i32
  %35 = icmp sle i32 1, %34
  br i1 %35, label %36, label %43

36:                                               ; preds = %30
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.FrameNumbers, ptr %37, i32 0, i32 2
  %39 = load i8, ptr %38, align 2, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = icmp sle i32 %40, 60
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  br label %44

43:                                               ; preds = %36, %30
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 23, ptr noundef @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

44:                                               ; preds = %42
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.FrameNumbers, ptr %45, i32 0, i32 3
  %47 = load i16, ptr %46, align 2, !tbaa !14
  %48 = zext i16 %47 to i32
  %49 = icmp sle i32 0, %48
  br i1 %49, label %50, label %57

50:                                               ; preds = %44
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.FrameNumbers, ptr %51, i32 0, i32 3
  %53 = load i16, ptr %52, align 2, !tbaa !14
  %54 = zext i16 %53 to i32
  %55 = icmp sle i32 %54, 65535
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  br label %58

57:                                               ; preds = %50, %44
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 24, ptr noundef @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

58:                                               ; preds = %56
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.FrameNumbers, ptr %59, i32 0, i32 4
  %61 = load i8, ptr %60, align 2, !tbaa !15
  %62 = zext i8 %61 to i32
  %63 = icmp sle i32 0, %62
  br i1 %63, label %64, label %71

64:                                               ; preds = %58
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.FrameNumbers, ptr %65, i32 0, i32 4
  %67 = load i8, ptr %66, align 2, !tbaa !15
  %68 = zext i8 %67 to i32
  %69 = icmp sle i32 %68, 1
  br i1 %69, label %70, label %71

70:                                               ; preds = %64
  br label %72

71:                                               ; preds = %64, %58
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 25, ptr noundef @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

72:                                               ; preds = %70
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.FrameNumbers, ptr %73, i32 0, i32 0
  %75 = load i8, ptr %74, align 2, !tbaa !9
  %76 = zext i8 %75 to i32
  %77 = sub nsw i32 %76, 1
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.FrameNumbers, ptr %78, i32 0, i32 1
  %80 = load i8, ptr %79, align 1, !tbaa !12
  %81 = zext i8 %80 to i32
  %82 = shl i32 %81, 2
  %83 = or i32 %77, %82
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.FrameNumbers, ptr %84, i32 0, i32 2
  %86 = load i8, ptr %85, align 2, !tbaa !13
  %87 = zext i8 %86 to i32
  %88 = shl i32 %87, 7
  %89 = or i32 %83, %88
  %90 = load ptr, ptr %2, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.FrameNumbers, ptr %90, i32 0, i32 3
  %92 = load i16, ptr %91, align 2, !tbaa !14
  %93 = zext i16 %92 to i32
  %94 = and i32 %93, 32767
  %95 = shl i32 %94, 13
  %96 = or i32 %89, %95
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.FrameNumbers, ptr %97, i32 0, i32 4
  %99 = load i8, ptr %98, align 2, !tbaa !15
  %100 = zext i8 %99 to i32
  %101 = shl i32 %100, 28
  %102 = or i32 %96, %101
  ret i32 %102
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !11, i64 4, !7, i64 6}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !7, i64 1}
!13 = !{!10, !7, i64 2}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !7, i64 6}


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

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.build_iv = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 128, 536870912) i32 @build_iv(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 2, !tbaa !5
  %3 = add i8 %2, -1
  %or.cond = icmp ult i8 %3, 4
  br i1 %or.cond, label %5, label %4

4:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 21, ptr noundef nonnull @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !10
  %8 = add i8 %7, -1
  %or.cond20 = icmp ult i8 %8, 18
  br i1 %or.cond20, label %10, label %9

9:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 22, ptr noundef nonnull @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 2
  %12 = load i8, ptr %11, align 2, !tbaa !11
  %13 = add i8 %12, -1
  %or.cond21 = icmp ult i8 %13, 60
  br i1 %or.cond21, label %15, label %14

14:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 23, ptr noundef nonnull @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 6
  %17 = load i8, ptr %16, align 2, !tbaa !12
  %18 = icmp ult i8 %17, 2
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 25, ptr noundef nonnull @__PRETTY_FUNCTION__.build_iv) #2
  unreachable

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  %22 = load i16, ptr %21, align 2, !tbaa !13
  %23 = zext nneg i8 %17 to i32
  %24 = zext nneg i8 %12 to i32
  %25 = zext nneg i8 %2 to i32
  %26 = add nsw i32 %25, -1
  %27 = shl nuw nsw i8 %7, 2
  %28 = zext nneg i8 %27 to i32
  %29 = or i32 %26, %28
  %30 = shl nuw nsw i32 %24, 7
  %31 = or i32 %29, %30
  %32 = and i16 %22, 32767
  %33 = zext nneg i16 %32 to i32
  %34 = shl nuw nsw i32 %33, 13
  %35 = shl nuw nsw i32 %23, 28
  %36 = or i32 %31, %35
  %37 = or i32 %36, %34
  ret i32 %37
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) 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)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !9, i64 4, !7, i64 6}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!6, !7, i64 1}
!11 = !{!6, !7, i64 2}
!12 = !{!6, !7, i64 6}
!13 = !{!6, !9, i64 4}


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