; LLVM IR from MakeContributions/DSA :: algorithms/C/queues (double-ended-queue-using-array)

; 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.deque = type { i32, i32, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local void @insertion_rear(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.deque, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.deque, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = sub nsw i32 %10, 1
  %12 = icmp eq i32 %7, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.deque, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %27, label %18

18:                                               ; preds = %13, %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.deque, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = add nsw i32 %21, 1
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.deque, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %18, %13
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %95

29:                                               ; preds = %18
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.deque, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %53

34:                                               ; preds = %29
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.deque, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %36, align 4, !tbaa !11
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.deque, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.deque, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %42, i64 %46
  store i32 %39, ptr %47, align 4, !tbaa !9
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.deque, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.deque, ptr %51, i32 0, i32 0
  store i32 %50, ptr %52, align 8, !tbaa !14
  br label %94

53:                                               ; preds = %29
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.deque, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.deque, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 8, !tbaa !13
  %60 = sub nsw i32 %59, 1
  %61 = icmp eq i32 %56, %60
  br i1 %61, label %62, label %79

62:                                               ; preds = %53
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.deque, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !14
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %79

67:                                               ; preds = %62
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.deque, ptr %68, i32 0, i32 1
  store i32 0, ptr %69, align 4, !tbaa !11
  %70 = load i32, ptr %4, align 4, !tbaa !9
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.deque, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.deque, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !11
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %73, i64 %77
  store i32 %70, ptr %78, align 4, !tbaa !9
  br label %93

79:                                               ; preds = %62, %53
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.deque, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !11
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %81, align 4, !tbaa !11
  %84 = load i32, ptr %4, align 4, !tbaa !9
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.deque, ptr %85, i32 0, i32 3
  %87 = load ptr, ptr %86, align 8, !tbaa !15
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.deque, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 4, !tbaa !11
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i32, ptr %87, i64 %91
  store i32 %84, ptr %92, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %79, %67
  br label %94

94:                                               ; preds = %93, %34
  br label %95

95:                                               ; preds = %94, %27
  ret void
}

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

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"deque", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !6, i64 16}


; 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.1 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @insertion_rear(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = add nsw i32 %6, -1
  %8 = icmp eq i32 %4, %7
  %.pre = load i32, ptr %0, align 8, !tbaa !12
  %9 = icmp eq i32 %.pre, 0
  %or.cond24 = select i1 %8, i1 %9, i1 false
  br i1 %or.cond24, label %13, label %10

10:                                               ; preds = %2
  %11 = add nsw i32 %4, 1
  %12 = icmp eq i32 %11, %.pre
  br i1 %12, label %13, label %15

13:                                               ; preds = %2, %10
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %32

15:                                               ; preds = %10
  %16 = icmp eq i32 %4, -1
  br i1 %16, label %17, label %23

17:                                               ; preds = %15
  store i32 %11, ptr %3, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = zext nneg i32 %11 to i64
  %21 = getelementptr inbounds i32, ptr %19, i64 %20
  store i32 %1, ptr %21, align 4, !tbaa !14
  %22 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %22, ptr %0, align 8, !tbaa !12
  br label %32

23:                                               ; preds = %15
  %24 = icmp ne i32 %4, %7
  %.not = icmp eq i32 %.pre, 0
  %or.cond = or i1 %24, %.not
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  br i1 %or.cond, label %28, label %26

26:                                               ; preds = %23
  store i32 0, ptr %3, align 4, !tbaa !5
  %27 = load ptr, ptr %25, align 8, !tbaa !13
  store i32 %1, ptr %27, align 4, !tbaa !14
  br label %32

28:                                               ; preds = %23
  store i32 %11, ptr %3, align 4, !tbaa !5
  %29 = load ptr, ptr %25, align 8, !tbaa !13
  %30 = sext i32 %11 to i64
  %31 = getelementptr inbounds i32, ptr %29, i64 %30
  store i32 %1, ptr %31, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %17, %28, %26, %13
  ret void
}

attributes #0 = { nofree 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 #1 = { nofree 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" }

!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 4}
!6 = !{!"deque", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!7, !7, i64 0}


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