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

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

; 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

11:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %82

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.binn_struct, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 9
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.binn_struct, ptr %17, i32 0, i32 7
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = sub nsw i32 %19, 9
  %21 = add nsw i32 %20, 3
  store i32 %21, ptr %7, align 4, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.binn_struct, ptr %22, i32 0, i32 11
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = icmp sgt i32 %24, 127
  br i1 %25, label %26, label %38

26:                                               ; preds = %12
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 -4
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !13
  %30 = add nsw i32 %29, 3
  store i32 %30, ptr %7, align 4, !tbaa !13
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.binn_struct, ptr %31, i32 0, i32 11
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = or i32 %33, -2147483648
  store i32 %34, ptr %6, align 4, !tbaa !13
  %35 = load i32, ptr %6, align 4, !tbaa !13
  %36 = call i32 @llvm.bswap.i32(i32 %35)
  store i32 %36, ptr %6, align 4, !tbaa !13
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %37, ptr align 4 %6, i64 4, i1 false)
  br label %46

38:                                               ; preds = %12
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i32 -1
  store ptr %40, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.binn_struct, ptr %41, i32 0, i32 11
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %44, ptr %45, align 1, !tbaa !15
  br label %46

46:                                               ; preds = %38, %26
  %47 = load i32, ptr %7, align 4, !tbaa !13
  %48 = icmp sgt i32 %47, 127
  br i1 %48, label %49, label %59

49:                                               ; preds = %46
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 -4
  store ptr %51, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !13
  %53 = add nsw i32 %52, 3
  store i32 %53, ptr %7, align 4, !tbaa !13
  %54 = load i32, ptr %7, align 4, !tbaa !13
  %55 = or i32 %54, -2147483648
  store i32 %55, ptr %6, align 4, !tbaa !13
  %56 = load i32, ptr %6, align 4, !tbaa !13
  %57 = call i32 @llvm.bswap.i32(i32 %56)
  store i32 %57, ptr %6, align 4, !tbaa !13
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %58, ptr align 4 %6, i64 4, i1 false)
  br label %65

59:                                               ; preds = %46
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i32 -1
  store ptr %61, ptr %5, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !13
  %63 = trunc i32 %62 to i8
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %63, ptr %64, align 1, !tbaa !15
  br label %65

65:                                               ; preds = %59, %49
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i32 -1
  store ptr %67, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.binn_struct, ptr %68, i32 0, i32 8
  %70 = load i32, ptr %69, align 4, !tbaa !16
  %71 = trunc i32 %70 to i8
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %71, ptr %72, align 1, !tbaa !15
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.binn_struct, ptr %74, i32 0, i32 9
  store ptr %73, ptr %75, align 8, !tbaa !17
  %76 = load i32, ptr %7, align 4, !tbaa !13
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.binn_struct, ptr %77, i32 0, i32 10
  store i32 %76, ptr %78, align 8, !tbaa !18
  %79 = load i8, ptr %4, align 1, !tbaa !15
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.binn_struct, ptr %80, i32 0, i32 3
  store i32 0, ptr %81, align 4, !tbaa !19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %82

82:                                               ; preds = %65, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  %83 = load i32, ptr %2, align 4
  ret i32 %83
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.bswap.i32(i32) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 16}
!10 = !{!"binn_struct", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !7, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 32}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 52}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !11, i64 36}
!17 = !{!10, !6, i64 40}
!18 = !{!10, !11, i64 48}
!19 = !{!10, !11, i64 12}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @binn_save_header(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %40, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 52
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = icmp sgt i32 %9, 127
  br i1 %10, label %11, label %16

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %5, i64 5
  %13 = add nsw i32 %7, -3
  %14 = or disjoint i32 %9, -2147483648
  %15 = tail call i32 @llvm.bswap.i32(i32 %14)
  store i32 %15, ptr %12, align 1
  br label %20

16:                                               ; preds = %3
  %17 = add nsw i32 %7, -6
  %18 = getelementptr inbounds i8, ptr %5, i64 8
  %19 = trunc i32 %9 to i8
  store i8 %19, ptr %18, align 1, !tbaa !13
  br label %20

20:                                               ; preds = %16, %11
  %.031 = phi ptr [ %12, %11 ], [ %18, %16 ]
  %.0 = phi i32 [ %13, %11 ], [ %17, %16 ]
  %21 = icmp sgt i32 %.0, 127
  br i1 %21, label %22, label %27

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %.031, i64 -4
  %24 = add nuw nsw i32 %.0, 3
  %25 = or disjoint i32 %24, -2147483648
  %26 = tail call i32 @llvm.bswap.i32(i32 %25)
  store i32 %26, ptr %23, align 1
  br label %30

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %.031, i64 -1
  %29 = trunc i32 %.0 to i8
  store i8 %29, ptr %28, align 1, !tbaa !13
  br label %30

30:                                               ; preds = %27, %22
  %31 = phi i64 [ -4, %22 ], [ -1, %27 ]
  %.1 = phi i32 [ %24, %22 ], [ %.0, %27 ]
  %32 = getelementptr inbounds i8, ptr %.031, i64 %31
  %33 = getelementptr inbounds i8, ptr %32, i64 -1
  %34 = getelementptr inbounds i8, ptr %0, i64 36
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = trunc i32 %35 to i8
  store i8 %36, ptr %33, align 1, !tbaa !13
  %37 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %33, ptr %37, align 8, !tbaa !15
  %38 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %.1, ptr %38, align 8, !tbaa !16
  %39 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 0, ptr %39, align 4, !tbaa !17
  br label %40

40:                                               ; preds = %1, %30
  %.033 = phi i32 [ 1, %30 ], [ 0, %1 ]
  ret i32 %.033
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.bswap.i32(i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !10, i64 16}
!6 = !{!"binn_struct", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !7, i64 48, !7, i64 52, !10, i64 56, !10, i64 64, !10, i64 72, !8, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 32}
!12 = !{!6, !7, i64 52}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !7, i64 36}
!15 = !{!6, !10, i64 40}
!16 = !{!6, !7, i64 48}
!17 = !{!6, !7, i64 12}


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