; LLVM IR from BurntSushi/clibs :: libds/examples (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.job = type { ptr, ptr, ptr }

@cpus = external hidden global i32, align 4
@num_producers = external hidden global i32, align 4
@num_consumers = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [55 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.job, align 8
  %12 = alloca %struct.job, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %13 = call i64 @sysconf(i32 noundef 84) #7
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr @cpus, align 4, !tbaa !5
  %15 = load i32, ptr @cpus, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %0
  br label %20

18:                                               ; preds = %0
  %19 = load i32, ptr @cpus, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %18, %17
  %21 = phi i32 [ 1, %17 ], [ %19, %18 ]
  store i32 %21, ptr @cpus, align 4, !tbaa !5
  %22 = load i32, ptr @num_producers, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = load i32, ptr @cpus, align 4, !tbaa !5
  br label %28

26:                                               ; preds = %20
  %27 = load i32, ptr @num_producers, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi i32 [ %25, %24 ], [ %27, %26 ]
  store i32 %29, ptr @num_producers, align 4, !tbaa !5
  %30 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %28
  %33 = load i32, ptr @cpus, align 4, !tbaa !5
  br label %36

34:                                               ; preds = %28
  %35 = load i32, ptr @num_consumers, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %34, %32
  %37 = phi i32 [ %33, %32 ], [ %35, %34 ]
  store i32 %37, ptr @num_consumers, align 4, !tbaa !5
  %38 = call ptr @ds_queue_create(i32 noundef 10)
  store ptr %38, ptr %2, align 8, !tbaa !9
  %39 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %40 = call ptr @ds_queue_create(i32 noundef %39)
  store ptr %40, ptr %3, align 8, !tbaa !9
  %41 = load i32, ptr @num_producers, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = mul i64 %42, 8
  %44 = call noalias ptr @malloc(i64 noundef %43) #8
  store ptr %44, ptr %4, align 8, !tbaa !9
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %36
  br label %48

47:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 98, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

48:                                               ; preds = %46
  %49 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul i64 %50, 8
  %52 = call noalias ptr @malloc(i64 noundef %51) #8
  store ptr %52, ptr %5, align 8, !tbaa !9
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %48
  br label %56

55:                                               ; preds = %48
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 99, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

56:                                               ; preds = %54
  %57 = load i32, ptr @num_producers, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = mul i64 %58, 24
  %60 = call noalias ptr @malloc(i64 noundef %59) #8
  store ptr %60, ptr %6, align 8, !tbaa !9
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %63

62:                                               ; preds = %56
  br label %64

63:                                               ; preds = %56
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 100, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

64:                                               ; preds = %62
  %65 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = mul i64 %66, 24
  %68 = call noalias ptr @malloc(i64 noundef %67) #8
  store ptr %68, ptr %7, align 8, !tbaa !9
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %71

70:                                               ; preds = %64
  br label %72

71:                                               ; preds = %64
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 101, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

72:                                               ; preds = %70
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %94, %72
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = load i32, ptr @num_producers, align 4, !tbaa !5
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %77, label %97

77:                                               ; preds = %73
  %78 = load ptr, ptr %6, align 8, !tbaa !9
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds %struct.job, ptr %78, i64 %80
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #7
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = load ptr, ptr %2, align 8, !tbaa !9
  %84 = load ptr, ptr %3, align 8, !tbaa !9
  call void @job_create(ptr dead_on_unwind writable sret(%struct.job) align 8 %11, i32 noundef %82, ptr noundef %83, ptr noundef %84)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %81, ptr align 8 %11, i64 24, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #7
  %85 = load ptr, ptr %4, align 8, !tbaa !9
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i64, ptr %85, i64 %87
  %89 = load ptr, ptr %6, align 8, !tbaa !9
  %90 = load i32, ptr %8, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds %struct.job, ptr %89, i64 %91
  %93 = call i32 @pthread_create(ptr noundef %88, ptr noundef null, ptr noundef @producer, ptr noundef %92) #7
  br label %94

94:                                               ; preds = %77
  %95 = load i32, ptr %8, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %8, align 4, !tbaa !5
  br label %73, !llvm.loop !12

97:                                               ; preds = %73
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %119, %97
  %99 = load i32, ptr %8, align 4, !tbaa !5
  %100 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %101 = icmp slt i32 %99, %100
  br i1 %101, label %102, label %122

102:                                              ; preds = %98
  %103 = load ptr, ptr %7, align 8, !tbaa !9
  %104 = load i32, ptr %8, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds %struct.job, ptr %103, i64 %105
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #7
  %107 = load i32, ptr %8, align 4, !tbaa !5
  %108 = load ptr, ptr %2, align 8, !tbaa !9
  %109 = load ptr, ptr %3, align 8, !tbaa !9
  call void @job_create(ptr dead_on_unwind writable sret(%struct.job) align 8 %12, i32 noundef %107, ptr noundef %108, ptr noundef %109)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %106, ptr align 8 %12, i64 24, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #7
  %110 = load ptr, ptr %5, align 8, !tbaa !9
  %111 = load i32, ptr %8, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds i64, ptr %110, i64 %112
  %114 = load ptr, ptr %7, align 8, !tbaa !9
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds %struct.job, ptr %114, i64 %116
  %118 = call i32 @pthread_create(ptr noundef %113, ptr noundef null, ptr noundef @consumer, ptr noundef %117) #7
  br label %119

119:                                              ; preds = %102
  %120 = load i32, ptr %8, align 4, !tbaa !5
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr %8, align 4, !tbaa !5
  br label %98, !llvm.loop !14

122:                                              ; preds = %98
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %123

123:                                              ; preds = %138, %122
  %124 = load i32, ptr %8, align 4, !tbaa !5
  %125 = load i32, ptr @num_producers, align 4, !tbaa !5
  %126 = icmp slt i32 %124, %125
  br i1 %126, label %127, label %141

127:                                              ; preds = %123
  %128 = load ptr, ptr %4, align 8, !tbaa !9
  %129 = load i32, ptr %8, align 4, !tbaa !5
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds i64, ptr %128, i64 %130
  %132 = load i64, ptr %131, align 8, !tbaa !15
  %133 = call i32 @pthread_join(i64 noundef %132, ptr noundef null)
  %134 = icmp eq i32 0, %133
  br i1 %134, label %135, label %136

135:                                              ; preds = %127
  br label %137

136:                                              ; preds = %127
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 118, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

137:                                              ; preds = %135
  br label %138

138:                                              ; preds = %137
  %139 = load i32, ptr %8, align 4, !tbaa !5
  %140 = add nsw i32 %139, 1
  store i32 %140, ptr %8, align 4, !tbaa !5
  br label %123, !llvm.loop !17

141:                                              ; preds = %123
  %142 = load ptr, ptr %2, align 8, !tbaa !9
  call void @ds_queue_close(ptr noundef %142)
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %143

143:                                              ; preds = %154, %141
  %144 = load i32, ptr %8, align 4, !tbaa !5
  %145 = load i32, ptr @num_producers, align 4, !tbaa !5
  %146 = icmp slt i32 %144, %145
  br i1 %146, label %147, label %157

147:                                              ; preds = %143
  %148 = load ptr, ptr %6, align 8, !tbaa !9
  %149 = load i32, ptr %8, align 4, !tbaa !5
  %150 = sext i32 %149 to i64
  %151 = getelementptr inbounds %struct.job, ptr %148, i64 %150
  %152 = getelementptr inbounds %struct.job, ptr %151, i32 0, i32 2
  %153 = load ptr, ptr %152, align 8, !tbaa !18
  call void @free(ptr noundef %153) #7
  br label %154

154:                                              ; preds = %147
  %155 = load i32, ptr %8, align 4, !tbaa !5
  %156 = add nsw i32 %155, 1
  store i32 %156, ptr %8, align 4, !tbaa !5
  br label %143, !llvm.loop !20

157:                                              ; preds = %143
  %158 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %158) #7
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %159

159:                                              ; preds = %174, %157
  %160 = load i32, ptr %8, align 4, !tbaa !5
  %161 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %162 = icmp slt i32 %160, %161
  br i1 %162, label %163, label %177

163:                                              ; preds = %159
  %164 = load ptr, ptr %5, align 8, !tbaa !9
  %165 = load i32, ptr %8, align 4, !tbaa !5
  %166 = sext i32 %165 to i64
  %167 = getelementptr inbounds i64, ptr %164, i64 %166
  %168 = load i64, ptr %167, align 8, !tbaa !15
  %169 = call i32 @pthread_join(i64 noundef %168, ptr noundef null)
  %170 = icmp eq i32 0, %169
  br i1 %170, label %171, label %172

171:                                              ; preds = %163
  br label %173

172:                                              ; preds = %163
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 132, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

173:                                              ; preds = %171
  br label %174

174:                                              ; preds = %173
  %175 = load i32, ptr %8, align 4, !tbaa !5
  %176 = add nsw i32 %175, 1
  store i32 %176, ptr %8, align 4, !tbaa !5
  br label %159, !llvm.loop !21

177:                                              ; preds = %159
  %178 = load ptr, ptr %3, align 8, !tbaa !9
  call void @ds_queue_close(ptr noundef %178)
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %179

179:                                              ; preds = %190, %177
  %180 = load i32, ptr %8, align 4, !tbaa !5
  %181 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %182 = icmp slt i32 %180, %181
  br i1 %182, label %183, label %193

183:                                              ; preds = %179
  %184 = load ptr, ptr %7, align 8, !tbaa !9
  %185 = load i32, ptr %8, align 4, !tbaa !5
  %186 = sext i32 %185 to i64
  %187 = getelementptr inbounds %struct.job, ptr %184, i64 %186
  %188 = getelementptr inbounds %struct.job, ptr %187, i32 0, i32 2
  %189 = load ptr, ptr %188, align 8, !tbaa !18
  call void @free(ptr noundef %189) #7
  br label %190

190:                                              ; preds = %183
  %191 = load i32, ptr %8, align 4, !tbaa !5
  %192 = add nsw i32 %191, 1
  store i32 %192, ptr %8, align 4, !tbaa !5
  br label %179, !llvm.loop !22

193:                                              ; preds = %179
  %194 = load ptr, ptr %7, align 8, !tbaa !9
  call void @free(ptr noundef %194) #7
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %195

195:                                              ; preds = %199, %193
  %196 = load ptr, ptr %3, align 8, !tbaa !9
  %197 = call ptr @ds_queue_get(ptr noundef %196)
  store ptr %197, ptr %9, align 8, !tbaa !9
  %198 = icmp ne ptr null, %197
  br i1 %198, label %199, label %205

199:                                              ; preds = %195
  %200 = load ptr, ptr %9, align 8, !tbaa !9
  %201 = load i32, ptr %200, align 4, !tbaa !5
  %202 = load i32, ptr %10, align 4, !tbaa !5
  %203 = add nsw i32 %202, %201
  store i32 %203, ptr %10, align 4, !tbaa !5
  %204 = load ptr, ptr %9, align 8, !tbaa !9
  call void @free(ptr noundef %204) #7
  br label %195, !llvm.loop !23

205:                                              ; preds = %195
  %206 = load i32, ptr @num_producers, align 4, !tbaa !5
  %207 = sdiv i32 100000, %206
  %208 = load i32, ptr @num_producers, align 4, !tbaa !5
  %209 = mul nsw i32 %207, %208
  %210 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %209)
  %211 = load i32, ptr %10, align 4, !tbaa !5
  %212 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %211)
  %213 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %213) #7
  %214 = load ptr, ptr %4, align 8, !tbaa !9
  call void @free(ptr noundef %214) #7
  %215 = load ptr, ptr %2, align 8, !tbaa !9
  call void @ds_queue_free(ptr noundef %215)
  %216 = load ptr, ptr %3, align 8, !tbaa !9
  call void @ds_queue_free(ptr noundef %216)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  ret i32 0
}

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

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) #2

