; LLVM IR from facebook/hermes :: API/hermes_sandbox/external (hermes_sandbox_impl_compiled_0)

; 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.w2c_hermes = type { ptr, ptr, ptr, i32, i32, i32, %struct.wasm_rt_memory_t, %struct.wasm_rt_funcref_table_t }
%struct.wasm_rt_memory_t = type { ptr, i64, i64, i64, i8 }
%struct.wasm_rt_funcref_table_t = type { ptr, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @w2c_hermes_dlfree(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @w2c_hermes_0x5F_errno_location_0(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @w2c_hermes_dlmalloc(ptr noundef, i32 noundef) #0

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

22:                                               ; preds = %3
  %23 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %23, ptr %9, align 4, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = call i32 @w2c_hermes_dlmalloc(ptr noundef %24, i32 noundef %25)
  store i32 %26, ptr %9, align 4, !tbaa !9
  br label %149

27:                                               ; preds = %3
  %28 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %28, ptr %9, align 4, !tbaa !9
  store i32 -64, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp uge i32 %29, %30
  %32 = zext i1 %31 to i32
  store i32 %32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %43

35:                                               ; preds = %27
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = call i32 @w2c_hermes_0x5F_errno_location_0(ptr noundef %36)
  store i32 %37, ptr %9, align 4, !tbaa !9
  store i32 48, ptr %10, align 4, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.w2c_hermes, ptr %38, i32 0, i32 6
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = load i32, ptr %10, align 4, !tbaa !9
  call void @i32_store(ptr noundef %39, i64 noundef %41, i32 noundef %42)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %149

43:                                               ; preds = %27
  %44 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %44, ptr %9, align 4, !tbaa !9
  store i32 8, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = sub i32 %46, %45
  store i32 %47, ptr %9, align 4, !tbaa !9
  store i32 16, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %48, ptr %11, align 4, !tbaa !9
  store i32 11, ptr %12, align 4, !tbaa !9
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = add i32 %50, %49
  store i32 %51, ptr %11, align 4, !tbaa !9
  store i32 -8, ptr %12, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = and i32 %53, %52
  store i32 %54, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %55, ptr %12, align 4, !tbaa !9
  store i32 11, ptr %13, align 4, !tbaa !9
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = icmp ult i32 %56, %57
  %59 = zext i1 %58 to i32
  store i32 %59, ptr %12, align 4, !tbaa !9
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %43
  %63 = load i32, ptr %10, align 4, !tbaa !9
  br label %66

64:                                               ; preds = %43
  %65 = load i32, ptr %11, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %64, %62
  %67 = phi i32 [ %63, %62 ], [ %65, %64 ]
  store i32 %67, ptr %10, align 4, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = call i32 @w2c_hermes_try_realloc_chunk(ptr noundef %68, i32 noundef %69, i32 noundef %70)
  store i32 %71, ptr %9, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %72, ptr %7, align 4, !tbaa !9
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %80

75:                                               ; preds = %66
  %76 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %76, ptr %9, align 4, !tbaa !9
  store i32 8, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = add i32 %78, %77
  store i32 %79, ptr %9, align 4, !tbaa !9
  br label %149

80:                                               ; preds = %66
  %81 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %81, ptr %9, align 4, !tbaa !9
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = call i32 @w2c_hermes_dlmalloc(ptr noundef %82, i32 noundef %83)
  store i32 %84, ptr %9, align 4, !tbaa !9
  %85 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %85, ptr %7, align 4, !tbaa !9
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 0
  %88 = xor i1 %87, true
  %89 = zext i1 %88 to i32
  store i32 %89, ptr %9, align 4, !tbaa !9
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %80
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %149

93:                                               ; preds = %80
  %94 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %94, ptr %9, align 4, !tbaa !9
  %95 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %95, ptr %10, align 4, !tbaa !9
  store i32 -4, ptr %11, align 4, !tbaa !9
  store i32 -8, ptr %12, align 4, !tbaa !9
  %96 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %96, ptr %13, align 4, !tbaa !9
  store i32 4, ptr %14, align 4, !tbaa !9
  %97 = load i32, ptr %14, align 4, !tbaa !9
  %98 = load i32, ptr %13, align 4, !tbaa !9
  %99 = sub i32 %98, %97
  store i32 %99, ptr %13, align 4, !tbaa !9
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.w2c_hermes, ptr %100, i32 0, i32 6
  %102 = load i32, ptr %13, align 4, !tbaa !9
  %103 = zext i32 %102 to i64
  %104 = call i32 @i32_load(ptr noundef %101, i64 noundef %103)
  store i32 %104, ptr %13, align 4, !tbaa !9
  %105 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %105, ptr %8, align 4, !tbaa !9
  store i32 3, ptr %14, align 4, !tbaa !9
  %106 = load i32, ptr %14, align 4, !tbaa !9
  %107 = load i32, ptr %13, align 4, !tbaa !9
  %108 = and i32 %107, %106
  store i32 %108, ptr %13, align 4, !tbaa !9
  %109 = load i32, ptr %13, align 4, !tbaa !9
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %113

111:                                              ; preds = %93
  %112 = load i32, ptr %11, align 4, !tbaa !9
  br label %115

113:                                              ; preds = %93
  %114 = load i32, ptr %12, align 4, !tbaa !9
  br label %115

115:                                              ; preds = %113, %111
  %116 = phi i32 [ %112, %111 ], [ %114, %113 ]
  store i32 %116, ptr %11, align 4, !tbaa !9
  %117 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %117, ptr %12, align 4, !tbaa !9
  store i32 -8, ptr %13, align 4, !tbaa !9
  %118 = load i32, ptr %13, align 4, !tbaa !9
  %119 = load i32, ptr %12, align 4, !tbaa !9
  %120 = and i32 %119, %118
  store i32 %120, ptr %12, align 4, !tbaa !9
  %121 = load i32, ptr %12, align 4, !tbaa !9
  %122 = load i32, ptr %11, align 4, !tbaa !9
  %123 = add i32 %122, %121
  store i32 %123, ptr %11, align 4, !tbaa !9
  %124 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %124, ptr %8, align 4, !tbaa !9
  %125 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %125, ptr %12, align 4, !tbaa !9
  %126 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %126, ptr %13, align 4, !tbaa !9
  %127 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %127, ptr %14, align 4, !tbaa !9
  %128 = load i32, ptr %13, align 4, !tbaa !9
  %129 = load i32, ptr %14, align 4, !tbaa !9
  %130 = icmp ugt i32 %128, %129
  %131 = zext i1 %130 to i32
  store i32 %131, ptr %13, align 4, !tbaa !9
  %132 = load i32, ptr %13, align 4, !tbaa !9
  %133 = icmp ne i32 %132, 0
  br i1 %133, label %134, label %136

134:                                              ; preds = %115
  %135 = load i32, ptr %11, align 4, !tbaa !9
  br label %138

136:                                              ; preds = %115
  %137 = load i32, ptr %12, align 4, !tbaa !9
  br label %138

138:                                              ; preds = %136, %134
  %139 = phi i32 [ %135, %134 ], [ %137, %136 ]
  store i32 %139, ptr %11, align 4, !tbaa !9
  %140 = load ptr, ptr %4, align 8, !tbaa !5
  %141 = load i32, ptr %9, align 4, !tbaa !9
  %142 = load i32, ptr %10, align 4, !tbaa !9
  %143 = load i32, ptr %11, align 4, !tbaa !9
  %144 = call i32 @w2c_hermes_0x5F_memcpy(ptr noundef %140, i32 noundef %141, i32 noundef %142, i32 noundef %143)
  store i32 %144, ptr %9, align 4, !tbaa !9
  %145 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %145, ptr %9, align 4, !tbaa !9
  %146 = load ptr, ptr %4, align 8, !tbaa !5
  %147 = load i32, ptr %9, align 4, !tbaa !9
  call void @w2c_hermes_dlfree(ptr noundef %146, i32 noundef %147)
  %148 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %148, ptr %9, align 4, !tbaa !9
  br label %149

149:                                              ; preds = %138, %92, %75, %35, %22
  %150 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %150
}

; 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: inlinehint nounwind uwtable
declare hidden void @i32_store(ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @w2c_hermes_0x5F_memcpy(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @i32_load(ptr noundef, i64 noundef) #2

declare i32 @w2c_hermes_try_realloc_chunk(ptr noundef, i32 noundef, i32 noundef) #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 = { 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}


; 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
declare dso_local void @w2c_hermes_dlfree(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @w2c_hermes_dlmalloc(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @w2c_hermes_dlrealloc(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %4, label %6

4:                                                ; preds = %3
  %5 = tail call i32 @w2c_hermes_dlmalloc(ptr noundef %0, i32 noundef %2)
  br label %34

6:                                                ; preds = %3
  %7 = icmp ugt i32 %2, -65
  br i1 %7, label %8, label %12

8:                                                ; preds = %6
  %9 = tail call i32 @w2c_hermes_0x5F_errno_location_0(ptr noundef %0)
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = zext i32 %9 to i64
  tail call void @i32_store(ptr noundef nonnull %10, i64 noundef %11, i32 noundef 48)
  br label %34

12:                                               ; preds = %6
  %13 = add i32 %1, -8
  %14 = add nuw i32 %2, 11
  %15 = and i32 %14, -8
  %16 = icmp ult i32 %2, 11
  %17 = select i1 %16, i32 16, i32 %15
  %18 = tail call i32 @w2c_hermes_try_realloc_chunk(ptr noundef %0, i32 noundef %13, i32 noundef %17) #4
  %.not79 = icmp eq i32 %18, 0
  br i1 %.not79, label %21, label %19

19:                                               ; preds = %12
  %20 = add i32 %18, 8
  br label %34

21:                                               ; preds = %12
  %22 = tail call i32 @w2c_hermes_dlmalloc(ptr noundef %0, i32 noundef %2)
  %.not80 = icmp eq i32 %22, 0
  br i1 %.not80, label %34, label %23

23:                                               ; preds = %21
  %24 = add i32 %1, -4
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = zext i32 %24 to i64
  %27 = tail call i32 @i32_load(ptr noundef nonnull %25, i64 noundef %26)
  %28 = and i32 %27, 3
  %.not81 = icmp eq i32 %28, 0
  %29 = select i1 %.not81, i32 -8, i32 -4
  %30 = and i32 %27, -8
  %31 = add i32 %29, %30
  %32 = tail call i32 @llvm.umin.i32(i32 %31, i32 %2)
  %33 = tail call i32 @w2c_hermes_0x5F_memcpy(ptr noundef %0, i32 noundef %22, i32 noundef %1, i32 noundef %32)
  tail call void @w2c_hermes_dlfree(ptr noundef %0, i32 noundef %1)
  br label %34

34:                                               ; preds = %21, %23, %19, %8, %4
  %.0 = phi i32 [ %5, %4 ], [ 0, %8 ], [ %20, %19 ], [ %22, %23 ], [ 0, %21 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @i32_store(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @w2c_hermes_0x5F_memcpy(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @i32_load(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @w2c_hermes_try_realloc_chunk(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


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