; LLVM IR from rweather/lightweight-crypto :: src/genavr/algorithm_gascon.ll (Z19test_drysponge128_gR4Code)

; 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.drysponge128_state_t = type { [40 x i8], [16 x i8], [16 x i8], i32, i32 }

@_ZL15gascon128_input = external hidden constant [40 x i8], align 16
@_ZL16gascon128_output = external hidden constant [40 x i8], align 16
@_ZL18gascon128_squeezed = external hidden constant [16 x i8], align 16

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @_ZN4Code16exec_permutationEPvjjjjj(ptr noundef nonnull align 8 dereferenceable(200), ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z19test_drysponge128_gR4Code(ptr noundef nonnull align 8 dereferenceable(200) %0) #4 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca %struct.drysponge128_state_t, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %4) #6
  call void @llvm.memset.p0.i64(ptr align 4 %4, i8 0, i64 80, i1 false)
  %6 = getelementptr inbounds %struct.drysponge128_state_t, ptr %4, i32 0, i32 0
  %7 = getelementptr inbounds [40 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 16 @_ZL15gascon128_input, i64 40, i1 false)
  %8 = getelementptr inbounds %struct.drysponge128_state_t, ptr %4, i32 0, i32 4
  store i32 12, ptr %8, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN4Code16exec_permutationEPvjjjjj(ptr noundef nonnull align 8 dereferenceable(200) %9, ptr noundef %4, i32 noundef 80, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %10 = getelementptr inbounds %struct.drysponge128_state_t, ptr %4, i32 0, i32 0
  %11 = getelementptr inbounds [40 x i8], ptr %10, i64 0, i64 0
  %12 = call i32 @memcmp(ptr noundef @_ZL16gascon128_output, ptr noundef %11, i64 noundef 40) #7
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %21

15:                                               ; preds = %1
  %16 = getelementptr inbounds %struct.drysponge128_state_t, ptr %4, i32 0, i32 1
  %17 = getelementptr inbounds [16 x i8], ptr %16, i64 0, i64 0
  %18 = call i32 @memcmp(ptr noundef @_ZL18gascon128_squeezed, ptr noundef %17, i64 noundef 16) #7
  %19 = icmp ne i32 %18, 0
  %20 = xor i1 %19, true
  store i1 %20, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %21

21:                                               ; preds = %15, %14
  call void @llvm.lifetime.end.p0(i64 80, ptr %4) #6
  %22 = load i1, ptr %2, align 1
  ret i1 %22
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { 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++ TBAA"}
!9 = !{!10, !11, i64 76}
!10 = !{!"_ZTS20drysponge128_state_t", !7, i64 0, !7, i64 40, !7, i64 56, !11, i64 72, !11, i64 76}
!11 = !{!"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"

%struct.drysponge128_state_t = type { [40 x i8], [16 x i8], [16 x i8], i32, i32 }

@_ZL15gascon128_input = external hidden local_unnamed_addr constant [40 x i8], align 16
@_ZL16gascon128_output = external hidden constant [40 x i8], align 16
@_ZL18gascon128_squeezed = external hidden constant [16 x i8], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @_ZN4Code16exec_permutationEPvjjjjj(ptr noundef nonnull align 8 dereferenceable(200), ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z19test_drysponge128_gR4Code(ptr noundef nonnull align 8 dereferenceable(200) %0) local_unnamed_addr #3 {
  %2 = alloca %struct.drysponge128_state_t, align 4
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %2) #6
  %3 = getelementptr inbounds i8, ptr %2, i64 40
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %3, i8 0, i64 36, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(40) %2, ptr noundef nonnull align 16 dereferenceable(40) @_ZL15gascon128_input, i64 40, i1 false)
  %4 = getelementptr inbounds i8, ptr %2, i64 76
  store i32 12, ptr %4, align 4, !tbaa !5
  call void @_ZN4Code16exec_permutationEPvjjjjj(ptr noundef nonnull align 8 dereferenceable(200) %0, ptr noundef nonnull %2, i32 noundef 80, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(40) @_ZL16gascon128_output, ptr noundef nonnull dereferenceable(40) %2, i64 40)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %5, label %7

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %2, i64 40
  %bcmp2 = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @_ZL18gascon128_squeezed, ptr noundef nonnull dereferenceable(16) %6, i64 16)
  %.not3 = icmp eq i32 %bcmp2, 0
  br label %7

7:                                                ; preds = %1, %5
  %.0 = phi i1 [ %.not3, %5 ], [ false, %1 ]
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %2) #6
  ret i1 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nofree nounwind willreturn memory(argmem: read) }
attributes #6 = { 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, !9, i64 76}
!6 = !{!"_ZTS20drysponge128_state_t", !7, i64 0, !7, i64 40, !7, i64 56, !9, i64 72, !9, i64 76}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass