; LLVM IR from facebook/redex :: libredex/IRInstruction.ll (ZN13IRInstructionC2E8IROpcode)

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

%class.IRInstruction = type { i16, i16, i32, %union.anon.0, %union.anon.1 }
%union.anon.0 = type { i64 }
%union.anon.1 = type { ptr, [8 x i8] }

@.str.7 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__._ZN13IRInstructionC2E8IROpcode = external hidden unnamed_addr constant [39 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

; 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: mustprogress uwtable
define dso_local void @_ZN13IRInstructionC2E8IROpcode(ptr noundef nonnull align 8 dereferenceable(32) %0, i16 noundef zeroext %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 0
  %8 = load i16, ptr %4, align 2, !tbaa !9
  store i16 %8, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 1
  store i16 0, ptr %9, align 2, !tbaa !15
  %10 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 2
  store i32 0, ptr %10, align 4, !tbaa !16
  %11 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 3
  store i64 0, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 4
  store i32 0, ptr %12, align 4, !tbaa !18
  %13 = getelementptr inbounds i32, ptr %12, i64 1
  %14 = getelementptr inbounds i32, ptr %12, i64 4
  br label %15

15:                                               ; preds = %15, %2
  %16 = phi ptr [ %13, %2 ], [ %17, %15 ]
  store i32 0, ptr %16, align 4, !tbaa !18
  %17 = getelementptr inbounds i32, ptr %16, i64 1
  %18 = icmp eq ptr %17, %14
  br i1 %18, label %19, label %15

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %20 = load i16, ptr %4, align 2, !tbaa !9
  %21 = call noundef i32 @_ZN11opcode_impl13min_srcs_sizeE8IROpcode(i16 noundef zeroext %20)
  store i32 %21, ptr %5, align 4, !tbaa !18
  %22 = load i32, ptr %5, align 4, !tbaa !18
  %23 = trunc i32 %22 to i16
  %24 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 1
  store i16 %23, ptr %24, align 2, !tbaa !15
  %25 = load i32, ptr %5, align 4, !tbaa !18
  %26 = icmp ugt i32 %25, 4
  br i1 %26, label %27, label %44

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !18
  %29 = call noundef zeroext i16 @_ZNSt14numeric_limitsItE3maxEv() #7
  %30 = zext i16 %29 to i32
  %31 = icmp ult i32 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  br label %35

33:                                               ; preds = %27
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef @.str.7, ptr noundef @.str.8, i32 noundef 25, ptr noundef @__PRETTY_FUNCTION__._ZN13IRInstructionC2E8IROpcode, i32 noundef 2, ptr noundef @.str.9) #8
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %32
  %36 = load i32, ptr %5, align 4, !tbaa !18
  %37 = zext i32 %36 to i64
  %38 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %37, i64 4)
  %39 = extractvalue { i64, i1 } %38, 1
  %40 = extractvalue { i64, i1 } %38, 0
  %41 = select i1 %39, i64 -1, i64 %40
  %42 = call noalias noundef nonnull ptr @_Znam(i64 noundef %41) #9
  %43 = getelementptr inbounds %class.IRInstruction, ptr %6, i32 0, i32 4
  store ptr %42, ptr %43, align 8, !tbaa !17
  br label %44

44:                                               ; preds = %35, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  ret void
}

declare noundef i32 @_ZN11opcode_impl13min_srcs_sizeE8IROpcode(i16 noundef zeroext) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNSt14numeric_limitsItE3maxEv() #3 align 2

; Function Attrs: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #5

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 = { mustprogress 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 #4 = { noreturn "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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nobuiltin allocsize(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 #7 = { nounwind }
attributes #8 = { noreturn }
attributes #9 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS8IROpcode", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS13IRInstruction", !10, i64 0, !13, i64 2, !14, i64 4, !7, i64 8, !7, i64 16}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !13, i64 2}
!16 = !{!12, !14, i64 4}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !14, 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"

@.str.7 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__._ZN13IRInstructionC2E8IROpcode = external hidden unnamed_addr constant [39 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13IRInstructionC2E8IROpcode(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(32) %0, i16 noundef zeroext %1) unnamed_addr #0 align 2 {
  store i16 %1, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 2
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(30) %3, i8 0, i64 30, i1 false)
  %5 = tail call noundef i32 @_ZN11opcode_impl13min_srcs_sizeE8IROpcode(i16 noundef zeroext %1)
  %6 = trunc i32 %5 to i16
  store i16 %6, ptr %3, align 2, !tbaa !12
  %7 = icmp ugt i32 %5, 4
  br i1 %7, label %8, label %17

8:                                                ; preds = %2
  %9 = tail call noundef zeroext i16 @_ZNSt14numeric_limitsItE3maxEv() #6
  %10 = zext i16 %9 to i32
  %11 = icmp ult i32 %5, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  tail call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.8, i32 noundef 25, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN13IRInstructionC2E8IROpcode, i32 noundef 2, ptr noundef nonnull @.str.9) #7
  unreachable

13:                                               ; preds = %8
  %14 = zext nneg i32 %5 to i64
  %15 = shl nuw nsw i64 %14, 2
  %16 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #8
  store ptr %16, ptr %4, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %13, %2
  ret void
}

declare noundef i32 @_ZN11opcode_impl13min_srcs_sizeE8IROpcode(i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNSt14numeric_limitsItE3maxEv() local_unnamed_addr #2 align 2

; Function Attrs: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { mustprogress 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 = { "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 = { mustprogress 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 = { noreturn "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 #4 = { nobuiltin allocsize(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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { noreturn }
attributes #8 = { builtin allocsize(0) }

!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 = !{!"_ZTS13IRInstruction", !7, i64 0, !10, i64 2, !11, i64 4, !8, i64 8, !8, i64 16}
!7 = !{!"_ZTS8IROpcode", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 2}
!13 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass