; LLVM IR from parallella/pal :: src/base (p_run)

; 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.team = type { ptr, ptr, i32, i32, i32, %union.p_coords, %union.p_coords, %union.p_coords }
%union.p_coords = type { %struct.anon }
%struct.anon = type { i32, i32, i32 }
%struct.dev = type { ptr, i32, %union.p_coords, %union.p_coords }
%struct.dev_ops = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @p_run(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6, i32 noundef %7) #0 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !5
  store i32 %7, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 0, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %23, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %24, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %25 = load ptr, ptr %19, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.team, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.dev, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  store ptr %29, ptr %21, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = call zeroext i1 @p_ref_is_err(ptr noundef %30)
  br i1 %31, label %35, label %32

32:                                               ; preds = %8
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = call zeroext i1 @p_ref_is_err(ptr noundef %33)
  br i1 %34, label %35, label %36

35:                                               ; preds = %32, %8
  store i32 -22, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %87

36:                                               ; preds = %32
  %37 = load i32, ptr %17, align 4, !tbaa !9
  %38 = and i32 %37, 2
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %61, label %40

40:                                               ; preds = %36
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = icmp sgt i32 %41, 16
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 -7, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %87

44:                                               ; preds = %40
  %45 = load ptr, ptr %21, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.dev_ops, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = load ptr, ptr %19, align 8, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %14, align 4, !tbaa !9
  %51 = load ptr, ptr %20, align 8, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = load i32, ptr %15, align 4, !tbaa !9
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  %55 = call i32 %47(ptr noundef %48, i32 noundef %49, i32 noundef %50, ptr noundef %51, ptr noundef %52, i32 noundef %53, ptr noundef %54)
  store i32 %55, ptr %18, align 4, !tbaa !9
  %56 = load i32, ptr %18, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %60

58:                                               ; preds = %44
  %59 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %59, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %87

60:                                               ; preds = %44
  br label %61

61:                                               ; preds = %60, %36
  %62 = load i32, ptr %17, align 4, !tbaa !9
  %63 = and i32 %62, 1
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %61
  store i32 0, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %87

66:                                               ; preds = %61
  %67 = load ptr, ptr %21, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.dev_ops, ptr %67, i32 0, i32 6
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = load ptr, ptr %19, align 8, !tbaa !5
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = call i32 %69(ptr noundef %70, i32 noundef %71, i32 noundef %72)
  store i32 %73, ptr %18, align 4, !tbaa !9
  %74 = load i32, ptr %18, align 4, !tbaa !9
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %66
  %77 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %77, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %87

78:                                               ; preds = %66
  %79 = load i32, ptr %17, align 4, !tbaa !9
  %80 = and i32 %79, 2048
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %85, label %82

82:                                               ; preds = %78
  %83 = load ptr, ptr %19, align 8, !tbaa !5
  %84 = call i32 @p_wait(ptr noundef %83)
  store i32 %84, ptr %18, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %82, %78
  %86 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %86, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %87

87:                                               ; preds = %85, %76, %65, %58, %43, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  %88 = load i32, ptr %9, align 4
  ret i32 %88
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @p_ref_is_err(ptr noundef) #2

declare i32 @p_wait(ptr noundef) #3

; 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 = { inlinehint 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 = { "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 = !{!"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, !6, i64 8}
!12 = !{!"team", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 28, !7, i64 40, !7, i64 52}
!13 = !{!14, !6, i64 0}
!14 = !{!"dev", !6, i64 0, !10, i64 8, !7, i64 12, !7, i64 24}
!15 = !{!16, !6, i64 40}
!16 = !{!"dev_ops", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144}
!17 = !{!16, !6, i64 48}


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

; Function Attrs: nounwind uwtable
define dso_local i32 @p_run(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = tail call zeroext i1 @p_ref_is_err(ptr noundef %0)
  br i1 %12, label %33, label %13

13:                                               ; preds = %8
  %14 = tail call zeroext i1 @p_ref_is_err(ptr noundef nonnull %2)
  br i1 %14, label %33, label %15

15:                                               ; preds = %13
  %16 = and i32 %7, 2
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %17, label %23

17:                                               ; preds = %15
  %18 = icmp sgt i32 %5, 16
  br i1 %18, label %33, label %19

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %11, i64 40
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = tail call i32 %21(ptr noundef nonnull %2, i32 noundef %3, i32 noundef %4, ptr noundef %0, ptr noundef %1, i32 noundef %5, ptr noundef %6) #3
  %.not31 = icmp eq i32 %22, 0
  br i1 %.not31, label %23, label %33

23:                                               ; preds = %19, %15
  %24 = and i32 %7, 1
  %.not32 = icmp eq i32 %24, 0
  br i1 %.not32, label %25, label %33

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %11, i64 48
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = tail call i32 %27(ptr noundef nonnull %2, i32 noundef %3, i32 noundef %4) #3
  %.not33 = icmp eq i32 %28, 0
  br i1 %.not33, label %29, label %33

29:                                               ; preds = %25
  %30 = and i32 %7, 2048
  %.not34 = icmp eq i32 %30, 0
  br i1 %.not34, label %31, label %33

31:                                               ; preds = %29
  %32 = tail call i32 @p_wait(ptr noundef nonnull %2) #3
  br label %33

33:                                               ; preds = %29, %31, %25, %23, %19, %17, %8, %13
  %.0 = phi i32 [ -22, %13 ], [ -22, %8 ], [ -7, %17 ], [ %22, %19 ], [ 0, %23 ], [ %28, %25 ], [ 0, %29 ], [ %32, %31 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @p_ref_is_err(ptr noundef) local_unnamed_addr #1

declare i32 @p_wait(ptr noundef) local_unnamed_addr #2

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 = { inlinehint 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 = { "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, !7, i64 8}
!6 = !{!"team", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !8, i64 28, !8, i64 40, !8, i64 52}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"dev", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 24}
!13 = !{!14, !7, i64 40}
!14 = !{!"dev_ops", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144}
!15 = !{!14, !7, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass