; LLVM IR from caryll/otfcc :: dep/extern (json-builder)

; 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.json_serialize_opts = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @get_serialize_flags(i64 %0, i32 %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca %struct.json_serialize_opts, align 4
  %5 = alloca { i64, i32 }, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %0, ptr %8, align 4
  %9 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %1, ptr %9, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %5, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %10 = getelementptr inbounds %struct.json_serialize_opts, ptr %4, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 2
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %54

14:                                               ; preds = %2
  %15 = getelementptr inbounds %struct.json_serialize_opts, ptr %4, i32 0, i32 0
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %27

18:                                               ; preds = %14
  %19 = getelementptr inbounds %struct.json_serialize_opts, ptr %4, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = and i32 %20, 32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = or i32 %24, 8
  store i32 %25, ptr %6, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %23, %18
  br label %44

27:                                               ; preds = %14
  %28 = getelementptr inbounds %struct.json_serialize_opts, ptr %4, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = and i32 %29, 4
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %35, label %32

32:                                               ; preds = %27
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = or i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %32, %27
  %36 = getelementptr inbounds %struct.json_serialize_opts, ptr %4, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = and i32 %37, 8
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %43, label %40

40:                                               ; preds = %35
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = or i32 %41, 2
  store i32 %42, ptr %6, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %40, %35
  br label %44

44:                                               ; preds = %43, %26
  %45 = getelementptr inbounds %struct.json_serialize_opts, ptr %4, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = and i32 %46, 16
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %52, label %49

49:                                               ; preds = %44
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = or i32 %50, 4
  store i32 %51, ptr %6, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %49, %44
  %53 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %53, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %54

54:                                               ; preds = %52, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

; 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) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"json_serialize_opts", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}


; 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(none) uwtable
define dso_local range(i32 0, 16) i32 @get_serialize_flags(i64 %0, i32 %1) local_unnamed_addr #0 {
  %.sroa.05.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.3.0.extract.shift = lshr i64 %0, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  switch i32 %.sroa.05.0.extract.trunc, label %5 [
    i32 2, label %11
    i32 0, label %3
  ]

3:                                                ; preds = %2
  %4 = lshr i32 %.sroa.3.0.extract.trunc, 2
  %spec.select = and i32 %4, 8
  br label %8

5:                                                ; preds = %2
  %6 = lshr i32 %.sroa.3.0.extract.trunc, 2
  %7 = and i32 %6, 3
  %spec.select17 = xor i32 %7, 3
  br label %8

8:                                                ; preds = %5, %3
  %.pre-phi = phi i32 [ %6, %5 ], [ %4, %3 ]
  %.1 = phi i32 [ %spec.select17, %5 ], [ %spec.select, %3 ]
  %9 = and i32 %.pre-phi, 4
  %10 = xor i32 %9, 4
  %spec.select16 = or i32 %.1, %10
  br label %11

11:                                               ; preds = %2, %8
  %.011 = phi i32 [ %spec.select16, %8 ], [ 0, %2 ]
  ret i32 %.011
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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" }

!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,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass