; LLVM IR from kala13x/libxutils :: examples (ws-server)

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

@.str.33 = external hidden unnamed_addr constant [16 x i8], align 1
@optarg = external global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [29 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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) #1

declare zeroext i8 @xstrused(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @parse_args(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i8, align 1
  %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.xws_args_t, ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  store i8 0, ptr %12, align 2, !tbaa !11
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.xws_args_t, ptr %13, i32 0, i32 2
  %15 = getelementptr inbounds [2048 x i8], ptr %14, i64 0, i64 0
  store i8 0, ptr %15, align 2, !tbaa !11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.xws_args_t, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds [2048 x i8], ptr %17, i64 0, i64 0
  store i8 0, ptr %18, align 2, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.xws_args_t, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds [128 x i8], ptr %20, i64 0, i64 0
  store i8 0, ptr %21, align 2, !tbaa !11
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.xws_args_t, ptr %22, i32 0, i32 4
  store i16 0, ptr %23, align 2, !tbaa !12
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xws_args_t, ptr %24, i32 0, i32 5
  store i8 0, ptr %25, align 2, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %68, %3
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call i32 @getopt(i32 noundef %27, ptr noundef %28, ptr noundef @.str.33) #5
  store i32 %29, ptr %8, align 4, !tbaa !9
  %30 = icmp ne i32 %29, -1
  br i1 %30, label %31, label %69

31:                                               ; preds = %26
  %32 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %32, label %67 [
    i32 97, label %33
    i32 99, label %39
    i32 107, label %45
    i32 114, label %51
    i32 112, label %57
    i32 115, label %63
    i32 104, label %66
  ]

33:                                               ; preds = %31
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.xws_args_t, ptr %34, i32 0, i32 3
  %36 = getelementptr inbounds [128 x i8], ptr %35, i64 0, i64 0
  %37 = load ptr, ptr @optarg, align 8, !tbaa !5
  %38 = call i64 @xstrncpy(ptr noundef %36, i64 noundef 128, ptr noundef %37)
  br label %68

39:                                               ; preds = %31
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.xws_args_t, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds [2048 x i8], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr @optarg, align 8, !tbaa !5
  %44 = call i64 @xstrncpy(ptr noundef %42, i64 noundef 2048, ptr noundef %43)
  br label %68

45:                                               ; preds = %31
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.xws_args_t, ptr %46, i32 0, i32 2
  %48 = getelementptr inbounds [2048 x i8], ptr %47, i64 0, i64 0
  %49 = load ptr, ptr @optarg, align 8, !tbaa !5
  %50 = call i64 @xstrncpy(ptr noundef %48, i64 noundef 2048, ptr noundef %49)
  br label %68

51:                                               ; preds = %31
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.xws_args_t, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [2048 x i8], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr @optarg, align 8, !tbaa !5
  %56 = call i64 @xstrncpy(ptr noundef %54, i64 noundef 2048, ptr noundef %55)
  br label %68

57:                                               ; preds = %31
  %58 = load ptr, ptr @optarg, align 8, !tbaa !5
  %59 = call i32 @atoi(ptr noundef %58) #6
  %60 = trunc i32 %59 to i16
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.xws_args_t, ptr %61, i32 0, i32 4
  store i16 %60, ptr %62, align 2, !tbaa !12
  br label %68

63:                                               ; preds = %31
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.xws_args_t, ptr %64, i32 0, i32 5
  store i8 1, ptr %65, align 2, !tbaa !15
  br label %68

66:                                               ; preds = %31
  br label %67

67:                                               ; preds = %66, %31
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %102

68:                                               ; preds = %63, %57, %51, %45, %39, %33
  br label %26, !llvm.loop !16

69:                                               ; preds = %26
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.xws_args_t, ptr %70, i32 0, i32 3
  %72 = getelementptr inbounds [128 x i8], ptr %71, i64 0, i64 0
  %73 = call zeroext i8 @xstrused(ptr noundef %72)
  %74 = icmp ne i8 %73, 0
  br i1 %74, label %76, label %75

75:                                               ; preds = %69
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.34)
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %102

76:                                               ; preds = %69
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.xws_args_t, ptr %77, i32 0, i32 4
  %79 = load i16, ptr %78, align 2, !tbaa !12
  %80 = icmp ne i16 %79, 0
  br i1 %80, label %82, label %81

81:                                               ; preds = %76
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.35)
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %102

82:                                               ; preds = %76
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.xws_args_t, ptr %83, i32 0, i32 5
  %85 = load i8, ptr %84, align 2, !tbaa !15
  %86 = zext i8 %85 to i32
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %101

88:                                               ; preds = %82
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.xws_args_t, ptr %89, i32 0, i32 1
  %91 = getelementptr inbounds [2048 x i8], ptr %90, i64 0, i64 0
  %92 = call zeroext i8 @xstrused(ptr noundef %91)
  %93 = icmp ne i8 %92, 0
  br i1 %93, label %94, label %100

