; LLVM IR from kala13x/libxutils :: tools (xjson)

; 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.xjson_args_ = type { [2048 x i8], i16, i8, i8 }

@.str.15 = external hidden unnamed_addr constant [13 x i8], align 1
@optarg = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @XJSON_ParseArgs(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.xjson_args_, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  call void @xstrnul(ptr noundef %12)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.xjson_args_, ptr %13, i32 0, i32 1
  store i16 4, ptr %14, align 2, !tbaa !11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.xjson_args_, ptr %15, i32 0, i32 2
  store i8 0, ptr %16, align 2, !tbaa !14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.xjson_args_, ptr %17, i32 0, i32 3
  store i8 0, ptr %18, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %46, %3
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call i32 @getopt(i32 noundef %20, ptr noundef %21, ptr noundef @.str.15) #5
  store i32 %22, ptr %8, align 4, !tbaa !9
  %23 = icmp ne i32 %22, -1
  br i1 %23, label %24, label %47

24:                                               ; preds = %19
  %25 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %25, label %45 [
    i32 105, label %26
    i32 108, label %32
    i32 109, label %38
    i32 112, label %41
    i32 104, label %44
  ]

26:                                               ; preds = %24
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xjson_args_, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [2048 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr @optarg, align 8, !tbaa !5
  %31 = call i64 @xstrncpy(ptr noundef %29, i64 noundef 2048, ptr noundef %30)
  br label %46

32:                                               ; preds = %24
  %33 = load ptr, ptr @optarg, align 8, !tbaa !5
  %34 = call i32 @atoi(ptr noundef %33) #6
  %35 = trunc i32 %34 to i16
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.xjson_args_, ptr %36, i32 0, i32 1
  store i16 %35, ptr %37, align 2, !tbaa !11
  br label %46

38:                                               ; preds = %24
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.xjson_args_, ptr %39, i32 0, i32 2
  store i8 1, ptr %40, align 2, !tbaa !14
  br label %46

41:                                               ; preds = %24
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.xjson_args_, ptr %42, i32 0, i32 3
  store i8 1, ptr %43, align 1, !tbaa !15
  br label %46

44:                                               ; preds = %24
  br label %45

45:                                               ; preds = %44, %24
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %48

46:                                               ; preds = %41, %38, %32, %26
  br label %19, !llvm.loop !16

47:                                               ; preds = %19
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %48

48:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %49 = load i32, ptr %4, align 4
  ret i32 %49
}

declare void @xstrnul(ptr noundef) #1

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

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #3

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #4

; 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 = { "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 willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint nounwind willreturn memory(read) 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 2048}
!12 = !{!"xjson_args_", !7, i64 0, !13, i64 2048, !7, i64 2050, !7, i64 2051}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 2050}
!15 = !{!12, !7, i64 2051}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.15 = external hidden unnamed_addr constant [13 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @XJSON_ParseArgs(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void @xstrnul(ptr noundef %0) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 2048
  store i16 4, ptr %4, align 2, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 2050
  store i8 0, ptr %5, align 2, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %0, i64 2051
  store i8 0, ptr %6, align 1, !tbaa !11
  br label %7

7:                                                ; preds = %.backedge, %3
  %8 = tail call i32 @getopt(i32 noundef %1, ptr noundef %2, ptr noundef nonnull @.str.15) #4
  switch i32 %8, label %.loopexit.loopexit [
    i32 -1, label %.loopexit
    i32 105, label %9
    i32 108, label %12
    i32 109, label %16
    i32 112, label %17
  ]

9:                                                ; preds = %7
  %10 = load ptr, ptr @optarg, align 8, !tbaa !12
  %11 = tail call i64 @xstrncpy(ptr noundef %0, i64 noundef 2048, ptr noundef %10) #4
  br label %.backedge

12:                                               ; preds = %7
  %13 = load ptr, ptr @optarg, align 8, !tbaa !12
  %14 = tail call i32 @atoi(ptr nocapture noundef %13) #5
  %15 = trunc i32 %14 to i16
  store i16 %15, ptr %4, align 2, !tbaa !5
  br label %.backedge

16:                                               ; preds = %7
  store i8 1, ptr %5, align 2, !tbaa !10
  br label %.backedge

17:                                               ; preds = %7
  store i8 1, ptr %6, align 1, !tbaa !11
  br label %.backedge

.backedge:                                        ; preds = %17, %16, %12, %9
  br label %7, !llvm.loop !14

.loopexit.loopexit:                               ; preds = %7
  br label %.loopexit

.loopexit:                                        ; preds = %7, %.loopexit.loopexit
  %.0 = phi i32 [ 0, %.loopexit.loopexit ], [ 1, %7 ]
  ret i32 %.0
}

declare void @xstrnul(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) 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 = { "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 "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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 }
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, !9, i64 2048}
!6 = !{!"xjson_args_", !7, i64 0, !9, i64 2048, !7, i64 2050, !7, i64 2051}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!6, !7, i64 2050}
!11 = !{!6, !7, i64 2051}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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