declare ptr @ds_queue_create(i32 noundef) #3

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

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

; Function Attrs: nounwind uwtable
declare hidden void @job_create(ptr dead_on_unwind noalias writable sret(%struct.job) align 8, i32 noundef, ptr noundef, ptr noundef) #0

; 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) #6

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

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @producer(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @consumer(ptr noundef) #0

declare i32 @pthread_join(i64 noundef, ptr noundef) #3

declare void @ds_queue_close(ptr noundef) #3

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

declare ptr @ds_queue_get(ptr noundef) #3

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

declare void @ds_queue_free(ptr noundef) #3

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 "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 = { "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 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 #5 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { 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 = !{i64 0, i64 8, !9, i64 8, i64 8, !9, i64 16, i64 8, !9}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !13}
!18 = !{!19, !10, i64 16}
!19 = !{!"job", !10, i64 0, !10, i64 8, !10, i64 16}
!20 = distinct !{!20, !13}
!21 = distinct !{!21, !13}
!22 = distinct !{!22, !13}
!23 = distinct !{!23, !13}


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

@cpus = external hidden local_unnamed_addr global i32, align 4
@num_producers = external hidden local_unnamed_addr global i32, align 4
@num_consumers = external hidden local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [55 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.job, align 8
  %2 = alloca %struct.job, align 8
  %3 = tail call i64 @sysconf(i32 noundef 84) #10
  %4 = trunc i64 %3 to i32
  %5 = tail call i32 @llvm.umax.i32(i32 %4, i32 1)
  store i32 %5, ptr @cpus, align 4, !tbaa !5
  %6 = load i32, ptr @num_producers, align 4
  %7 = icmp eq i32 %6, 0
  %8 = select i1 %7, i32 %5, i32 %6
  store i32 %8, ptr @num_producers, align 4, !tbaa !5
  %9 = load i32, ptr @num_consumers, align 4
  %10 = icmp eq i32 %9, 0
  %11 = select i1 %10, i32 %5, i32 %9
  store i32 %11, ptr @num_consumers, align 4, !tbaa !5
  %12 = tail call ptr @ds_queue_create(i32 noundef 10) #10
  %13 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %14 = tail call ptr @ds_queue_create(i32 noundef %13) #10
  %15 = load i32, ptr @num_producers, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = shl nsw i64 %16, 3
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #11
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %19, label %20

19:                                               ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 98, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #12
  unreachable

20:                                               ; preds = %0
  %21 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = shl nsw i64 %22, 3
  %24 = tail call noalias ptr @malloc(i64 noundef %23) #11
  %.not56 = icmp eq ptr %24, null
  br i1 %.not56, label %25, label %26

25:                                               ; preds = %20
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 99, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #12
  unreachable

26:                                               ; preds = %20
  %27 = mul nsw i64 %16, 24
  %28 = tail call noalias ptr @malloc(i64 noundef %27) #11
  %.not57 = icmp eq ptr %28, null
  br i1 %.not57, label %29, label %30

29:                                               ; preds = %26
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 100, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #12
  unreachable

30:                                               ; preds = %26
  %31 = mul nsw i64 %22, 24
  %32 = tail call noalias ptr @malloc(i64 noundef %31) #11
  %.not58 = icmp eq ptr %32, null
  br i1 %.not58, label %34, label %.preheader61

.preheader61:                                     ; preds = %30
  %33 = icmp sgt i32 %15, 0
  br i1 %33, label %.lr.ph, label %.preheader60

34:                                               ; preds = %30
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 101, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #12
  unreachable

.preheader60.loopexit:                            ; preds = %.lr.ph
  %.pre = load i32, ptr @num_consumers, align 4, !tbaa !5
  br label %.preheader60

.preheader60:                                     ; preds = %.preheader60.loopexit, %.preheader61
  %35 = phi i32 [ %42, %.preheader60.loopexit ], [ %15, %.preheader61 ]
  %36 = phi i32 [ %.pre, %.preheader60.loopexit ], [ %21, %.preheader61 ]
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.lr.ph64, label %.preheader

.lr.ph:                                           ; preds = %.preheader61, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader61 ]
  %38 = getelementptr inbounds %struct.job, ptr %28, i64 %indvars.iv
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #10
  %39 = trunc nuw nsw i64 %indvars.iv to i32
  call void @job_create(ptr dead_on_unwind nonnull writable sret(%struct.job) align 8 %1, i32 noundef %39, ptr noundef %12, ptr noundef %14)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %38, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 24, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #10
  %40 = getelementptr inbounds i64, ptr %18, i64 %indvars.iv
  %41 = call i32 @pthread_create(ptr noundef nonnull %40, ptr noundef null, ptr noundef nonnull @producer, ptr noundef nonnull %38) #10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr @num_producers, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next, %43
  br i1 %44, label %.lr.ph, label %.preheader60.loopexit, !llvm.loop !12

.preheader.loopexit:                              ; preds = %.lr.ph64
  %.pre100 = load i32, ptr @num_producers, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.preheader60
  %45 = phi i32 [ %.pre100, %.preheader.loopexit ], [ %35, %.preheader60 ]
  %46 = icmp sgt i32 %45, 0
  br i1 %46, label %.lr.ph66, label %._crit_edge

.lr.ph64:                                         ; preds = %.preheader60, %.lr.ph64
  %indvars.iv85 = phi i64 [ %indvars.iv.next86, %.lr.ph64 ], [ 0, %.preheader60 ]
  %47 = getelementptr inbounds %struct.job, ptr %32, i64 %indvars.iv85
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #10
  %48 = trunc nuw nsw i64 %indvars.iv85 to i32
  call void @job_create(ptr dead_on_unwind nonnull writable sret(%struct.job) align 8 %2, i32 noundef %48, ptr noundef %12, ptr noundef %14)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %47, ptr noundef nonnull align 8 dereferenceable(24) %2, i64 24, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #10
  %49 = getelementptr inbounds i64, ptr %24, i64 %indvars.iv85
  %50 = call i32 @pthread_create(ptr noundef nonnull %49, ptr noundef null, ptr noundef nonnull @consumer, ptr noundef nonnull %47) #10
  %indvars.iv.next86 = add nuw nsw i64 %indvars.iv85, 1
  %51 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = icmp slt i64 %indvars.iv.next86, %52
  br i1 %53, label %.lr.ph64, label %.preheader.loopexit, !llvm.loop !14

54:                                               ; preds = %.lr.ph66
  %indvars.iv.next89 = add nuw nsw i64 %indvars.iv88, 1
  %55 = load i32, ptr @num_producers, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = icmp slt i64 %indvars.iv.next89, %56
  br i1 %57, label %.lr.ph66, label %._crit_edge, !llvm.loop !15

.lr.ph66:                                         ; preds = %.preheader, %54
  %indvars.iv88 = phi i64 [ %indvars.iv.next89, %54 ], [ 0, %.preheader ]
  %58 = getelementptr inbounds i64, ptr %18, i64 %indvars.iv88
  %59 = load i64, ptr %58, align 8, !tbaa !16
  %60 = call i32 @pthread_join(i64 noundef %59, ptr noundef null) #10
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %54, label %62

62:                                               ; preds = %.lr.ph66
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 118, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #12
  unreachable

._crit_edge:                                      ; preds = %54, %.preheader
  call void @ds_queue_close(ptr noundef %12) #10
  %63 = load i32, ptr @num_producers, align 4, !tbaa !5
  %64 = icmp sgt i32 %63, 0
  br i1 %64, label %.lr.ph69, label %._crit_edge70

.lr.ph69:                                         ; preds = %._crit_edge, %.lr.ph69
  %indvars.iv91 = phi i64 [ %indvars.iv.next92, %.lr.ph69 ], [ 0, %._crit_edge ]
  %65 = getelementptr inbounds %struct.job, ptr %28, i64 %indvars.iv91, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  call void @free(ptr noundef %66) #10
  %indvars.iv.next92 = add nuw nsw i64 %indvars.iv91, 1
  %67 = load i32, ptr @num_producers, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = icmp slt i64 %indvars.iv.next92, %68
  br i1 %69, label %.lr.ph69, label %._crit_edge70, !llvm.loop !20

._crit_edge70:                                    ; preds = %.lr.ph69, %._crit_edge
  call void @free(ptr noundef %28) #10
  %70 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %71 = icmp sgt i32 %70, 0
  br i1 %71, label %.lr.ph73, label %._crit_edge74

72:                                               ; preds = %.lr.ph73
  %indvars.iv.next95 = add nuw nsw i64 %indvars.iv94, 1
  %73 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = icmp slt i64 %indvars.iv.next95, %74
  br i1 %75, label %.lr.ph73, label %._crit_edge74, !llvm.loop !21

.lr.ph73:                                         ; preds = %._crit_edge70, %72
  %indvars.iv94 = phi i64 [ %indvars.iv.next95, %72 ], [ 0, %._crit_edge70 ]
  %76 = getelementptr inbounds i64, ptr %24, i64 %indvars.iv94
  %77 = load i64, ptr %76, align 8, !tbaa !16
  %78 = call i32 @pthread_join(i64 noundef %77, ptr noundef null) #10
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %72, label %80

80:                                               ; preds = %.lr.ph73
  call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 132, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #12
  unreachable

._crit_edge74:                                    ; preds = %72, %._crit_edge70
  call void @ds_queue_close(ptr noundef %14) #10
  %81 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %82 = icmp sgt i32 %81, 0
  br i1 %82, label %.lr.ph77, label %._crit_edge78

.lr.ph77:                                         ; preds = %._crit_edge74, %.lr.ph77
  %indvars.iv97 = phi i64 [ %indvars.iv.next98, %.lr.ph77 ], [ 0, %._crit_edge74 ]
  %83 = getelementptr inbounds %struct.job, ptr %32, i64 %indvars.iv97, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !18
  call void @free(ptr noundef %84) #10
  %indvars.iv.next98 = add nuw nsw i64 %indvars.iv97, 1
  %85 = load i32, ptr @num_consumers, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = icmp slt i64 %indvars.iv.next98, %86
  br i1 %87, label %.lr.ph77, label %._crit_edge78, !llvm.loop !22

._crit_edge78:                                    ; preds = %.lr.ph77, %._crit_edge74
  call void @free(ptr noundef %32) #10
  %88 = call ptr @ds_queue_get(ptr noundef %14) #10
  %.not5979 = icmp eq ptr %88, null
  br i1 %.not5979, label %._crit_edge83, label %.lr.ph82

.lr.ph82:                                         ; preds = %._crit_edge78, %.lr.ph82
  %89 = phi ptr [ %92, %.lr.ph82 ], [ %88, %._crit_edge78 ]
  %.080 = phi i32 [ %91, %.lr.ph82 ], [ 0, %._crit_edge78 ]
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = add nsw i32 %90, %.080
  call void @free(ptr noundef nonnull %89) #10
  %92 = call ptr @ds_queue_get(ptr noundef %14) #10
  %.not59 = icmp eq ptr %92, null
  br i1 %.not59, label %._crit_edge83, label %.lr.ph82, !llvm.loop !23

._crit_edge83:                                    ; preds = %.lr.ph82, %._crit_edge78
  %.0.lcssa = phi i32 [ 0, %._crit_edge78 ], [ %91, %.lr.ph82 ]
  %93 = load i32, ptr @num_producers, align 4, !tbaa !5
  %94 = srem i32 100000, %93
  %95 = sub nuw nsw i32 100000, %94
  %96 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %95)
  %97 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %.0.lcssa)
  call void @free(ptr noundef %24) #10
  call void @free(ptr noundef %18) #10
  call void @ds_queue_free(ptr noundef %12) #10
  call void @ds_queue_free(ptr noundef %14) #10
  ret i32 0
}

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

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) local_unnamed_addr #2

declare ptr @ds_queue_create(i32 noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
declare hidden void @job_create(ptr dead_on_unwind noalias writable sret(%struct.job) align 8, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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) #6

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @producer(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @consumer(ptr noundef) #0

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #3

declare void @ds_queue_close(ptr noundef) local_unnamed_addr #3

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

declare ptr @ds_queue_get(ptr noundef) local_unnamed_addr #3

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

declare void @ds_queue_free(ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #9

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { "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 = { 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 #5 = { 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 #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 #8 = { 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 #9 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #10 = { nounwind }
attributes #11 = { nounwind allocsize(0) }
attributes #12 = { 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 = !{i64 0, i64 8, !10, i64 8, i64 8, !10, i64 16, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !11, i64 16}
!19 = !{!"job", !11, i64 0, !11, i64 8, !11, i64 16}
!20 = distinct !{!20, !13}
!21 = distinct !{!21, !13}
!22 = distinct !{!22, !13}
!23 = distinct !{!23, !13}


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