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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @queue_create() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %4 = call noalias ptr @malloc(i64 noundef 56) #5
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %87

7:                                                ; preds = %0
  %8 = call noalias ptr @malloc(i64 noundef 40) #5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.queue_s, ptr %9, i32 0, i32 8
  store ptr %8, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.queue_s, ptr %11, i32 0, i32 8
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %7
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %16) #4
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %89

17:                                               ; preds = %7
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.queue_s, ptr %18, i32 0, i32 8
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = call i32 @pthread_mutex_init(ptr noundef %20, ptr noundef null) #4
  %22 = call noalias ptr @malloc(i64 noundef 48) #5
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.queue_s, ptr %23, i32 0, i32 9
  store ptr %22, ptr %24, align 8, !tbaa !12
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.queue_s, ptr %25, i32 0, i32 9
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %38

29:                                               ; preds = %17
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.queue_s, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = call i32 @pthread_mutex_destroy(ptr noundef %32) #4
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.queue_s, ptr %34, i32 0, i32 8
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  call void @free(ptr noundef %36) #4
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %37) #4
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %89

38:                                               ; preds = %17
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.queue_s, ptr %39, i32 0, i32 9
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  %42 = call i32 @pthread_cond_init(ptr noundef %41, ptr noundef null) #4
  %43 = call noalias ptr @malloc(i64 noundef 48) #5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.queue_s, ptr %44, i32 0, i32 10
  store ptr %43, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.queue_s, ptr %46, i32 0, i32 10
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %66

50:                                               ; preds = %38
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.queue_s, ptr %51, i32 0, i32 9
  %53 = load ptr, ptr %52, align 8, !tbaa !12
  %54 = call i32 @pthread_cond_destroy(ptr noundef %53) #4
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.queue_s, ptr %55, i32 0, i32 9
  %57 = load ptr, ptr %56, align 8, !tbaa !12
  call void @free(ptr noundef %57) #4
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.queue_s, ptr %58, i32 0, i32 8
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = call i32 @pthread_mutex_destroy(ptr noundef %60) #4
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.queue_s, ptr %62, i32 0, i32 8
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  call void @free(ptr noundef %64) #4
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %65) #4
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %89

66:                                               ; preds = %38
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.queue_s, ptr %67, i32 0, i32 10
  %69 = load ptr, ptr %68, align 8, !tbaa !13
  %70 = call i32 @pthread_cond_init(ptr noundef %69, ptr noundef null) #4
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.queue_s, ptr %71, i32 0, i32 0
  store ptr null, ptr %72, align 8, !tbaa !14
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.queue_s, ptr %73, i32 0, i32 1
  store ptr null, ptr %74, align 8, !tbaa !15
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.queue_s, ptr %75, i32 0, i32 2
  store i16 0, ptr %76, align 8, !tbaa !16
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.queue_s, ptr %77, i32 0, i32 3
  store i16 0, ptr %78, align 2, !tbaa !17
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.queue_s, ptr %79, i32 0, i32 4
  store i8 1, ptr %80, align 4, !tbaa !18
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.queue_s, ptr %81, i32 0, i32 5
  store i8 0, ptr %82, align 1, !tbaa !19
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.queue_s, ptr %83, i32 0, i32 6
  store i8 1, ptr %84, align 2, !tbaa !20
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.queue_s, ptr %85, i32 0, i32 7
  store ptr null, ptr %86, align 8, !tbaa !21
  br label %87

87:                                               ; preds = %66, %0
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %88, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %89

89:                                               ; preds = %87, %50, %29, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %90 = load ptr, ptr %1, align 8
  ret ptr %90
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_destroy(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @pthread_cond_init(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @pthread_cond_destroy(ptr noundef) #3

; 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 = { nounwind 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 #3 = { 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 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!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, !6, i64 40}
!13 = !{!10, !6, i64 48}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !11, i64 16}
!17 = !{!10, !11, i64 18}
!18 = !{!10, !7, i64 20}
!19 = !{!10, !7, i64 21}
!20 = !{!10, !7, i64 22}
!21 = !{!10, !6, i64 24}


; 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: nounwind uwtable
define dso_local noalias noundef ptr @queue_create() local_unnamed_addr #0 {
  %1 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %28, label %2

2:                                                ; preds = %0
  %3 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %4 = getelementptr inbounds i8, ptr %1, i64 32
  store ptr %3, ptr %4, align 8, !tbaa !5
  %5 = icmp eq ptr %3, null
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  tail call void @free(ptr noundef nonnull %1) #6
  br label %28

7:                                                ; preds = %2
  %8 = tail call i32 @pthread_mutex_init(ptr noundef nonnull %3, ptr noundef null) #6
  %9 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #5
  %10 = getelementptr inbounds i8, ptr %1, i64 40
  store ptr %9, ptr %10, align 8, !tbaa !11
  %11 = icmp eq ptr %9, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %7
  %13 = tail call i32 @pthread_mutex_destroy(ptr noundef nonnull %3) #6
  tail call void @free(ptr noundef nonnull %3) #6
  tail call void @free(ptr noundef nonnull %1) #6
  br label %28

14:                                               ; preds = %7
  %15 = tail call i32 @pthread_cond_init(ptr noundef nonnull %9, ptr noundef null) #6
  %16 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #5
  %17 = getelementptr inbounds i8, ptr %1, i64 48
  store ptr %16, ptr %17, align 8, !tbaa !12
  %18 = icmp eq ptr %16, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %14
  %20 = tail call i32 @pthread_cond_destroy(ptr noundef nonnull %9) #6
  tail call void @free(ptr noundef nonnull %9) #6
  %21 = tail call i32 @pthread_mutex_destroy(ptr noundef nonnull %3) #6
  tail call void @free(ptr noundef nonnull %3) #6
  tail call void @free(ptr noundef nonnull %1) #6
  br label %28

22:                                               ; preds = %14
  %23 = tail call i32 @pthread_cond_init(ptr noundef nonnull %16, ptr noundef null) #6
  %24 = getelementptr inbounds i8, ptr %1, i64 20
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %1, i8 0, i64 20, i1 false)
  store i8 1, ptr %24, align 4, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %1, i64 21
  store i8 0, ptr %25, align 1, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %1, i64 22
  store i8 1, ptr %26, align 2, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr null, ptr %27, align 8, !tbaa !16
  br label %28

28:                                               ; preds = %0, %22, %19, %12, %6
  %.0 = phi ptr [ null, %6 ], [ null, %12 ], [ null, %19 ], [ %1, %22 ], [ null, %0 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_destroy(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_cond_init(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_cond_destroy(ptr noundef) local_unnamed_addr #3

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

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { 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 #3 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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, !7, i64 32}
!6 = !{!"queue_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !8, i64 20, !8, i64 21, !8, i64 22, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 40}
!12 = !{!6, !7, i64 48}
!13 = !{!6, !8, i64 20}
!14 = !{!6, !8, i64 21}
!15 = !{!6, !8, i64 22}
!16 = !{!6, !7, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass