; LLVM IR from kala13x/libxutils :: src/net (api)

; 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.xapi_data_ = type { [128 x i8], [128 x i8], [2048 x i8], i16, %struct.XSocket, i32, i8, i8, i8, i8, i8, i8, %struct.XByteBuffer, %struct.XByteBuffer, ptr, i32, i32, ptr, ptr, ptr }
%struct.XSocket = type { i32, %union.xsock_addr_t, i32, i32, i16, i32, i32, i32, i32, ptr }
%union.xsock_addr_t = type { %struct.sockaddr_in, [96 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }

@.str.24 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [6 x i8], align 1

; 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
declare dso_local i32 @XAPI_RespondHTTP(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XAPI_AuthorizeHTTP(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.xapi_data_, ptr %18, i32 0, i32 19
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %17, %3
  store i32 -1, ptr %4, align 4
  br label %118

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xapi_data_, ptr %24, i32 0, i32 19
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  store ptr %26, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call zeroext i8 @xstrused(ptr noundef %27)
  %29 = zext i8 %28 to i32
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %23
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i64 @strlen(ptr noundef %32) #5
  br label %35

34:                                               ; preds = %23
  br label %35

35:                                               ; preds = %34, %31
  %36 = phi i64 [ %33, %31 ], [ 0, %34 ]
  store i64 %36, ptr %9, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call zeroext i8 @xstrused(ptr noundef %37)
  %39 = zext i8 %38 to i32
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i64 @strlen(ptr noundef %42) #5
  br label %45

44:                                               ; preds = %35
  br label %45

45:                                               ; preds = %44, %41
  %46 = phi i64 [ %43, %41 ], [ 0, %44 ]
  store i64 %46, ptr %10, align 8, !tbaa !16
  %47 = load i64, ptr %9, align 8, !tbaa !16
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %53, label %49

49:                                               ; preds = %45
  %50 = load i64, ptr %10, align 8, !tbaa !16
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %117

53:                                               ; preds = %49, %45
  %54 = load i64, ptr %10, align 8, !tbaa !16
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %78

56:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = call ptr @XHTTP_GetHeader(ptr noundef %57, ptr noundef @.str.24)
  store ptr %58, ptr %12, align 8, !tbaa !5
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = call zeroext i8 @xstrused(ptr noundef %59)
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %65, label %62

62:                                               ; preds = %56
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call i32 @XAPI_RespondHTTP(ptr noundef %63, i32 noundef 401, i32 noundef 1)
  store i32 %64, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

65:                                               ; preds = %56
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i64, ptr %10, align 8, !tbaa !16
  %69 = call i32 @strncmp(ptr noundef %66, ptr noundef %67, i64 noundef %68) #5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %65
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = call i32 @XAPI_RespondHTTP(ptr noundef %72, i32 noundef 401, i32 noundef 2)
  store i32 %73, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

74:                                               ; preds = %65
  store i32 0, ptr %11, align 4
  br label %75

75:                                               ; preds = %74, %71, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %76 = load i32, ptr %11, align 4
  switch i32 %76, label %117 [
    i32 0, label %77
  ]

77:                                               ; preds = %75
  br label %78

78:                                               ; preds = %77, %53
  %79 = load i64, ptr %9, align 8, !tbaa !16
  %80 = icmp ne i64 %79, 0
  br i1 %80, label %81, label %116

81:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = call ptr @XHTTP_GetHeader(ptr noundef %82, ptr noundef @.str.25)
  store ptr %83, ptr %13, align 8, !tbaa !5
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = call zeroext i8 @xstrused(ptr noundef %84)
  %86 = icmp ne i8 %85, 0
  br i1 %86, label %90, label %87

87:                                               ; preds = %81
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = call i32 @XAPI_RespondHTTP(ptr noundef %88, i32 noundef 401, i32 noundef 6)
  store i32 %89, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %113

90:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = call i32 @xstrsrc(ptr noundef %91, ptr noundef @.str.26)
  store i32 %92, ptr %14, align 4, !tbaa !17
  %93 = load i32, ptr %14, align 4, !tbaa !17
  %94 = icmp slt i32 %93, 0
  br i1 %94, label %95, label %98

95:                                               ; preds = %90
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = call i32 @XAPI_RespondHTTP(ptr noundef %96, i32 noundef 401, i32 noundef 6)
  store i32 %97, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %112

98:                                               ; preds = %90
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = load i32, ptr %14, align 4, !tbaa !17
  %101 = add nsw i32 %100, 6
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds i8, ptr %99, i64 %102
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = load i64, ptr %9, align 8, !tbaa !16
  %106 = call i32 @strncmp(ptr noundef %103, ptr noundef %104, i64 noundef %105) #5
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %108, label %111

108:                                              ; preds = %98
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = call i32 @XAPI_RespondHTTP(ptr noundef %109, i32 noundef 401, i32 noundef 5)
  store i32 %110, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %112

111:                                              ; preds = %98
  store i32 0, ptr %11, align 4
  br label %112

112:                                              ; preds = %111, %108, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %113

113:                                              ; preds = %112, %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %114 = load i32, ptr %11, align 4
  switch i32 %114, label %117 [
    i32 0, label %115
  ]

115:                                              ; preds = %113
  br label %116

116:                                              ; preds = %115, %78
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %117

117:                                              ; preds = %116, %113, %75, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %118

118:                                              ; preds = %117, %22
  %119 = load i32, ptr %4, align 4
  ret i32 %119
}

declare zeroext i8 @xstrused(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

declare ptr @XHTTP_GetHeader(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @xstrsrc(ptr noundef, ptr noundef) #2

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 = { "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 willreturn memory(read) "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 2576}
!10 = !{!"xapi_data_", !7, i64 0, !7, i64 128, !7, i64 256, !11, i64 2304, !12, i64 2312, !13, i64 2464, !7, i64 2468, !7, i64 2469, !7, i64 2470, !7, i64 2471, !7, i64 2472, !7, i64 2473, !14, i64 2480, !14, i64 2512, !6, i64 2544, !13, i64 2552, !13, i64 2556, !6, i64 2560, !6, i64 2568, !6, i64 2576}
!11 = !{!"short", !7, i64 0}
!12 = !{!"XSocket", !13, i64 0, !7, i64 4, !13, i64 116, !13, i64 120, !11, i64 124, !13, i64 128, !13, i64 132, !13, i64 136, !13, i64 140, !6, i64 144}
!13 = !{!"int", !7, i64 0}
!14 = !{!"XByteBuffer", !6, i64 0, !15, i64 8, !15, i64 16, !11, i64 24, !11, i64 26, !13, i64 28}
!15 = !{!"long", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!13, !13, 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"

@.str.24 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 2576
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not41 = icmp eq ptr %6, null
  br i1 %.not41, label %.thread, label %7

7:                                                ; preds = %4
  %8 = tail call zeroext i8 @xstrused(ptr noundef %1) #3
  %.not42 = icmp eq i8 %8, 0
  br i1 %.not42, label %11, label %9

9:                                                ; preds = %7
  %10 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  br label %11

11:                                               ; preds = %7, %9
  %12 = phi i64 [ %10, %9 ], [ 0, %7 ]
  %13 = tail call zeroext i8 @xstrused(ptr noundef %2) #3
  %.not43 = icmp eq i8 %13, 0
  br i1 %.not43, label %16, label %14

14:                                               ; preds = %11
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #4
  br label %16

16:                                               ; preds = %11, %14
  %17 = phi i64 [ %15, %14 ], [ 0, %11 ]
  %18 = icmp ne i64 %12, 0
  %19 = icmp ne i64 %17, 0
  %or.cond = select i1 %18, i1 true, i1 %19
  br i1 %or.cond, label %20, label %.thread

20:                                               ; preds = %16
  br i1 %19, label %21, label %26

21:                                               ; preds = %20
  %22 = tail call ptr @XHTTP_GetHeader(ptr noundef nonnull %6, ptr noundef nonnull @.str.24) #3
  %23 = tail call zeroext i8 @xstrused(ptr noundef %22) #3
  %.not44 = icmp eq i8 %23, 0
  br i1 %.not44, label %.thread.sink.split, label %24

24:                                               ; preds = %21
  %25 = tail call i32 @strncmp(ptr noundef %22, ptr noundef %2, i64 noundef %17) #4
  %.not45 = icmp eq i32 %25, 0
  br i1 %.not45, label %26, label %.thread.sink.split

26:                                               ; preds = %24, %20
  br i1 %18, label %27, label %.thread

27:                                               ; preds = %26
  %28 = tail call ptr @XHTTP_GetHeader(ptr noundef nonnull %6, ptr noundef nonnull @.str.25) #3
  %29 = tail call zeroext i8 @xstrused(ptr noundef %28) #3
  %.not46 = icmp eq i8 %29, 0
  br i1 %.not46, label %.thread.sink.split, label %30

30:                                               ; preds = %27
  %31 = tail call i32 @xstrsrc(ptr noundef %28, ptr noundef nonnull @.str.26) #3
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %.thread.sink.split, label %33

33:                                               ; preds = %30
  %34 = zext nneg i32 %31 to i64
  %35 = getelementptr inbounds i8, ptr %28, i64 %34
  %36 = getelementptr inbounds i8, ptr %35, i64 6
  %37 = tail call i32 @strncmp(ptr noundef nonnull %36, ptr noundef %1, i64 noundef %12) #4
  %.not47 = icmp eq i32 %37, 0
  br i1 %.not47, label %.thread, label %.thread.sink.split

.thread.sink.split:                               ; preds = %33, %30, %27, %24, %21
  %.sink = phi i32 [ 1, %21 ], [ 2, %24 ], [ 6, %27 ], [ 6, %30 ], [ 5, %33 ]
  %38 = tail call i32 @XAPI_RespondHTTP(ptr noundef nonnull %0, i32 noundef 401, i32 noundef %.sink)
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %26, %33, %16, %3, %4
  %.5 = phi i32 [ -1, %4 ], [ -1, %3 ], [ 1, %16 ], [ 1, %33 ], [ 1, %26 ], [ %38, %.thread.sink.split ]
  ret i32 %.5
}

declare zeroext i8 @xstrused(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

declare ptr @XHTTP_GetHeader(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

declare i32 @xstrsrc(ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #4 = { 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, !12, i64 2576}
!6 = !{!"xapi_data_", !7, i64 0, !7, i64 128, !7, i64 256, !9, i64 2304, !10, i64 2312, !11, i64 2464, !7, i64 2468, !7, i64 2469, !7, i64 2470, !7, i64 2471, !7, i64 2472, !7, i64 2473, !13, i64 2480, !13, i64 2512, !12, i64 2544, !11, i64 2552, !11, i64 2556, !12, i64 2560, !12, i64 2568, !12, i64 2576}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"XSocket", !11, i64 0, !7, i64 4, !11, i64 116, !11, i64 120, !9, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !12, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"XByteBuffer", !12, i64 0, !14, i64 8, !14, i64 16, !9, i64 24, !9, i64 26, !11, i64 28}
!14 = !{!"long", !7, i64 0}


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