; LLVM IR from Dovyski/opengl-demos :: libs/glm-0.9.9.3/test/gtc/gtc_round.ll (ZN12isPowerOfTwo10test_int16Ev)

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

@__const._ZN12isPowerOfTwo10test_int16Ev.Data = external hidden unnamed_addr constant [6 x %"struct.isPowerOfTwo::type"], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12isPowerOfTwo10test_int16Ev() #0 {
  %1 = alloca [6 x %"struct.isPowerOfTwo::type"], align 16
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 24, ptr %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %1, ptr align 16 @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 6, ptr %4, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %32, %0
  %7 = load i64, ptr %3, align 8, !tbaa !9
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = icmp ult i64 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %35

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  %12 = load i64, ptr %3, align 8, !tbaa !9
  %13 = getelementptr inbounds [6 x %"struct.isPowerOfTwo::type"], ptr %1, i64 0, i64 %12
  %14 = getelementptr inbounds %"struct.isPowerOfTwo::type", ptr %13, i32 0, i32 0
  %15 = load i16, ptr %14, align 4, !tbaa !11
  %16 = call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %15)
  %17 = zext i1 %16 to i8
  store i8 %17, ptr %5, align 1, !tbaa !15
  %18 = load i64, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds [6 x %"struct.isPowerOfTwo::type"], ptr %1, i64 0, i64 %18
  %20 = getelementptr inbounds %"struct.isPowerOfTwo::type", ptr %19, i32 0, i32 1
  %21 = load i8, ptr %20, align 2, !tbaa !16, !range !17, !noundef !18
  %22 = trunc i8 %21 to i1
  %23 = zext i1 %22 to i32
  %24 = load i8, ptr %5, align 1, !tbaa !15, !range !17, !noundef !18
  %25 = trunc i8 %24 to i1
  %26 = zext i1 %25 to i32
  %27 = icmp eq i32 %23, %26
  %28 = zext i1 %27 to i64
  %29 = select i1 %27, i32 0, i32 1
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %32

32:                                               ; preds = %11
  %33 = load i64, ptr %3, align 8, !tbaa !9
  %34 = add i64 %33, 1
  store i64 %34, ptr %3, align 8, !tbaa !9
  br label %6, !llvm.loop !19

35:                                               ; preds = %10
  %36 = load i32, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %1) #4
  ret i32 %36
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext) #3

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN12isPowerOfTwo4typeIsEE", !13, i64 0, !14, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!12, !14, i64 2}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%"struct.isPowerOfTwo::type" = type { i16, i8 }

@__const._ZN12isPowerOfTwo10test_int16Ev.Data = external hidden unnamed_addr constant [6 x %"struct.isPowerOfTwo::type"], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12isPowerOfTwo10test_int16Ev() local_unnamed_addr #0 {
  %1 = load i16, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, align 16, !tbaa !5
  %2 = tail call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %1)
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 2), align 2, !tbaa !11, !range !12, !noundef !13
  %4 = zext i1 %2 to i8
  %5 = icmp ne i8 %3, %4
  %6 = zext i1 %5 to i32
  %7 = load i16, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 4), align 4, !tbaa !5
  %8 = tail call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %7)
  %9 = load i8, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 6), align 2, !tbaa !11, !range !12, !noundef !13
  %10 = zext i1 %8 to i8
  %11 = icmp ne i8 %9, %10
  %12 = zext i1 %11 to i32
  %13 = add nuw nsw i32 %6, %12
  %14 = load i16, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 8), align 8, !tbaa !5
  %15 = tail call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %14)
  %16 = load i8, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 10), align 2, !tbaa !11, !range !12, !noundef !13
  %17 = zext i1 %15 to i8
  %18 = icmp ne i8 %16, %17
  %19 = zext i1 %18 to i32
  %20 = add nuw nsw i32 %13, %19
  %21 = load i16, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 12), align 4, !tbaa !5
  %22 = tail call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %21)
  %23 = load i8, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 14), align 2, !tbaa !11, !range !12, !noundef !13
  %24 = zext i1 %22 to i8
  %25 = icmp ne i8 %23, %24
  %26 = zext i1 %25 to i32
  %27 = add nuw nsw i32 %20, %26
  %28 = load i16, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 16), align 16, !tbaa !5
  %29 = tail call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %28)
  %30 = load i8, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 18), align 2, !tbaa !11, !range !12, !noundef !13
  %31 = zext i1 %29 to i8
  %32 = icmp ne i8 %30, %31
  %33 = zext i1 %32 to i32
  %34 = add nuw nsw i32 %27, %33
  %35 = load i16, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 20), align 4, !tbaa !5
  %36 = tail call noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext %35)
  %37 = load i8, ptr getelementptr inbounds (i8, ptr @__const._ZN12isPowerOfTwo10test_int16Ev.Data, i64 22), align 2, !tbaa !11, !range !12, !noundef !13
  %38 = zext i1 %36 to i8
  %39 = icmp ne i8 %37, %38
  %40 = zext i1 %39 to i32
  %41 = add nuw nsw i32 %34, %40
  ret i32 %41
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3glm12isPowerOfTwoIsEEbT_(i16 noundef signext) local_unnamed_addr #1

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 = { inlinehint 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" }

!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 = !{!"_ZTSN12isPowerOfTwo4typeIsEE", !7, i64 0, !10, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!6, !10, i64 2}
!12 = !{i8 0, i8 2}
!13 = !{}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass