; LLVM IR from Softmotions/iowow :: src/json (iwjsreg)

; 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.iwjsreg = type { ptr, ptr, ptr, ptr, ptr, %union.pthread_rwlock_t, %struct.iwref_holder, ptr, ptr, ptr, ptr, i32, i8 }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }
%struct.iwref_holder = type { ptr, i64, ptr }

@.str.3 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @iwjsreg_sync(ptr noundef) #2

declare void @iwlog3(i32 noundef, i64 noundef, ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i64 @iwjsreg_merge(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.iwjsreg, ptr %11, i32 0, i32 8
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.iwjsreg, ptr %14, i32 0, i32 10
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = call i64 %13(ptr noundef %16)
  %18 = icmp ne i64 %17, 0
  %19 = xor i1 %18, true
  %20 = xor i1 %19, true
  %21 = zext i1 %20 to i32
  %22 = sext i32 %21 to i64
  %23 = call i64 @llvm.expect.i64(i64 %22, i64 0)
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.iwjsreg, ptr %26, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.iwjsreg, ptr %29, i32 0, i32 10
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = call i64 %28(ptr noundef %31)
  store i64 %32, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

33:                                               ; preds = %3
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.iwjsreg, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = call i64 @jbn_merge_patch_path(ptr noundef %36, ptr noundef %37, ptr noundef %38, ptr noundef null)
  store i64 %39, ptr %8, align 8, !tbaa !9
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %45, label %42

42:                                               ; preds = %33
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.iwjsreg, ptr %43, i32 0, i32 12
  store i8 1, ptr %44, align 4, !tbaa !18
  br label %45

45:                                               ; preds = %42, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.iwjsreg, ptr %46, i32 0, i32 9
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.iwjsreg, ptr %49, i32 0, i32 10
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = call i64 %48(ptr noundef %51)
  store i64 %52, ptr %10, align 8, !tbaa !9
  %53 = load i64, ptr %10, align 8, !tbaa !9
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %63

55:                                               ; preds = %45
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %60, label %58

58:                                               ; preds = %55
  %59 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %59, ptr %8, align 8, !tbaa !9
  br label %62

60:                                               ; preds = %55
  %61 = load i64, ptr %10, align 8, !tbaa !9
  call void @iwlog3(i32 noundef 0, i64 noundef %61, ptr noundef @.str.3, i32 noundef 319, ptr noundef @.str.4)
  br label %62

62:                                               ; preds = %60, %58
  br label %63

63:                                               ; preds = %62, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = icmp ne i64 %64, 0
  br i1 %65, label %75, label %66

66:                                               ; preds = %63
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.iwjsreg, ptr %67, i32 0, i32 11
  %69 = load i32, ptr %68, align 8, !tbaa !20
  %70 = and i32 %69, 2
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %75

72:                                               ; preds = %66
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = call i64 @iwjsreg_sync(ptr noundef %73)
  store i64 %74, ptr %8, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %72, %66, %63
  %76 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %76, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

77:                                               ; preds = %75, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %78 = load i64, ptr %4, align 8
  ret i64 %78
}

declare i64 @jbn_merge_patch_path(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 128}
!12 = !{!"iwjsreg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !13, i64 96, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !14, i64 152, !15, i64 156}
!13 = !{!"iwref_holder", !6, i64 0, !7, i64 8, !6, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!12, !6, i64 144}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !15, i64 156}
!19 = !{!12, !6, i64 136}
!20 = !{!12, !14, i64 152}


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

@.str.3 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @iwjsreg_sync(ptr noundef) local_unnamed_addr #0

declare void @iwlog3(i32 noundef, i64 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @iwjsreg_merge(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 144
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %8 = tail call i64 %5(ptr noundef %7) #2
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %13, label %9, !prof !14

9:                                                ; preds = %3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !13
  %12 = tail call i64 %10(ptr noundef %11) #2
  br label %31

13:                                               ; preds = %3
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = tail call i64 @jbn_merge_patch_path(ptr noundef %15, ptr noundef %1, ptr noundef %2, ptr noundef null) #2
  %.not22 = icmp eq i64 %16, 0
  br i1 %.not22, label %17, label %19

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 156
  store i8 1, ptr %18, align 4, !tbaa !16
  br label %19

19:                                               ; preds = %17, %13
  %20 = getelementptr inbounds i8, ptr %0, i64 136
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = load ptr, ptr %6, align 8, !tbaa !13
  %23 = tail call i64 %21(ptr noundef %22) #2
  %.not23 = icmp eq i64 %23, 0
  %brmerge = or i1 %.not22, %.not23
  br i1 %brmerge, label %24, label %.thread

.thread:                                          ; preds = %19
  tail call void @iwlog3(i32 noundef 0, i64 noundef %23, ptr noundef nonnull @.str.3, i32 noundef 319, ptr noundef nonnull @.str.4) #2
  br label %31

24:                                               ; preds = %19
  %.mux = select i1 %.not23, i64 %16, i64 %23
  %.not24 = icmp eq i64 %.mux, 0
  br i1 %.not24, label %25, label %31

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %0, i64 152
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = and i32 %27, 2
  %.not25 = icmp eq i32 %28, 0
  br i1 %.not25, label %31, label %29

29:                                               ; preds = %25
  %30 = tail call i64 @iwjsreg_sync(ptr noundef nonnull %0)
  br label %31

31:                                               ; preds = %.thread, %24, %25, %29, %9
  %.0 = phi i64 [ %12, %9 ], [ %.mux, %24 ], [ %30, %29 ], [ 0, %25 ], [ %16, %.thread ]
  ret i64 %.0
}

declare i64 @jbn_merge_patch_path(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 }

!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 128}
!6 = !{!"iwjsreg", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40, !10, i64 96, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !11, i64 152, !12, i64 156}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"iwref_holder", !7, i64 0, !8, i64 8, !7, i64 16}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!6, !7, i64 144}
!14 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !12, i64 156}
!17 = !{!6, !7, i64 136}
!18 = !{!6, !11, i64 152}


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