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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @iwjsreg_remove(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store i64 0, ptr %6, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %20

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.iwjsreg, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %12, %2
  store i64 70017, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %116

21:                                               ; preds = %17
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.iwjsreg, ptr %22, i32 0, i32 8
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.iwjsreg, ptr %25, i32 0, i32 10
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = call i64 %24(ptr noundef %27)
  %29 = icmp ne i64 %28, 0
  %30 = xor i1 %29, true
  %31 = xor i1 %30, true
  %32 = zext i1 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = call i64 @llvm.expect.i64(i64 %33, i64 0)
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %44

36:                                               ; preds = %21
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.iwjsreg, ptr %37, i32 0, i32 8
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.iwjsreg, ptr %40, i32 0, i32 10
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = call i64 %39(ptr noundef %42)
  store i64 %43, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %116

44:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.iwjsreg, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.jbl_node, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  store ptr %49, ptr %8, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %91, %44
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  store i32 2, ptr %7, align 4
  br label %95

54:                                               ; preds = %50
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.jbl_node, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %90

59:                                               ; preds = %54
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.jbl_node, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.jbl_node, ptr %64, i32 0, i32 4
  %66 = load i32, ptr %65, align 8, !tbaa !21
  %67 = sext i32 %66 to i64
  %68 = call i32 @strncmp(ptr noundef %62, ptr noundef %63, i64 noundef %67) #7
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %90

70:                                               ; preds = %59
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.iwjsreg, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !11
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  call void @jbn_remove_item(ptr noundef %73, ptr noundef %74)
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.jbl_node, ptr %75, i32 0, i32 8
  %77 = load i32, ptr %76, align 4, !tbaa !22
  %78 = icmp eq i32 %77, 5
  br i1 %78, label %79, label %83

79:                                               ; preds = %70
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.jbl_node, ptr %80, i32 0, i32 9
  %82 = load ptr, ptr %81, align 8, !tbaa !23
  call void @free(ptr noundef %82) #6
  br label %83

83:                                               ; preds = %79, %70
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.jbl_node, ptr %84, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !20
  call void @free(ptr noundef %86) #6
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %87) #6
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.iwjsreg, ptr %88, i32 0, i32 12
  store i8 1, ptr %89, align 4, !tbaa !24
  store i32 2, ptr %7, align 4
  br label %95

90:                                               ; preds = %59, %54
  br label %91

91:                                               ; preds = %90
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.jbl_node, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !25
  store ptr %94, ptr %8, align 8, !tbaa !5
  br label %50, !llvm.loop !26

95:                                               ; preds = %83, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %96

96:                                               ; preds = %95
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.iwjsreg, ptr %97, i32 0, i32 9
  %99 = load ptr, ptr %98, align 8, !tbaa !28
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.iwjsreg, ptr %100, i32 0, i32 10
  %102 = load ptr, ptr %101, align 8, !tbaa !17
  %103 = call i64 %99(ptr noundef %102)
  store i64 %103, ptr %9, align 8, !tbaa !9
  %104 = load i64, ptr %9, align 8, !tbaa !9
  %105 = icmp ne i64 %104, 0
  br i1 %105, label %106, label %114

106:                                              ; preds = %96
  %107 = load i64, ptr %6, align 8, !tbaa !9
  %108 = icmp ne i64 %107, 0
  br i1 %108, label %111, label %109

109:                                              ; preds = %106
  %110 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %110, ptr %6, align 8, !tbaa !9
  br label %113

111:                                              ; preds = %106
  %112 = load i64, ptr %9, align 8, !tbaa !9
  call void @iwlog3(i32 noundef 0, i64 noundef %112, ptr noundef @.str.3, i32 noundef 257, ptr noundef @.str.4)
  br label %113

113:                                              ; preds = %111, %109
  br label %114

114:                                              ; preds = %113, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  %115 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %115, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %116

116:                                              ; preds = %114, %36, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %117 = load i64, ptr %3, align 8
  ret i64 %117
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #4

declare void @jbn_remove_item(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 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 #4 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 8}
!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 128}
!17 = !{!12, !6, i64 144}
!18 = !{!19, !6, i64 40}
!19 = !{!"jbl_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !14, i64 36, !6, i64 40, !14, i64 48, !14, i64 52, !7, i64 56}
!20 = !{!19, !6, i64 24}
!21 = !{!19, !14, i64 32}
!22 = !{!19, !14, i64 52}
!23 = !{!7, !7, i64 0}
!24 = !{!12, !15, i64 156}
!25 = !{!19, !6, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!12, !6, i64 136}


; 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 i64 @iwjsreg_remove(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %41, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  %7 = icmp ne ptr %1, null
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %8, label %41

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 128
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 144
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = tail call i64 %10(ptr noundef %12) #4
  %.not35 = icmp eq i64 %13, 0
  br i1 %.not35, label %14, label %.sink.split, !prof !15

14:                                               ; preds = %8
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 40
  %.02940 = load ptr, ptr %16, align 8, !tbaa !16
  %.not3641 = icmp eq ptr %.02940, null
  br i1 %.not3641, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %14, %36
  %.02942 = phi ptr [ %.029, %36 ], [ %.02940, %14 ]
  %17 = getelementptr inbounds i8, ptr %.02942, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %.not37 = icmp eq ptr %18, null
  br i1 %.not37, label %36, label %19

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds i8, ptr %.02942, i64 32
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %22 = sext i32 %21 to i64
  %23 = tail call i32 @strncmp(ptr noundef nonnull %18, ptr noundef nonnull %1, i64 noundef %22) #5
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %36

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %.02942, i64 24
  tail call void @jbn_remove_item(ptr noundef %15, ptr noundef nonnull %.02942) #4
  %27 = getelementptr inbounds i8, ptr %.02942, i64 52
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = icmp eq i32 %28, 5
  br i1 %29, label %30, label %33

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %.02942, i64 56
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  tail call void @free(ptr noundef %32) #4
  br label %33

33:                                               ; preds = %30, %25
  %34 = load ptr, ptr %26, align 8, !tbaa !17
  tail call void @free(ptr noundef %34) #4
  tail call void @free(ptr noundef nonnull %.02942) #4
  %35 = getelementptr inbounds i8, ptr %0, i64 156
  store i8 1, ptr %35, align 4, !tbaa !22
  br label %.loopexit

36:                                               ; preds = %.lr.ph, %19
  %.029 = load ptr, ptr %.02942, align 8, !tbaa !16
  %.not36 = icmp eq ptr %.029, null
  br i1 %.not36, label %.loopexit, label %.lr.ph, !llvm.loop !23

.loopexit:                                        ; preds = %36, %14, %33
  %37 = getelementptr inbounds i8, ptr %0, i64 136
  br label %.sink.split

.sink.split:                                      ; preds = %8, %.loopexit
  %.sink = phi ptr [ %37, %.loopexit ], [ %9, %8 ]
  %38 = load ptr, ptr %.sink, align 8, !tbaa !16
  %39 = load ptr, ptr %11, align 8, !tbaa !14
  %40 = tail call i64 %38(ptr noundef %39) #4
  br label %41

41:                                               ; preds = %.sink.split, %2, %3
  %.0 = phi i64 [ 70017, %3 ], [ 70017, %2 ], [ %40, %.sink.split ]
  ret i64 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #1

declare void @jbn_remove_item(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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 nofree nounwind willreturn memory(argmem: 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"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 128}
!14 = !{!6, !7, i64 144}
!15 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 24}
!18 = !{!"jbl_node", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !11, i64 36, !7, i64 40, !11, i64 48, !11, i64 52, !8, i64 56}
!19 = !{!18, !11, i64 32}
!20 = !{!18, !11, i64 52}
!21 = !{!8, !8, i64 0}
!22 = !{!6, !12, i64 156}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass