; 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.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @test_func3(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 4
  br i1 %12, label %13, label %36

13:                                               ; preds = %2
  br label %14

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

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

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

22:                                               ; preds = %18
  call void @spin_unlock(ptr noundef @pr)
  br label %23

23:                                               ; preds = %22, %18
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  call void @spin_lock(ptr noundef @pr)
  br label %29

29:                                               ; preds = %28, %25
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %31 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  call void @spin_unlock(ptr noundef @pr)
  br label %34

34:                                               ; preds = %33, %29
  br label %35

35:                                               ; preds = %34
  store i32 -1, ptr %3, align 4
  br label %107

36:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds ptr, ptr %37, i64 1
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = call i32 @atoi(ptr noundef %39)
  store i32 %40, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds ptr, ptr %41, i64 2
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = call i32 @atoi(ptr noundef %43)
  store i32 %44, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = getelementptr inbounds ptr, ptr %45, i64 3
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %47, i64 0
  %49 = load i8, ptr %48, align 1, !tbaa !15
  store i8 %49, ptr %8, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %50 = load i8, ptr %8, align 1, !tbaa !15
  %51 = sext i8 %50 to i32
  switch i32 %51, label %64 [
    i32 43, label %52
    i32 42, label %56
    i32 45, label %60
  ]

52:                                               ; preds = %36
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = add nsw i32 %53, %54
  store i32 %55, ptr %9, align 4, !tbaa !5
  br label %92

56:                                               ; preds = %36
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = mul nsw i32 %57, %58
  store i32 %59, ptr %9, align 4, !tbaa !5
  br label %92

60:                                               ; preds = %36
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sub nsw i32 %61, %62
  store i32 %63, ptr %9, align 4, !tbaa !5
  br label %92

64:                                               ; preds = %36
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %65
  call void @spin_lock(ptr noundef @pr)
  br label %69

69:                                               ; preds = %68, %65
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = getelementptr inbounds ptr, ptr %70, i64 3
  %72 = load ptr, ptr %71, align 8, !tbaa !9
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %72)
  %74 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %69
  call void @spin_unlock(ptr noundef @pr)
  br label %77

77:                                               ; preds = %76, %69
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  call void @spin_lock(ptr noundef @pr)
  br label %84

84:                                               ; preds = %83, %80
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %86 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %84
  call void @spin_unlock(ptr noundef @pr)
  br label %89

89:                                               ; preds = %88, %84
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %106

92:                                               ; preds = %60, %56, %52
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %93
  call void @spin_lock(ptr noundef @pr)
  br label %97

97:                                               ; preds = %96, %93
  %98 = load i32, ptr %9, align 4, !tbaa !5
  %99 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %98)
  %100 = load i32, ptr getelementptr inbounds (%struct.lock_t, ptr @pr, i32 0, i32 1), align 8, !tbaa !11
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %103

102:                                              ; preds = %97
  call void @spin_unlock(ptr noundef @pr)
  br label %103

103:                                              ; preds = %102, %97
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %106

106:                                              ; preds = %105, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %107

107:                                              ; preds = %106, %35
  %108 = load i32, ptr %3, align 4
  ret i32 %108
}

declare i32 @atoi(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!7, !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"

%struct.lock_t = type { %struct.spinlock, i32 }
%struct.spinlock = type { i64, i64, i64, ptr, i64 }

@pr = external global %struct.lock_t, align 8
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 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 range(i32 -1, 1) i32 @test_func3(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %.not = icmp eq i32 %0, 4
  br i1 %.not, label %13, label %3

3:                                                ; preds = %2
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not20 = icmp eq i32 %4, 0
  br i1 %.not20, label %6, label %5

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

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

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

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

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

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = tail call i32 @atoi(ptr nocapture noundef %15)
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = tail call i32 @atoi(ptr nocapture noundef %18)
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load i8, ptr %21, align 1, !tbaa !14
  switch i8 %22, label %29 [
    i8 43, label %23
    i8 42, label %25
    i8 45, label %27
  ]

23:                                               ; preds = %13
  %24 = add nsw i32 %19, %16
  br label %40

25:                                               ; preds = %13
  %26 = mul nsw i32 %19, %16
  br label %40

27:                                               ; preds = %13
  %28 = sub nsw i32 %16, %19
  br label %40

29:                                               ; preds = %13
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not16 = icmp eq i32 %30, 0
  br i1 %.not16, label %32, label %31

31:                                               ; preds = %29
  tail call void @spin_lock(ptr noundef nonnull @pr) #4
  %.pre = load ptr, ptr %20, align 8, !tbaa !13
  br label %32

32:                                               ; preds = %31, %29
  %33 = phi ptr [ %.pre, %31 ], [ %21, %29 ]
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef %33)
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not17 = icmp eq i32 %35, 0
  br i1 %.not17, label %.thread26, label %36

36:                                               ; preds = %32
  tail call void @spin_unlock(ptr noundef nonnull @pr) #4
  %.pr25 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not18 = icmp eq i32 %.pr25, 0
  br i1 %.not18, label %.thread26, label %37

37:                                               ; preds = %36
  tail call void @spin_lock(ptr noundef nonnull @pr) #4
  br label %.thread26

.thread26:                                        ; preds = %32, %37, %36
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %39 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not19 = icmp eq i32 %39, 0
  br i1 %.not19, label %46, label %.sink.split

40:                                               ; preds = %23, %25, %27
  %.0 = phi i32 [ %28, %27 ], [ %26, %25 ], [ %24, %23 ]
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 40), align 8, !tbaa !5
  %.not14 = icmp eq i32 %41, 0
  br i1 %.not14, label %43, label %42

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

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

.sink.split:                                      ; preds = %43, %.thread26, %.thread
  %.1.ph = phi i32 [ -1, %.thread ], [ -1, %.thread26 ], [ 0, %43 ]
  tail call void @spin_unlock(ptr noundef nonnull @pr) #4
  br label %46

46:                                               ; preds = %.sink.split, %.thread26, %43, %.thread
  %.1 = phi i32 [ -1, %.thread ], [ -1, %.thread26 ], [ 0, %43 ], [ %.1.ph, %.sink.split ]
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @atoi(ptr nocapture noundef) local_unnamed_addr #3

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 = { mustprogress nofree nounwind willreturn memory(read) "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, !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}
!13 = !{!11, !11, i64 0}
!14 = !{!9, !9, i64 0}


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