; LLVM IR from MidnightBlueLabs/TETRA_crypto :: tea1 (tea1_init_key_register)

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

@g_abTea1Sbox = external dso_local constant [256 x i8], align 16

; 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 i32 @tea1_init_key_register(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %29, %1
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 10
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %32

9:                                                ; preds = %5
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = shl i32 %10, 8
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = ashr i32 %12, 24
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = xor i32 %13, %19
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = xor i32 %20, %21
  %23 = and i32 %22, 255
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = or i32 %11, %27
  store i32 %28, ptr %3, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %9
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !9
  br label %5, !llvm.loop !12

32:                                               ; preds = %8
  %33 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %33
}

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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@g_abTea1Sbox = external dso_local local_unnamed_addr constant [256 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @tea1_init_key_register(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = zext i8 %2 to i64
  %4 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %3
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = xor i8 %5, %7
  %9 = zext i8 %8 to i64
  %10 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 2
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = xor i8 %11, %13
  %15 = zext i8 %14 to i64
  %16 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 3
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = xor i8 %17, %19
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = xor i8 %5, %25
  %27 = xor i8 %26, %23
  %28 = zext i8 %27 to i64
  %29 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 5
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = xor i8 %11, %32
  %34 = xor i8 %33, %30
  %35 = zext i8 %34 to i64
  %36 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %0, i64 6
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = xor i8 %17, %39
  %41 = xor i8 %40, %37
  %42 = zext i8 %41 to i64
  %43 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = zext i8 %44 to i32
  %46 = getelementptr inbounds i8, ptr %0, i64 7
  %47 = load i8, ptr %46, align 1, !tbaa !5
  %48 = xor i8 %23, %47
  %49 = xor i8 %48, %44
  %50 = zext i8 %49 to i64
  %51 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !5
  %53 = zext i8 %52 to i32
  %54 = shl nuw nsw i32 %45, 16
  %55 = shl nuw nsw i32 %53, 8
  %56 = or disjoint i32 %54, %55
  %57 = getelementptr inbounds i8, ptr %0, i64 8
  %58 = load i8, ptr %57, align 1, !tbaa !5
  %59 = xor i8 %30, %58
  %60 = xor i8 %59, %52
  %61 = zext i8 %60 to i64
  %62 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !5
  %64 = zext i8 %63 to i32
  %65 = or disjoint i32 %56, %64
  %66 = shl nuw i32 %65, 8
  %67 = getelementptr inbounds i8, ptr %0, i64 9
  %68 = load i8, ptr %67, align 1, !tbaa !5
  %69 = xor i8 %37, %68
  %70 = xor i8 %69, %63
  %71 = zext i8 %70 to i64
  %72 = getelementptr inbounds [256 x i8], ptr @g_abTea1Sbox, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !5
  %74 = zext i8 %73 to i32
  %75 = or disjoint i32 %66, %74
  ret i32 %75
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass