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

; 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.XLogConfig = type { i32, i32, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i8, i16, [256 x i8], [2048 x i8], [256 x i8] }
%struct.xhttp_args_ = type { i32, %struct.xcli_bar_, ptr, %struct.XTime, i8, i8, i8, i8, i8, i64, i64, i64, %struct.XByteBuffer, [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8] }
%struct.xcli_bar_ = type { %struct.xcli_size_, i64, i64, i32, i32, i8, i8, i8, i8, double, i32, i8, i8, i8, i8, i8, i8, [256 x i8], [256 x i8], [256 x i8] }
%struct.xcli_size_ = type { i64, i64 }
%struct.XTime = type { i16, i8, i8, i8, i8, i8, i8 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.XLink = type { i32, [2048 x i8], [256 x i8], [256 x i8], [32 x i8], [32 x i8], [1024 x i8], [32 x i8] }

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

; 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: nounwind uwtable
declare dso_local i32 @XHTTPApp_ParseArgs(ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.XLogConfig, align 8
  %7 = alloca %struct.xhttp_args_, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.XLink, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @XLog_Init(ptr noundef null, i16 noundef zeroext 203, i8 noundef zeroext 0)
  call void @llvm.lifetime.start.p0(i64 2600, ptr %6) #3
  call void @XLog_ConfigGet(ptr noundef %6)
  %11 = getelementptr inbounds %struct.XLogConfig, ptr %6, i32 0, i32 0
  store i32 2, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.XLogConfig, ptr %6, i32 0, i32 7
  store i8 1, ptr %12, align 1, !tbaa !14
  %13 = getelementptr inbounds %struct.XLogConfig, ptr %6, i32 0, i32 10
  store i8 1, ptr %13, align 2, !tbaa !15
  %14 = getelementptr inbounds %struct.XLogConfig, ptr %6, i32 0, i32 12
  %15 = load i16, ptr %14, align 8, !tbaa !16
  %16 = zext i16 %15 to i32
  %17 = or i32 %16, 4
  %18 = trunc i32 %17 to i16
  store i16 %18, ptr %14, align 8, !tbaa !16
  call void @XLog_ConfigSet(ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 13216, ptr %7) #3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = call i32 @XHTTPApp_ParseArgs(ptr noundef %7, i32 noundef %19, ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %27, label %23

23:                                               ; preds = %2
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %24, i64 0
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  call void @XHTTPApp_DisplayUsage(ptr noundef %26)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %44

27:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %40, %27
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %41

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 3684, ptr %10) #3
  %32 = call i32 @XHTTPApp_Prepare(ptr noundef %7, ptr noundef %10)
  store i32 %32, ptr %9, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i32 3, ptr %8, align 4
  br label %38

36:                                               ; preds = %31
  %37 = call i32 @XHTTPApp_Perform(ptr noundef %7, ptr noundef %10)
  store i32 %37, ptr %9, align 4, !tbaa !5
  store i32 0, ptr %8, align 4
  br label %38

38:                                               ; preds = %36, %35
  call void @llvm.lifetime.end.p0(i64 3684, ptr %10) #3
  %39 = load i32, ptr %8, align 4
  switch i32 %39, label %46 [
    i32 0, label %40
    i32 3, label %41
  ]

40:                                               ; preds = %38
  br label %28, !llvm.loop !17

41:                                               ; preds = %38, %28
  %42 = getelementptr inbounds %struct.xhttp_args_, ptr %7, i32 0, i32 12
  call void @XByteBuffer_Clear(ptr noundef %42)
  call void @XSock_DeinitSSL()
  %43 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %43, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %44

44:                                               ; preds = %41, %23
  call void @llvm.lifetime.end.p0(i64 13216, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2600, ptr %6) #3
  %45 = load i32, ptr %3, align 4
  ret i32 %45

46:                                               ; preds = %38
  unreachable
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #2

declare void @XLog_ConfigGet(ptr noundef) #2

declare void @XLog_ConfigSet(ptr noundef) #2

declare void @XByteBuffer_Clear(ptr noundef) #2

declare void @XSock_DeinitSSL() #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 nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"XLogConfig", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !13, i64 32, !7, i64 34, !7, i64 290, !7, i64 2338}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 27}
!15 = !{!12, !7, i64 30}
!16 = !{!12, !13, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.XLogConfig = type { i32, i32, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i8, i16, [256 x i8], [2048 x i8], [256 x i8] }
%struct.xhttp_args_ = type { i32, %struct.xcli_bar_, ptr, %struct.XTime, i8, i8, i8, i8, i8, i64, i64, i64, %struct.XByteBuffer, [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8] }
%struct.xcli_bar_ = type { %struct.xcli_size_, i64, i64, i32, i32, i8, i8, i8, i8, double, i32, i8, i8, i8, i8, i8, i8, [256 x i8], [256 x i8], [256 x i8] }
%struct.xcli_size_ = type { i64, i64 }
%struct.XTime = type { i16, i8, i8, i8, i8, i8, i8 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.XLink = type { i32, [2048 x i8], [256 x i8], [256 x i8], [32 x i8], [32 x i8], [1024 x i8], [32 x i8] }

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.XLogConfig, align 8
  %4 = alloca %struct.xhttp_args_, align 8
  %5 = alloca %struct.XLink, align 4
  tail call void @XLog_Init(ptr noundef null, i16 noundef zeroext 203, i8 noundef zeroext 0) #3
  call void @llvm.lifetime.start.p0(i64 2600, ptr nonnull %3) #3
  call void @XLog_ConfigGet(ptr noundef nonnull %3) #3
  store i32 2, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 27
  store i8 1, ptr %6, align 1, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %3, i64 30
  store i8 1, ptr %7, align 2, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %3, i64 32
  %9 = load i16, ptr %8, align 8, !tbaa !14
  %10 = or i16 %9, 4
  store i16 %10, ptr %8, align 8, !tbaa !14
  call void @XLog_ConfigSet(ptr noundef nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 13216, ptr nonnull %4) #3
  %11 = call i32 @XHTTPApp_ParseArgs(ptr noundef nonnull %4, i32 noundef %0, ptr noundef %1)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %.preheader

12:                                               ; preds = %2
  %13 = load ptr, ptr %1, align 8, !tbaa !15
  call void @XHTTPApp_DisplayUsage(ptr noundef %13)
  br label %20

.preheader:                                       ; preds = %2, %16
  call void @llvm.lifetime.start.p0(i64 3684, ptr nonnull %5) #3
  %14 = call i32 @XHTTPApp_Prepare(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %.thread, label %16

.thread:                                          ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 3684, ptr nonnull %5) #3
  br label %.loopexit

16:                                               ; preds = %.preheader
  %17 = call i32 @XHTTPApp_Perform(ptr noundef nonnull %4, ptr noundef nonnull %5)
  call void @llvm.lifetime.end.p0(i64 3684, ptr nonnull %5) #3
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %.preheader, label %.loopexit

.loopexit:                                        ; preds = %16, %.thread
  %.2 = phi i32 [ %14, %.thread ], [ %17, %16 ]
  %19 = getelementptr inbounds i8, ptr %4, i64 896
  call void @XByteBuffer_Clear(ptr noundef nonnull %19) #3
  call void @XSock_DeinitSSL() #3
  br label %20

20:                                               ; preds = %.loopexit, %12
  %.08 = phi i32 [ %.2, %.loopexit ], [ -1, %12 ]
  call void @llvm.lifetime.end.p0(i64 13216, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 2600, ptr nonnull %3) #3
  ret i32 %.08
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

declare void @XLog_ConfigGet(ptr noundef) local_unnamed_addr #2

declare void @XLog_ConfigSet(ptr noundef) local_unnamed_addr #2

declare void @XByteBuffer_Clear(ptr noundef) local_unnamed_addr #2

declare void @XSock_DeinitSSL() local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 0}
!6 = !{!"XLogConfig", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27, !8, i64 28, !8, i64 29, !8, i64 30, !8, i64 31, !11, i64 32, !8, i64 34, !8, i64 290, !8, i64 2338}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !8, i64 27}
!13 = !{!6, !8, i64 30}
!14 = !{!6, !11, i64 32}
!15 = !{!10, !10, i64 0}


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