; LLVM IR from guanzhi/GmSSL :: src (tls)

; 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"

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__FUNCTION__.tls_uint32_from_bytes = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_uint32_from_bytes(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
  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
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp ult i64 %9, 4
  br i1 %10, label %11, label %16

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 145, ptr noundef @__FUNCTION__.tls_uint32_from_bytes) #2
  br label %15

15:                                               ; preds = %12
  store i32 -1, ptr %4, align 4
  br label %59

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i32 1
  store ptr %19, ptr %17, align 8, !tbaa !5
  %20 = load i8, ptr %18, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %21, ptr %22, align 4, !tbaa !12
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = shl i32 %24, 8
  store i32 %25, ptr %23, align 4, !tbaa !12
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %26, align 8, !tbaa !5
  %29 = load i8, ptr %27, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = or i32 %32, %30
  store i32 %33, ptr %31, align 4, !tbaa !12
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = shl i32 %35, 8
  store i32 %36, ptr %34, align 4, !tbaa !12
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %37, align 8, !tbaa !5
  %40 = load i8, ptr %38, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = or i32 %43, %41
  store i32 %44, ptr %42, align 4, !tbaa !12
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = shl i32 %46, 8
  store i32 %47, ptr %45, align 4, !tbaa !12
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %48, align 8, !tbaa !5
  %51 = load i8, ptr %49, align 1, !tbaa !11
  %52 = zext i8 %51 to i32
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 4, !tbaa !12
  %55 = or i32 %54, %52
  store i32 %55, ptr %53, align 4, !tbaa !12
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = sub i64 %57, 4
  store i64 %58, ptr %56, align 8, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %59

59:                                               ; preds = %16, %15
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

attributes #0 = { 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 #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 }

!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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__FUNCTION__.tls_uint32_from_bytes = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_uint32_from_bytes(ptr nocapture noundef writeonly %0, ptr nocapture noundef %1, ptr nocapture noundef %2) local_unnamed_addr #1 {
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = icmp ult i64 %4, 4
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = load ptr, ptr @stderr, align 8, !tbaa !9
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 145, ptr noundef nonnull @__FUNCTION__.tls_uint32_from_bytes) #2
  br label %30

9:                                                ; preds = %3
  %10 = load ptr, ptr %1, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 1
  store ptr %11, ptr %1, align 8, !tbaa !9
  %12 = load i8, ptr %10, align 1, !tbaa !11
  %13 = zext i8 %12 to i32
  %14 = shl nuw nsw i32 %13, 8
  store i32 %14, ptr %0, align 4, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %10, i64 2
  store ptr %15, ptr %1, align 8, !tbaa !9
  %16 = load i8, ptr %11, align 1, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = or disjoint i32 %14, %17
  %19 = shl nuw nsw i32 %18, 8
  store i32 %19, ptr %0, align 4, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %10, i64 3
  store ptr %20, ptr %1, align 8, !tbaa !9
  %21 = load i8, ptr %15, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = or disjoint i32 %19, %22
  %24 = shl nuw i32 %23, 8
  store i32 %24, ptr %0, align 4, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %10, i64 4
  store ptr %25, ptr %1, align 8, !tbaa !9
  %26 = load i8, ptr %20, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = or disjoint i32 %24, %27
  store i32 %28, ptr %0, align 4, !tbaa !12
  %29 = add i64 %4, -4
  store i64 %29, ptr %2, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %9, %6
  %.0 = phi i32 [ -1, %6 ], [ 1, %9 ]
  ret i32 %.0
}

attributes #0 = { nofree 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 #1 = { nofree 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 = { cold 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 = !{!"long", !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass