; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (nem)

; 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.nem_transaction_ctx = type { [32 x i8], ptr, i64, i64 }

; 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 willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @nem_transaction_write_common(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u32(ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_tagged(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u64(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @nem_transaction_create_provision_namespace(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, i64 noundef %9) #2 {
  %11 = alloca i1, align 1
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca i8, align 1
  %23 = alloca i32, align 4
  store ptr %0, ptr %12, align 8, !tbaa !5
  store i8 %1, ptr %13, align 1, !tbaa !9
  store i32 %2, ptr %14, align 4, !tbaa !10
  store ptr %3, ptr %15, align 8, !tbaa !5
  store i64 %4, ptr %16, align 8, !tbaa !12
  store i32 %5, ptr %17, align 4, !tbaa !10
  store ptr %6, ptr %18, align 8, !tbaa !5
  store ptr %7, ptr %19, align 8, !tbaa !5
  store ptr %8, ptr %20, align 8, !tbaa !5
  store i64 %9, ptr %21, align 8, !tbaa !12
  %24 = load ptr, ptr %15, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %30, label %26

26:                                               ; preds = %10
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.nem_transaction_ctx, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [32 x i8], ptr %28, i64 0, i64 0
  store ptr %29, ptr %15, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %26, %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %22) #4
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = load i8, ptr %13, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = shl i32 %33, 24
  %35 = or i32 %34, 1
  %36 = load i32, ptr %14, align 4, !tbaa !10
  %37 = load ptr, ptr %15, align 8, !tbaa !5
  %38 = load i64, ptr %16, align 8, !tbaa !12
  %39 = load i32, ptr %17, align 4, !tbaa !10
  %40 = call zeroext i1 @nem_transaction_write_common(ptr noundef %31, i32 noundef 8193, i32 noundef %35, i32 noundef %36, ptr noundef %37, i64 noundef %38, i32 noundef %39)
  %41 = zext i1 %40 to i8
  store i8 %41, ptr %22, align 1, !tbaa !14
  %42 = load i8, ptr %22, align 1, !tbaa !14, !range !16, !noundef !17
  %43 = trunc i8 %42 to i1
  br i1 %43, label %45, label %44

44:                                               ; preds = %30
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

45:                                               ; preds = %30
  %46 = load ptr, ptr %19, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %87

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %20, align 8, !tbaa !5
  %52 = call zeroext i1 @nem_write_tagged(ptr noundef %50, ptr noundef %51, i32 noundef 40)
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

54:                                               ; preds = %49
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load i64, ptr %21, align 8, !tbaa !12
  %60 = call zeroext i1 @nem_write_u64(ptr noundef %58, i64 noundef %59)
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

62:                                               ; preds = %57
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = load ptr, ptr %18, align 8, !tbaa !5
  %68 = load ptr, ptr %18, align 8, !tbaa !5
  %69 = call i64 @strlen(ptr noundef %68) #5
  %70 = trunc i64 %69 to i32
  %71 = call zeroext i1 @nem_write_tagged(ptr noundef %66, ptr noundef %67, i32 noundef %70)
  br i1 %71, label %73, label %72

72:                                               ; preds = %65
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

73:                                               ; preds = %65
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = load ptr, ptr %19, align 8, !tbaa !5
  %79 = load ptr, ptr %19, align 8, !tbaa !5
  %80 = call i64 @strlen(ptr noundef %79) #5
  %81 = trunc i64 %80 to i32
  %82 = call zeroext i1 @nem_write_tagged(ptr noundef %77, ptr noundef %78, i32 noundef %81)
  br i1 %82, label %84, label %83

83:                                               ; preds = %76
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

84:                                               ; preds = %76
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85
  br label %122

87:                                               ; preds = %45
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = load ptr, ptr %20, align 8, !tbaa !5
  %91 = call zeroext i1 @nem_write_tagged(ptr noundef %89, ptr noundef %90, i32 noundef 40)
  br i1 %91, label %93, label %92

92:                                               ; preds = %88
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

93:                                               ; preds = %88
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  br label %96

96:                                               ; preds = %95
  %97 = load ptr, ptr %12, align 8, !tbaa !5
  %98 = load i64, ptr %21, align 8, !tbaa !12
  %99 = call zeroext i1 @nem_write_u64(ptr noundef %97, i64 noundef %98)
  br i1 %99, label %101, label %100

100:                                              ; preds = %96
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

101:                                              ; preds = %96
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102
  br label %104

104:                                              ; preds = %103
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  %106 = load ptr, ptr %18, align 8, !tbaa !5
  %107 = load ptr, ptr %18, align 8, !tbaa !5
  %108 = call i64 @strlen(ptr noundef %107) #5
  %109 = trunc i64 %108 to i32
  %110 = call zeroext i1 @nem_write_tagged(ptr noundef %105, ptr noundef %106, i32 noundef %109)
  br i1 %110, label %112, label %111

111:                                              ; preds = %104
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

112:                                              ; preds = %104
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %12, align 8, !tbaa !5
  %117 = call zeroext i1 @nem_write_u32(ptr noundef %116, i32 noundef -1)
  br i1 %117, label %119, label %118

118:                                              ; preds = %115
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

119:                                              ; preds = %115
  br label %120

120:                                              ; preds = %119
  br label %121

121:                                              ; preds = %120
  br label %122

122:                                              ; preds = %121, %86
  store i1 true, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %123

123:                                              ; preds = %122, %118, %111, %100, %92, %83, %72, %61, %53, %44
  call void @llvm.lifetime.end.p0(i64 1, ptr %22) #4
  %124 = load i1, ptr %11, align 1
  ret i1 %124
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @nem_transaction_write_common(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u32(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_tagged(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u64(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @nem_transaction_create_provision_namespace(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, i64 noundef %9) local_unnamed_addr #1 {
  %.not = icmp eq ptr %3, null
  %spec.select = select i1 %.not, ptr %0, ptr %3
  %11 = zext i8 %1 to i32
  %12 = shl nuw i32 %11, 24
  %13 = or disjoint i32 %12, 1
  %14 = tail call zeroext i1 @nem_transaction_write_common(ptr noundef %0, i32 noundef 8193, i32 noundef %13, i32 noundef %2, ptr noundef %spec.select, i64 noundef %4, i32 noundef %5)
  br i1 %14, label %15, label %38

15:                                               ; preds = %10
  %.not31 = icmp eq ptr %7, null
  %16 = tail call zeroext i1 @nem_write_tagged(ptr noundef %0, ptr noundef %8, i32 noundef 40)
  br i1 %.not31, label %28, label %17

17:                                               ; preds = %15
  br i1 %16, label %18, label %38

18:                                               ; preds = %17
  %19 = tail call zeroext i1 @nem_write_u64(ptr noundef %0, i64 noundef %9)
  br i1 %19, label %20, label %38

20:                                               ; preds = %18
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #3
  %22 = trunc i64 %21 to i32
  %23 = tail call zeroext i1 @nem_write_tagged(ptr noundef %0, ptr noundef %6, i32 noundef %22)
  br i1 %23, label %24, label %38

24:                                               ; preds = %20
  %25 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %7) #3
  %26 = trunc i64 %25 to i32
  %27 = tail call zeroext i1 @nem_write_tagged(ptr noundef %0, ptr noundef nonnull %7, i32 noundef %26)
  br i1 %27, label %37, label %38

28:                                               ; preds = %15
  br i1 %16, label %29, label %38

29:                                               ; preds = %28
  %30 = tail call zeroext i1 @nem_write_u64(ptr noundef %0, i64 noundef %9)
  br i1 %30, label %31, label %38

31:                                               ; preds = %29
  %32 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #3
  %33 = trunc i64 %32 to i32
  %34 = tail call zeroext i1 @nem_write_tagged(ptr noundef %0, ptr noundef %6, i32 noundef %33)
  br i1 %34, label %35, label %38

35:                                               ; preds = %31
  %36 = tail call zeroext i1 @nem_write_u32(ptr noundef %0, i32 noundef -1)
  br i1 %36, label %37, label %38

37:                                               ; preds = %35, %24
  br label %38

38:                                               ; preds = %35, %31, %29, %28, %24, %20, %18, %17, %10, %37
  %.0 = phi i1 [ true, %37 ], [ false, %10 ], [ false, %17 ], [ false, %18 ], [ false, %20 ], [ false, %24 ], [ false, %28 ], [ false, %29 ], [ false, %31 ], [ false, %35 ]
  ret i1 %.0
}

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


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