; LLVM IR from kala13x/libxutils :: examples (async-client)

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

@.str.19 = external hidden unnamed_addr constant [22 x i8], align 1
@optarg = external global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [22 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

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

; 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
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.xasync_client_args_t, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [128 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.xasync_client_args_t, ptr %13, i32 0, i32 1
  store i16 0, ptr %14, align 2, !tbaa !12
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.xasync_client_args_t, ptr %15, i32 0, i32 2
  store i8 0, ptr %16, align 2, !tbaa !15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.xasync_client_args_t, ptr %17, i32 0, i32 3
  store i8 0, ptr %18, align 1, !tbaa !16
  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.19) #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 97, label %26
    i32 112, label %32
    i32 117, label %38
    i32 115, label %41
    i32 104, label %44
  ]

26:                                               ; preds = %24
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xasync_client_args_t, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [128 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 128, 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.xasync_client_args_t, ptr %36, i32 0, i32 1
  store i16 %35, ptr %37, align 2, !tbaa !12
  br label %46

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

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

44:                                               ; preds = %24
  br label %45

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

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

47:                                               ; preds = %19
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.xasync_client_args_t, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds [128 x i8], ptr %49, i64 0, i64 0
  %51 = call zeroext i8 @xstrused(ptr noundef %50)
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.20)
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %66

54:                                               ; preds = %47
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.xasync_client_args_t, ptr %55, i32 0, i32 1
  %57 = load i16, ptr %56, align 2, !tbaa !12
  %58 = icmp ne i16 %57, 0
  br i1 %58, label %65, label %59

59:                                               ; preds = %54
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.xasync_client_args_t, ptr %60, i32 0, i32 2
  %62 = load i8, ptr %61, align 2, !tbaa !15
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %65, label %64

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

65:                                               ; preds = %59, %54
  store i8 1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %66

66:                                               ; preds = %65, %64, %53, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %67 = load i8, ptr %4, align 1
  ret i8 %67
}

; 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

declare zeroext i8 @xstrused(ptr noundef) #1

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 128}
!13 = !{!"", !7, i64 0, !14, i64 128, !7, i64 130, !7, i64 131}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !7, i64 130}
!16 = !{!13, !7, i64 131}
!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"

@.str.19 = external hidden unnamed_addr constant [22 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [22 x i8], align 1

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, 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 {
  store i8 0, ptr %0, align 2, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  store i16 0, ptr %4, align 2, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 130
  store i8 0, ptr %5, align 2, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 131
  store i8 0, ptr %6, align 1, !tbaa !12
  br label %7

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

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

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

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

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

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

18:                                               ; preds = %7
  %19 = tail call zeroext i8 @xstrused(ptr noundef nonnull %0) #4
  %.not15 = icmp eq i8 %19, 0
  br i1 %.not15, label %.loopexit.sink.split, label %20

20:                                               ; preds = %18
  %21 = load i16, ptr %4, align 2, !tbaa !8
  %.not16 = icmp eq i16 %21, 0
  br i1 %.not16, label %22, label %.loopexit

22:                                               ; preds = %20
  %23 = load i8, ptr %5, align 2, !tbaa !11
  %.not17 = icmp eq i8 %23, 0
  br i1 %.not17, label %.loopexit.sink.split, label %.loopexit

.loopexit.sink.split:                             ; preds = %22, %18
  %.str.21.sink = phi ptr [ @.str.20, %18 ], [ @.str.21, %22 ]
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull %.str.21.sink) #4
  br label %.loopexit

.loopexit:                                        ; preds = %7, %.loopexit.sink.split, %20, %22
  %.0 = phi i8 [ 1, %22 ], [ 1, %20 ], [ 0, %.loopexit.sink.split ], [ 0, %7 ]
  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

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

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 128}
!9 = !{!"", !6, i64 0, !10, i64 128, !6, i64 130, !6, i64 131}
!10 = !{!"short", !6, i64 0}
!11 = !{!9, !6, i64 130}
!12 = !{!9, !6, i64 131}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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