; LLVM IR from AllenDowney/ExercisesInC :: examples/queue (queue_test)

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

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@__PRETTY_FUNCTION__.queue_test = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @queue_test() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 128, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = call ptr @make_queue(i32 noundef %5)
  store ptr %6, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !9
  %8 = call i32 @queue_empty(ptr noundef %7)
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %0
  br label %12

11:                                               ; preds = %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 10, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

12:                                               ; preds = %10
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %20, %12
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %13
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = load i32, ptr %1, align 4, !tbaa !5
  call void @queue_push(ptr noundef %18, i32 noundef %19)
  br label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %1, align 4, !tbaa !5
  br label %13, !llvm.loop !11

23:                                               ; preds = %13
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = call i32 @queue_full(ptr noundef %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  br label %29

28:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 14, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

29:                                               ; preds = %27
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %42, %29
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 10
  br i1 %32, label %33, label %45

33:                                               ; preds = %30
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = call i32 @queue_pop(ptr noundef %34)
  store i32 %35, ptr %2, align 4, !tbaa !5
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = icmp eq i32 %36, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  br label %41

40:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 17, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

41:                                               ; preds = %39
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %1, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %1, align 4, !tbaa !5
  br label %30, !llvm.loop !13

45:                                               ; preds = %30
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = call i32 @queue_empty(ptr noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  br label %51

50:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 19, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

51:                                               ; preds = %49
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = call i32 @queue_full(ptr noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  br label %57

56:                                               ; preds = %51
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 20, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

57:                                               ; preds = %55
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %64, %57
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = icmp slt i32 %59, 10
  br i1 %60, label %61, label %67

61:                                               ; preds = %58
  %62 = load ptr, ptr %4, align 8, !tbaa !9
  %63 = load i32, ptr %1, align 4, !tbaa !5
  call void @queue_push(ptr noundef %62, i32 noundef %63)
  br label %64

64:                                               ; preds = %61
  %65 = load i32, ptr %1, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %1, align 4, !tbaa !5
  br label %58, !llvm.loop !14

67:                                               ; preds = %58
  %68 = load ptr, ptr %4, align 8, !tbaa !9
  %69 = call i32 @queue_full(ptr noundef %68)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %67
  br label %73

72:                                               ; preds = %67
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 24, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

73:                                               ; preds = %71
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %80, %73
  %75 = load i32, ptr %1, align 4, !tbaa !5
  %76 = icmp slt i32 %75, 10
  br i1 %76, label %77, label %83

77:                                               ; preds = %74
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = call i32 @queue_pop(ptr noundef %78)
  store i32 %79, ptr %2, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %77
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %1, align 4, !tbaa !5
  br label %74, !llvm.loop !15

83:                                               ; preds = %74
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = icmp eq i32 %84, 19
  br i1 %85, label %86, label %87

86:                                               ; preds = %83
  br label %88

87:                                               ; preds = %83
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 28, ptr noundef @__PRETTY_FUNCTION__.queue_test) #5
  unreachable

88:                                               ; preds = %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

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

declare ptr @make_queue(i32 noundef) #2

declare i32 @queue_empty(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare void @queue_push(ptr noundef, i32 noundef) #2

declare i32 @queue_full(ptr noundef) #2

declare i32 @queue_pop(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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 [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@__PRETTY_FUNCTION__.queue_test = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @queue_test() local_unnamed_addr #0 {
  %1 = tail call ptr @make_queue(i32 noundef 128) #3
  %2 = tail call i32 @queue_empty(ptr noundef %1) #3
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %.preheader32

3:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 10, ptr noundef nonnull @__PRETTY_FUNCTION__.queue_test) #4
  unreachable

.preheader32:                                     ; preds = %0, %.preheader32
  %.034 = phi i32 [ %4, %.preheader32 ], [ 0, %0 ]
  tail call void @queue_push(ptr noundef %1, i32 noundef %.034) #3
  %4 = add nuw nsw i32 %.034, 1
  %exitcond.not = icmp eq i32 %4, 128
  br i1 %exitcond.not, label %5, label %.preheader32, !llvm.loop !5

5:                                                ; preds = %.preheader32
  %6 = tail call i32 @queue_full(ptr noundef %1) #3
  %.not26 = icmp eq i32 %6, 0
  br i1 %.not26, label %9, label %.preheader31.preheader

.preheader31.preheader:                           ; preds = %5
  %7 = tail call i32 @queue_pop(ptr noundef %1) #3
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.preheader31.1, label %30

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

.preheader31.1:                                   ; preds = %.preheader31.preheader
  %10 = tail call i32 @queue_pop(ptr noundef %1) #3
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %.preheader31.2, label %30

.preheader31.2:                                   ; preds = %.preheader31.1
  %12 = tail call i32 @queue_pop(ptr noundef %1) #3
  %13 = icmp eq i32 %12, 2
  br i1 %13, label %.preheader31.3, label %30

.preheader31.3:                                   ; preds = %.preheader31.2
  %14 = tail call i32 @queue_pop(ptr noundef %1) #3
  %15 = icmp eq i32 %14, 3
  br i1 %15, label %.preheader31.4, label %30

.preheader31.4:                                   ; preds = %.preheader31.3
  %16 = tail call i32 @queue_pop(ptr noundef %1) #3
  %17 = icmp eq i32 %16, 4
  br i1 %17, label %.preheader31.5, label %30

.preheader31.5:                                   ; preds = %.preheader31.4
  %18 = tail call i32 @queue_pop(ptr noundef %1) #3
  %19 = icmp eq i32 %18, 5
  br i1 %19, label %.preheader31.6, label %30

.preheader31.6:                                   ; preds = %.preheader31.5
  %20 = tail call i32 @queue_pop(ptr noundef %1) #3
  %21 = icmp eq i32 %20, 6
  br i1 %21, label %.preheader31.7, label %30

.preheader31.7:                                   ; preds = %.preheader31.6
  %22 = tail call i32 @queue_pop(ptr noundef %1) #3
  %23 = icmp eq i32 %22, 7
  br i1 %23, label %.preheader31.8, label %30

.preheader31.8:                                   ; preds = %.preheader31.7
  %24 = tail call i32 @queue_pop(ptr noundef %1) #3
  %25 = icmp eq i32 %24, 8
  br i1 %25, label %.preheader31.9, label %30

.preheader31.9:                                   ; preds = %.preheader31.8
  %26 = tail call i32 @queue_pop(ptr noundef %1) #3
  %27 = icmp eq i32 %26, 9
  br i1 %27, label %28, label %30

28:                                               ; preds = %.preheader31.9
  %29 = tail call i32 @queue_empty(ptr noundef %1) #3
  %.not27 = icmp eq i32 %29, 0
  br i1 %.not27, label %32, label %31

30:                                               ; preds = %.preheader31.9, %.preheader31.8, %.preheader31.7, %.preheader31.6, %.preheader31.5, %.preheader31.4, %.preheader31.3, %.preheader31.2, %.preheader31.1, %.preheader31.preheader
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 17, ptr noundef nonnull @__PRETTY_FUNCTION__.queue_test) #4
  unreachable

31:                                               ; preds = %28
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 19, ptr noundef nonnull @__PRETTY_FUNCTION__.queue_test) #4
  unreachable

32:                                               ; preds = %28
  %33 = tail call i32 @queue_full(ptr noundef %1) #3
  %.not28 = icmp eq i32 %33, 0
  br i1 %.not28, label %.preheader30.preheader, label %35

.preheader30.preheader:                           ; preds = %32
  tail call void @queue_push(ptr noundef %1, i32 noundef 0) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 1) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 2) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 3) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 4) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 5) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 6) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 7) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 8) #3
  tail call void @queue_push(ptr noundef %1, i32 noundef 9) #3
  %34 = tail call i32 @queue_full(ptr noundef %1) #3
  %.not29 = icmp eq i32 %34, 0
  br i1 %.not29, label %47, label %.preheader.preheader

35:                                               ; preds = %32
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 20, ptr noundef nonnull @__PRETTY_FUNCTION__.queue_test) #4
  unreachable

.preheader.preheader:                             ; preds = %.preheader30.preheader
  %36 = tail call i32 @queue_pop(ptr noundef %1) #3
  %37 = tail call i32 @queue_pop(ptr noundef %1) #3
  %38 = tail call i32 @queue_pop(ptr noundef %1) #3
  %39 = tail call i32 @queue_pop(ptr noundef %1) #3
  %40 = tail call i32 @queue_pop(ptr noundef %1) #3
  %41 = tail call i32 @queue_pop(ptr noundef %1) #3
  %42 = tail call i32 @queue_pop(ptr noundef %1) #3
  %43 = tail call i32 @queue_pop(ptr noundef %1) #3
  %44 = tail call i32 @queue_pop(ptr noundef %1) #3
  %45 = tail call i32 @queue_pop(ptr noundef %1) #3
  %46 = icmp eq i32 %45, 19
  br i1 %46, label %49, label %48

47:                                               ; preds = %.preheader30.preheader
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 24, ptr noundef nonnull @__PRETTY_FUNCTION__.queue_test) #4
  unreachable

48:                                               ; preds = %.preheader.preheader
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 28, ptr noundef nonnull @__PRETTY_FUNCTION__.queue_test) #4
  unreachable

49:                                               ; preds = %.preheader.preheader
  ret void
}

declare ptr @make_queue(i32 noundef) local_unnamed_addr #1

declare i32 @queue_empty(ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

declare i32 @queue_full(ptr noundef) local_unnamed_addr #1

declare i32 @queue_pop(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 = { "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 "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 = { nounwind }
attributes #4 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass