; LLVM IR from christo1030/ReaderWriter :: OS4 (main)

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

%union.sem_t = type { i64, [24 x i8] }

@sem = external dso_local global %union.sem_t, align 8
@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [10 x i64], align 16
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca [10 x i32], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 80, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #4
  %6 = call i32 @sem_init(ptr noundef @sem, i32 noundef 0, i32 noundef 1) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %26, %0
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 10
  br i1 %9, label %10, label %29

10:                                               ; preds = %7
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [10 x i32], ptr %5, i64 0, i64 %14
  store i32 %12, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10 x i64], ptr %2, i64 0, i64 %17
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x i32], ptr %5, i64 0, i64 %20
  %22 = call i32 @pthread_create(ptr noundef %18, ptr noundef null, ptr noundef @reader, ptr noundef %21) #4
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %10
  call void @perror(ptr noundef @.str)
  br label %25

25:                                               ; preds = %24, %10
  br label %26

26:                                               ; preds = %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %7, !llvm.loop !9

29:                                               ; preds = %7
  %30 = call i32 @pthread_create(ptr noundef %3, ptr noundef null, ptr noundef @writer, ptr noundef null) #4
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  call void @perror(ptr noundef @.str.1)
  br label %33

33:                                               ; preds = %32, %29
  %34 = load i64, ptr %3, align 8, !tbaa !11
  %35 = call i32 @pthread_join(i64 noundef %34, ptr noundef null)
  %36 = call i32 @sem_destroy(ptr noundef @sem) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %2) #4
  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 i32 @sem_init(ptr noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @reader(ptr noundef) #0

declare void @perror(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @writer(ptr noundef) #0

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

; Function Attrs: nounwind
declare i32 @sem_destroy(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 = { 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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


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

%union.sem_t = type { i64, [24 x i8] }

@sem = external dso_local global %union.sem_t, align 8
@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [10 x i64], align 16
  %2 = alloca i64, align 8
  %3 = alloca [10 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #5
  %4 = tail call i32 @sem_init(ptr noundef nonnull @sem, i32 noundef 0, i32 noundef 1) #5
  store i32 1, ptr %3, align 16, !tbaa !5
  %5 = call i32 @pthread_create(ptr noundef nonnull %1, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %3) #5
  %.not6 = icmp eq i32 %5, 0
  br i1 %.not6, label %7, label %6

6:                                                ; preds = %0
  call void @perror(ptr noundef nonnull @.str) #6
  br label %7

7:                                                ; preds = %0, %6
  %8 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 2, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = call i32 @pthread_create(ptr noundef nonnull %9, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %8) #5
  %.not6.1 = icmp eq i32 %10, 0
  br i1 %.not6.1, label %12, label %11

11:                                               ; preds = %7
  call void @perror(ptr noundef nonnull @.str) #6
  br label %12

12:                                               ; preds = %11, %7
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 3, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = call i32 @pthread_create(ptr noundef nonnull %14, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %13) #5
  %.not6.2 = icmp eq i32 %15, 0
  br i1 %.not6.2, label %17, label %16

16:                                               ; preds = %12
  call void @perror(ptr noundef nonnull @.str) #6
  br label %17

17:                                               ; preds = %16, %12
  %18 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 4, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = call i32 @pthread_create(ptr noundef nonnull %19, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %18) #5
  %.not6.3 = icmp eq i32 %20, 0
  br i1 %.not6.3, label %22, label %21

21:                                               ; preds = %17
  call void @perror(ptr noundef nonnull @.str) #6
  br label %22

22:                                               ; preds = %21, %17
  %23 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 5, ptr %23, align 16, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %1, i64 32
  %25 = call i32 @pthread_create(ptr noundef nonnull %24, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %23) #5
  %.not6.4 = icmp eq i32 %25, 0
  br i1 %.not6.4, label %27, label %26

26:                                               ; preds = %22
  call void @perror(ptr noundef nonnull @.str) #6
  br label %27

27:                                               ; preds = %26, %22
  %28 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 6, ptr %28, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 40
  %30 = call i32 @pthread_create(ptr noundef nonnull %29, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %28) #5
  %.not6.5 = icmp eq i32 %30, 0
  br i1 %.not6.5, label %32, label %31

31:                                               ; preds = %27
  call void @perror(ptr noundef nonnull @.str) #6
  br label %32

32:                                               ; preds = %31, %27
  %33 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 7, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %1, i64 48
  %35 = call i32 @pthread_create(ptr noundef nonnull %34, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %33) #5
  %.not6.6 = icmp eq i32 %35, 0
  br i1 %.not6.6, label %37, label %36

36:                                               ; preds = %32
  call void @perror(ptr noundef nonnull @.str) #6
  br label %37

37:                                               ; preds = %36, %32
  %38 = getelementptr inbounds i8, ptr %3, i64 28
  store i32 8, ptr %38, align 4, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %1, i64 56
  %40 = call i32 @pthread_create(ptr noundef nonnull %39, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %38) #5
  %.not6.7 = icmp eq i32 %40, 0
  br i1 %.not6.7, label %42, label %41

41:                                               ; preds = %37
  call void @perror(ptr noundef nonnull @.str) #6
  br label %42

42:                                               ; preds = %41, %37
  %43 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 9, ptr %43, align 16, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %1, i64 64
  %45 = call i32 @pthread_create(ptr noundef nonnull %44, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %43) #5
  %.not6.8 = icmp eq i32 %45, 0
  br i1 %.not6.8, label %47, label %46

46:                                               ; preds = %42
  call void @perror(ptr noundef nonnull @.str) #6
  br label %47

47:                                               ; preds = %46, %42
  %48 = getelementptr inbounds i8, ptr %3, i64 36
  store i32 10, ptr %48, align 4, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %1, i64 72
  %50 = call i32 @pthread_create(ptr noundef nonnull %49, ptr noundef null, ptr noundef nonnull @reader, ptr noundef nonnull %48) #5
  %.not6.9 = icmp eq i32 %50, 0
  br i1 %.not6.9, label %52, label %51

51:                                               ; preds = %47
  call void @perror(ptr noundef nonnull @.str) #6
  br label %52

52:                                               ; preds = %51, %47
  %53 = call i32 @pthread_create(ptr noundef nonnull %2, ptr noundef null, ptr noundef nonnull @writer, ptr noundef null) #5
  %.not = icmp eq i32 %53, 0
  br i1 %.not, label %55, label %54

54:                                               ; preds = %52
  call void @perror(ptr noundef nonnull @.str.1) #6
  br label %55

55:                                               ; preds = %54, %52
  %56 = load i64, ptr %2, align 8, !tbaa !9
  %57 = call i32 @pthread_join(i64 noundef %56, ptr noundef null) #5
  %58 = call i32 @sem_destroy(ptr noundef nonnull @sem) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %1) #5
  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 i32 @sem_init(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @reader(ptr noundef) #0

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @writer(ptr noundef) #0

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

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

; Function Attrs: mustprogress 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 = { 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 = { 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 #4 = { "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 = { nounwind }
attributes #6 = { cold }

!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 = !{!"long", !7, i64 0}


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