; LLVM IR from kaynewbie/algorithm :: algorithm/LeetCode/libs (queue_internal)

; 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.queue_s = type { ptr, ptr, i16, i16, i8, i8, i8, ptr, ptr, ptr, ptr }
%struct.queue_element_s = type { ptr, ptr }

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

; Function Attrs: nounwind
declare i32 @pthread_cond_signal(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @queue_get_internal(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %18, align 8, !tbaa !5
  store i8 -1, ptr %6, align 1
  br label %151

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.queue_s, ptr %20, i32 0, i32 2
  %22 = load i16, ptr %21, align 8, !tbaa !9
  %23 = zext i16 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %69

25:                                               ; preds = %19
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %30

28:                                               ; preds = %25
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %29, align 8, !tbaa !5
  store i8 -7, ptr %6, align 1
  br label %151

30:                                               ; preds = %25
  br label %31

31:                                               ; preds = %45, %30
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.queue_s, ptr %32, i32 0, i32 2
  %34 = load i16, ptr %33, align 8, !tbaa !9
  %35 = zext i16 %34 to i32
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %31
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.queue_s, ptr %38, i32 0, i32 4
  %40 = load i8, ptr %39, align 4, !tbaa !12
  %41 = zext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br label %43

43:                                               ; preds = %37, %31
  %44 = phi i1 [ false, %31 ], [ %42, %37 ]
  br i1 %44, label %45, label %54

45:                                               ; preds = %43
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.queue_s, ptr %47, i32 0, i32 9
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.queue_s, ptr %50, i32 0, i32 8
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = call i32 %46(ptr noundef %49, ptr noundef %52)
  br label %31, !llvm.loop !15

54:                                               ; preds = %43
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.queue_s, ptr %55, i32 0, i32 2
  %57 = load i16, ptr %56, align 8, !tbaa !9
  %58 = zext i16 %57 to i32
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %67

60:                                               ; preds = %54
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.queue_s, ptr %61, i32 0, i32 4
  %63 = load i8, ptr %62, align 4, !tbaa !12
  %64 = zext i8 %63 to i32
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %60
  store i8 -4, ptr %6, align 1
  br label %151

67:                                               ; preds = %60, %54
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.queue_s, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !17
  store ptr %72, ptr %13, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %87, %69
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %85

76:                                               ; preds = %73
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %85

79:                                               ; preds = %76
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = call i32 %80(ptr noundef %81, ptr noundef %82)
  %84 = icmp ne i32 0, %83
  br label %85

85:                                               ; preds = %79, %76, %73
  %86 = phi i1 [ false, %76 ], [ false, %73 ], [ %84, %79 ]
  br i1 %86, label %87, label %92

87:                                               ; preds = %85
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %88, ptr %12, align 8, !tbaa !5
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.queue_element_s, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !18
  store ptr %91, ptr %13, align 8, !tbaa !5
  br label %73, !llvm.loop !20

92:                                               ; preds = %85
  %93 = load ptr, ptr %13, align 8, !tbaa !5
  %94 = icmp ne ptr %93, null
  br i1 %94, label %95, label %121

95:                                               ; preds = %92
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = icmp eq ptr %96, null
  br i1 %97, label %98, label %121

98:                                               ; preds = %95
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.queue_element_s, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !18
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.queue_s, ptr %102, i32 0, i32 0
  store ptr %101, ptr %103, align 8, !tbaa !17
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.queue_s, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !17
  %107 = icmp eq ptr %106, null
  br i1 %107, label %108, label %111

108:                                              ; preds = %98
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.queue_s, ptr %109, i32 0, i32 1
  store ptr null, ptr %110, align 8, !tbaa !21
  br label %111

111:                                              ; preds = %108, %98
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.queue_s, ptr %112, i32 0, i32 2
  %114 = load i16, ptr %113, align 8, !tbaa !9
  %115 = add i16 %114, -1
  store i16 %115, ptr %113, align 8, !tbaa !9
  %116 = load ptr, ptr %13, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.queue_element_s, ptr %116, i32 0, i32 0
  %118 = load ptr, ptr %117, align 8, !tbaa !22
  %119 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %118, ptr %119, align 8, !tbaa !5
  %120 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %120) #3
  br label %145

121:                                              ; preds = %95, %92
  %122 = load ptr, ptr %13, align 8, !tbaa !5
  %123 = icmp ne ptr %122, null
  br i1 %123, label %124, label %142

124:                                              ; preds = %121
  %125 = load ptr, ptr %12, align 8, !tbaa !5
  %126 = icmp ne ptr %125, null
  br i1 %126, label %127, label %142

127:                                              ; preds = %124
  %128 = load ptr, ptr %13, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.queue_element_s, ptr %128, i32 0, i32 1
  %130 = load ptr, ptr %129, align 8, !tbaa !18
  %131 = load ptr, ptr %12, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.queue_element_s, ptr %131, i32 0, i32 1
  store ptr %130, ptr %132, align 8, !tbaa !18
  %133 = load ptr, ptr %7, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.queue_s, ptr %133, i32 0, i32 2
  %135 = load i16, ptr %134, align 8, !tbaa !9
  %136 = add i16 %135, -1
  store i16 %136, ptr %134, align 8, !tbaa !9
  %137 = load ptr, ptr %13, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.queue_element_s, ptr %137, i32 0, i32 0
  %139 = load ptr, ptr %138, align 8, !tbaa !22
  %140 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %139, ptr %140, align 8, !tbaa !5
  %141 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %141) #3
  br label %144

142:                                              ; preds = %124, %121
  %143 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %143, align 8, !tbaa !5
  store i8 -5, ptr %6, align 1
  store i32 1, ptr %14, align 4
  br label %150

144:                                              ; preds = %127
  br label %145

145:                                              ; preds = %144, %111
  %146 = load ptr, ptr %7, align 8, !tbaa !5
  %147 = getelementptr inbounds %struct.queue_s, ptr %146, i32 0, i32 10
  %148 = load ptr, ptr %147, align 8, !tbaa !23
  %149 = call i32 @pthread_cond_signal(ptr noundef %148) #3
  store i8 0, ptr %6, align 1
  store i32 1, ptr %14, align 4
  br label %150

150:                                              ; preds = %145, %142
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %151

151:                                              ; preds = %150, %66, %28, %17
  %152 = load i8, ptr %6, align 1
  ret i8 %152
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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, !11, i64 16}
!10 = !{!"queue_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 18, !7, i64 20, !7, i64 21, !7, i64 22, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !7, i64 20}
!13 = !{!10, !6, i64 40}
!14 = !{!10, !6, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 0}
!18 = !{!19, !6, i64 8}
!19 = !{!"queue_element_s", !6, i64 0, !6, i64 8}
!20 = distinct !{!20, !16}
!21 = !{!10, !6, i64 8}
!22 = !{!19, !6, i64 0}
!23 = !{!10, !6, i64 48}


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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @pthread_cond_signal(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local signext range(i8 -7, 1) i8 @queue_get_internal(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef readonly %2, ptr noundef readonly %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = icmp eq ptr %0, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  store ptr null, ptr %1, align 8, !tbaa !5
  br label %.loopexit

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i16, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i16 %10, 0
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %8
  %13 = icmp eq ptr %2, null
  br i1 %13, label %17, label %.preheader

.preheader:                                       ; preds = %12
  %14 = getelementptr inbounds i8, ptr %0, i64 20
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  br label %18

17:                                               ; preds = %12
  store ptr null, ptr %1, align 8, !tbaa !5
  br label %.loopexit

18:                                               ; preds = %.preheader, %20
  %19 = load i8, ptr %14, align 4, !tbaa !12
  %.not = icmp eq i8 %19, 0
  br i1 %.not, label %.loopexit, label %20

20:                                               ; preds = %18
  %21 = load ptr, ptr %15, align 8, !tbaa !13
  %22 = load ptr, ptr %16, align 8, !tbaa !14
  %23 = tail call i32 %2(ptr noundef %21, ptr noundef %22) #3
  %.pr = load i16, ptr %9, align 8, !tbaa !9
  %24 = icmp eq i16 %.pr, 0
  br i1 %24, label %18, label %.critedge, !llvm.loop !15

.critedge:                                        ; preds = %20, %8
  %25 = icmp ne ptr %3, null
  %.052 = load ptr, ptr %0, align 8, !tbaa !5
  %26 = icmp ne ptr %.052, null
  %or.cond53 = select i1 %25, i1 %26, i1 false
  br i1 %or.cond53, label %.lr.ph.split, label %.critedge3

.lr.ph.split:                                     ; preds = %.critedge
  %27 = tail call i32 %3(ptr noundef nonnull %.052, ptr noundef %4) #3
  %.not5167 = icmp eq i32 %27, 0
  br i1 %.not5167, label %.critedge100, label %.lr.ph69

28:                                               ; preds = %.lr.ph69
  %29 = tail call i32 %3(ptr noundef nonnull %.0, ptr noundef %4) #3
  %.not51 = icmp eq i32 %29, 0
  br i1 %.not51, label %34, label %.lr.ph69, !llvm.loop !17

.lr.ph69:                                         ; preds = %.lr.ph.split, %28
  %.05568 = phi ptr [ %.0, %28 ], [ %.052, %.lr.ph.split ]
  %30 = getelementptr inbounds i8, ptr %.05568, i64 8
  %.0 = load ptr, ptr %30, align 8, !tbaa !5
  %.not75.not = icmp eq ptr %.0, null
  br i1 %.not75.not, label %.thread87, label %28, !llvm.loop !17

.critedge3:                                       ; preds = %.critedge
  br i1 %26, label %.critedge100, label %.thread87

.critedge100:                                     ; preds = %.lr.ph.split, %.critedge3
  %31 = getelementptr inbounds i8, ptr %.052, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  store ptr %32, ptr %0, align 8, !tbaa !20
  %33 = icmp eq ptr %32, null
  br i1 %33, label %.sink.split, label %39

34:                                               ; preds = %28
  br i1 %.not75.not, label %.thread87, label %35

35:                                               ; preds = %34
  %36 = getelementptr inbounds i8, ptr %.0, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  br label %.sink.split

.thread87:                                        ; preds = %.lr.ph69, %.critedge3, %34
  store ptr null, ptr %1, align 8, !tbaa !5
  br label %.loopexit

.sink.split:                                      ; preds = %.critedge100, %35
  %.sink96 = phi ptr [ %.05568, %35 ], [ %0, %.critedge100 ]
  %.sink = phi ptr [ %37, %35 ], [ null, %.critedge100 ]
  %.0.lcssa91.sink93.ph = phi ptr [ %.0, %35 ], [ %.052, %.critedge100 ]
  %38 = getelementptr inbounds i8, ptr %.sink96, i64 8
  store ptr %.sink, ptr %38, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %.sink.split, %.critedge100
  %.0.lcssa91.sink93 = phi ptr [ %.052, %.critedge100 ], [ %.0.lcssa91.sink93.ph, %.sink.split ]
  %40 = load i16, ptr %9, align 8, !tbaa !9
  %41 = add i16 %40, -1
  store i16 %41, ptr %9, align 8, !tbaa !9
  %42 = load ptr, ptr %.0.lcssa91.sink93, align 8, !tbaa !21
  store ptr %42, ptr %1, align 8, !tbaa !5
  tail call void @free(ptr noundef nonnull %.0.lcssa91.sink93) #3
  %43 = getelementptr inbounds i8, ptr %0, i64 48
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %45 = tail call i32 @pthread_cond_signal(ptr noundef %44) #3
  br label %.loopexit

.loopexit:                                        ; preds = %18, %.thread87, %39, %17, %7
  %.1 = phi i8 [ -1, %7 ], [ -7, %17 ], [ 0, %39 ], [ -5, %.thread87 ], [ -4, %18 ]
  ret i8 %.1
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { 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 = { 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, !11, i64 16}
!10 = !{!"queue_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 18, !7, i64 20, !7, i64 21, !7, i64 22, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !7, i64 20}
!13 = !{!10, !6, i64 40}
!14 = !{!10, !6, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !6, i64 8}
!19 = !{!"queue_element_s", !6, i64 0, !6, i64 8}
!20 = !{!10, !6, i64 0}
!21 = !{!19, !6, i64 0}
!22 = !{!10, !6, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass