; LLVM IR from google/esh :: examples/emulation/armv8A-64-smp/multicore (multicore)

; 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.lock_t = type { %struct.spinlock, i32 }
%struct.spinlock = type { i64, i64, i64, ptr, i64 }

@pr = external global %struct.lock_t, align 8
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1

declare void @spin_lock(ptr noundef) #0

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

declare void @spin_unlock(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @test_fun1(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %24, %2
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = icmp sle i32 %7, 10
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %27

10:                                               ; preds = %6
  br label %11

11:                                               ; preds = %10
  %12 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  call void @spin_lock(ptr noundef @pr)
  br label %15

15:                                               ; preds = %14, %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %16)
  %18 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  call void @spin_unlock(ptr noundef @pr)
  br label %21

21:                                               ; preds = %20, %15
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !5
  br label %6, !llvm.loop !15

27:                                               ; preds = %9
  ret i32 0
}

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

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

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{!12, !6, i64 40}
!12 = !{!"lock_t", !13, i64 0, !6, i64 40}
!13 = !{!"spinlock", !14, i64 0, !14, i64 8, !14, i64 16, !10, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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.lock_t = type { %struct.spinlock, i32 }
%struct.spinlock = type { i64, i64, i64, ptr, i64 }

@pr = external global %struct.lock_t, align 8
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1

declare void @spin_lock(ptr noundef) local_unnamed_addr #0

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

declare void @spin_unlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @test_fun1(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #2 {
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %5, label %4

4:                                                ; preds = %2
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %5

5:                                                ; preds = %4, %2
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3 = icmp eq i32 %7, 0
  br i1 %.not3, label %.thread, label %8

8:                                                ; preds = %5
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not.1 = icmp eq i32 %.pre, 0
  br i1 %.not.1, label %.thread, label %9

9:                                                ; preds = %8
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread

.thread:                                          ; preds = %5, %9, %8
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.1 = icmp eq i32 %11, 0
  br i1 %.not3.1, label %.thread15, label %12

12:                                               ; preds = %.thread
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre5 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not.2 = icmp eq i32 %.pre5, 0
  br i1 %.not.2, label %.thread15, label %13

13:                                               ; preds = %12
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread15

.thread15:                                        ; preds = %.thread, %13, %12
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.2 = icmp eq i32 %15, 0
  br i1 %.not3.2, label %.thread17, label %16

16:                                               ; preds = %.thread15
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre6 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not.3 = icmp eq i32 %.pre6, 0
  br i1 %.not.3, label %.thread17, label %17

17:                                               ; preds = %16
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread17

.thread17:                                        ; preds = %.thread15, %17, %16
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.3 = icmp eq i32 %19, 0
  br i1 %.not3.3, label %.thread19, label %20

20:                                               ; preds = %.thread17
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre7 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %21 = icmp eq i32 %.pre7, 0
  br i1 %21, label %.thread19, label %22

22:                                               ; preds = %20
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread19

.thread19:                                        ; preds = %.thread17, %22, %20
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.4 = icmp eq i32 %24, 0
  br i1 %.not3.4, label %.thread21, label %25

25:                                               ; preds = %.thread19
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre8 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %26 = icmp eq i32 %.pre8, 0
  br i1 %26, label %.thread21, label %27

27:                                               ; preds = %25
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread21

.thread21:                                        ; preds = %.thread19, %27, %25
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.5 = icmp eq i32 %29, 0
  br i1 %.not3.5, label %.thread23, label %30

30:                                               ; preds = %.thread21
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre9 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %31 = icmp eq i32 %.pre9, 0
  br i1 %31, label %.thread23, label %32

32:                                               ; preds = %30
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread23

.thread23:                                        ; preds = %.thread21, %32, %30
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %34 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.6 = icmp eq i32 %34, 0
  br i1 %.not3.6, label %.thread25, label %35

35:                                               ; preds = %.thread23
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre10 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %36 = icmp eq i32 %.pre10, 0
  br i1 %36, label %.thread25, label %37

37:                                               ; preds = %35
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread25

.thread25:                                        ; preds = %.thread23, %37, %35
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %39 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.7 = icmp eq i32 %39, 0
  br i1 %.not3.7, label %.thread27, label %40

40:                                               ; preds = %.thread25
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre11 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %41 = icmp eq i32 %.pre11, 0
  br i1 %41, label %.thread27, label %42

42:                                               ; preds = %40
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread27

.thread27:                                        ; preds = %.thread25, %42, %40
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %44 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.8 = icmp eq i32 %44, 0
  br i1 %.not3.8, label %.thread29, label %45

45:                                               ; preds = %.thread27
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre12 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %46 = icmp eq i32 %.pre12, 0
  br i1 %46, label %.thread29, label %47

47:                                               ; preds = %45
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread29

.thread29:                                        ; preds = %.thread27, %47, %45
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %49 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.9 = icmp eq i32 %49, 0
  br i1 %.not3.9, label %.thread31, label %50

50:                                               ; preds = %.thread29
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  %.pre13 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %51 = icmp eq i32 %.pre13, 0
  br i1 %51, label %.thread31, label %52

52:                                               ; preds = %50
  tail call void @spin_lock(ptr noundef nonnull @pr) #3
  br label %.thread31

.thread31:                                        ; preds = %.thread29, %52, %50
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0)
  %54 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not3.10 = icmp eq i32 %54, 0
  br i1 %.not3.10, label %56, label %55

55:                                               ; preds = %.thread31
  tail call void @spin_unlock(ptr noundef nonnull @pr) #3
  br label %56

56:                                               ; preds = %55, %.thread31
  ret i32 0
}

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 = { 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 #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, !12, i64 40}
!6 = !{!"lock_t", !7, i64 0, !12, i64 40}
!7 = !{!"spinlock", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !8, i64 32}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"int", !9, i64 0}


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