94:                                               ; preds = %88
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.xws_args_t, ptr %95, i32 0, i32 2
  %97 = getelementptr inbounds [2048 x i8], ptr %96, i64 0, i64 0
  %98 = call zeroext i8 @xstrused(ptr noundef %97)
  %99 = icmp ne i8 %98, 0
  br i1 %99, label %101, label %100

100:                                              ; preds = %94, %88
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.36)
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %102

101:                                              ; preds = %94, %82
  store i8 1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %102

102:                                              ; preds = %101, %100, %81, %75, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %103 = load i8, ptr %4, align 1
  ret i8 %103
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 6272}
!13 = !{!"", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 6144, !14, i64 6272, !7, i64 6274}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !7, i64 6274}
!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.33 = external hidden unnamed_addr constant [16 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [29 x i8], align 1

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @parse_args(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 2048
  store i8 0, ptr %4, align 2, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4096
  store i8 0, ptr %5, align 2, !tbaa !5
  store i8 0, ptr %0, align 2, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 6144
  store i8 0, ptr %6, align 2, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 6272
  store i16 0, ptr %7, align 2, !tbaa !8
  %8 = getelementptr inbounds i8, ptr %0, i64 6274
  store i8 0, ptr %8, align 2, !tbaa !11
  br label %9

9:                                                ; preds = %.backedge, %3
  %10 = tail call i32 @getopt(i32 noundef %1, ptr noundef %2, ptr noundef nonnull @.str.33) #4
  switch i32 %10, label %.loopexit [
    i32 -1, label %28
    i32 97, label %11
    i32 99, label %14
    i32 107, label %17
    i32 114, label %20
    i32 112, label %23
    i32 115, label %27
  ]

11:                                               ; preds = %9
  %12 = load ptr, ptr @optarg, align 8, !tbaa !12
  %13 = tail call i64 @xstrncpy(ptr noundef nonnull %6, i64 noundef 128, ptr noundef %12) #4
  br label %.backedge

14:                                               ; preds = %9
  %15 = load ptr, ptr @optarg, align 8, !tbaa !12
  %16 = tail call i64 @xstrncpy(ptr noundef nonnull %4, i64 noundef 2048, ptr noundef %15) #4
  br label %.backedge

17:                                               ; preds = %9
  %18 = load ptr, ptr @optarg, align 8, !tbaa !12
  %19 = tail call i64 @xstrncpy(ptr noundef nonnull %5, i64 noundef 2048, ptr noundef %18) #4
  br label %.backedge

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

23:                                               ; preds = %9
  %24 = load ptr, ptr @optarg, align 8, !tbaa !12
  %25 = tail call i32 @atoi(ptr nocapture noundef %24) #5
  %26 = trunc i32 %25 to i16
  store i16 %26, ptr %7, align 2, !tbaa !8
  br label %.backedge

27:                                               ; preds = %9
  store i8 1, ptr %8, align 2, !tbaa !11
  br label %.backedge

.backedge:                                        ; preds = %27, %23, %20, %17, %14, %11
  br label %9, !llvm.loop !14

28:                                               ; preds = %9
  %29 = tail call zeroext i8 @xstrused(ptr noundef nonnull %6) #4
  %.not21 = icmp eq i8 %29, 0
  br i1 %.not21, label %.loopexit.sink.split, label %30

30:                                               ; preds = %28
  %31 = load i16, ptr %7, align 2, !tbaa !8
  %.not22 = icmp eq i16 %31, 0
  br i1 %.not22, label %.loopexit.sink.split, label %32

32:                                               ; preds = %30
  %33 = load i8, ptr %8, align 2, !tbaa !11
  %.not23 = icmp eq i8 %33, 0
  br i1 %.not23, label %.loopexit, label %34

34:                                               ; preds = %32
  %35 = tail call zeroext i8 @xstrused(ptr noundef nonnull %4) #4
  %.not24 = icmp eq i8 %35, 0
  br i1 %.not24, label %.loopexit.sink.split, label %36

36:                                               ; preds = %34
  %37 = tail call zeroext i8 @xstrused(ptr noundef nonnull %5) #4
  %.not25 = icmp eq i8 %37, 0
  br i1 %.not25, label %.loopexit.sink.split, label %.loopexit

.loopexit.sink.split:                             ; preds = %34, %36, %30, %28
  %.str.36.sink = phi ptr [ @.str.34, %28 ], [ @.str.35, %30 ], [ @.str.36, %36 ], [ @.str.36, %34 ]
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull %.str.36.sink) #4
  br label %.loopexit

.loopexit:                                        ; preds = %9, %.loopexit.sink.split, %32, %36
  %.0 = phi i8 [ 1, %36 ], [ 1, %32 ], [ 0, %.loopexit.sink.split ], [ 0, %9 ]
  ret i8 %.0
}

; 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 #0

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

attributes #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 = { 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 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 6272}
!9 = !{!"", !6, i64 0, !6, i64 2048, !6, i64 4096, !6, i64 6144, !10, i64 6272, !6, i64 6274}
!10 = !{!"short", !6, i64 0}
!11 = !{!9, !6, i64 6274}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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