; LLVM IR from tleonhardt/practical_cryptography_engineering :: sodium (nacl_symmetric_gen)

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

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca [32 x i8], align 16
  %11 = alloca [65 x i8], align 16
  %12 = alloca i64, align 8
  %13 = alloca [24 x i8], align 16
  %14 = alloca [20 x i8], align 16
  %15 = alloca [5 x i8], align 1
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 2
  br i1 %17, label %18, label %23

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %19, i64 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %21)
  br label %86

23:                                               ; preds = %2
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %24, i64 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  store ptr %26, ptr %8, align 8, !tbaa !9
  %27 = call i32 @sodium_init()
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %23
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %94

31:                                               ; preds = %23
  %32 = call ptr @sodium_version_string()
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %32)
  %34 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  call void @crypto_secretbox_keygen(ptr noundef %34)
  %35 = getelementptr inbounds [65 x i8], ptr %11, i64 0, i64 0
  %36 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %37 = call ptr @sodium_bin2hex(ptr noundef %35, i64 noundef 65, ptr noundef %36, i64 noundef 32)
  %38 = getelementptr inbounds [65 x i8], ptr %11, i64 0, i64 0
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %38)
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %40)
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = call noalias ptr @fopen(ptr noundef %42, ptr noundef @.str.5)
  store ptr %43, ptr %7, align 8, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = icmp eq ptr null, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %31
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %47)
  br label %86

49:                                               ; preds = %31
  %50 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  %52 = call i64 @fwrite(ptr noundef %50, i64 noundef 1, i64 noundef 32, ptr noundef %51)
  store i64 %52, ptr %12, align 8, !tbaa !11
  %53 = load i64, ptr %12, align 8, !tbaa !11
  %54 = icmp ne i64 32, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %49
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %86

57:                                               ; preds = %49
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %59 = getelementptr inbounds [24 x i8], ptr %13, i64 0, i64 0
  call void @randombytes_buf(ptr noundef %59, i64 noundef 24)
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %61 = getelementptr inbounds [20 x i8], ptr %14, i64 0, i64 0
  %62 = getelementptr inbounds [24 x i8], ptr %13, i64 0, i64 0
  %63 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %64 = call i32 @crypto_secretbox_easy(ptr noundef %61, ptr noundef @.str.10, i64 noundef 4, ptr noundef %62, ptr noundef %63)
  store i32 %64, ptr %6, align 4, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %57
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, i32 noundef 4)
  br label %69

69:                                               ; preds = %67, %57
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  %72 = getelementptr inbounds [5 x i8], ptr %15, i64 0, i64 0
  %73 = getelementptr inbounds [20 x i8], ptr %14, i64 0, i64 0
  %74 = getelementptr inbounds [24 x i8], ptr %13, i64 0, i64 0
  %75 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %76 = call i32 @crypto_secretbox_open_easy(ptr noundef %72, ptr noundef %73, i64 noundef 20, ptr noundef %74, ptr noundef %75)
  store i32 %76, ptr %6, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %69
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef 20)
  br label %81

81:                                               ; preds = %79, %69
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.14)
  %83 = getelementptr inbounds [5 x i8], ptr %15, i64 0, i64 4
  store i8 0, ptr %83, align 1, !tbaa !13
  %84 = getelementptr inbounds [5 x i8], ptr %15, i64 0, i64 0
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef %84)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %81, %55, %46, %18
  %87 = load ptr, ptr %7, align 8, !tbaa !9
  %88 = icmp ne ptr null, %87
  br i1 %88, label %89, label %92

89:                                               ; preds = %86
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  %91 = call i32 @fclose(ptr noundef %90)
  br label %92

92:                                               ; preds = %89, %86
  %93 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %93, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %94

94:                                               ; preds = %92, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %95 = load i32, ptr %3, align 4
  ret i32 %95
}

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @sodium_init() #2

declare ptr @sodium_version_string() #2

declare void @crypto_secretbox_keygen(ptr noundef) #2

declare ptr @sodium_bin2hex(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare void @randombytes_buf(ptr noundef, i64 noundef) #2

declare i32 @crypto_secretbox_easy(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i32 @crypto_secretbox_open_easy(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync 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 }

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

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [32 x i8], align 16
  %4 = alloca [65 x i8], align 16
  %5 = alloca [24 x i8], align 16
  %6 = alloca [20 x i8], align 16
  %7 = alloca [5 x i8], align 1
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %11, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %9)
  br label %.thread

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = tail call i32 @sodium_init() #3
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.thread

18:                                               ; preds = %11
  %19 = tail call ptr @sodium_version_string() #3
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %19)
  call void @crypto_secretbox_keygen(ptr noundef nonnull %3) #3
  %21 = call ptr @sodium_bin2hex(ptr noundef nonnull %4, i64 noundef 65, ptr noundef nonnull %3, i64 noundef 32) #3
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %4)
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %13)
  %24 = call noalias ptr @fopen(ptr noundef %13, ptr noundef nonnull @.str.5)
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %18
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %13)
  br label %.thread

28:                                               ; preds = %18
  %29 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 1, i64 noundef 32, ptr noundef nonnull %24)
  %.not17 = icmp eq i64 %29, 32
  br i1 %.not17, label %32, label %30

30:                                               ; preds = %28
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %48

32:                                               ; preds = %28
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  call void @randombytes_buf(ptr noundef nonnull %5, i64 noundef 24) #3
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %35 = call i32 @crypto_secretbox_easy(ptr noundef nonnull %6, ptr noundef nonnull @.str.10, i64 noundef 4, ptr noundef nonnull %5, ptr noundef nonnull %3) #3
  %.not18 = icmp eq i32 %35, 0
  br i1 %.not18, label %38, label %36

36:                                               ; preds = %32
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, i32 noundef 4)
  br label %38

38:                                               ; preds = %36, %32
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  %41 = call i32 @crypto_secretbox_open_easy(ptr noundef nonnull %7, ptr noundef nonnull %6, i64 noundef 20, ptr noundef nonnull %5, ptr noundef nonnull %3) #3
  %.not19 = icmp eq i32 %41, 0
  br i1 %.not19, label %44, label %42

42:                                               ; preds = %38
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef 20)
  br label %44

44:                                               ; preds = %42, %38
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14)
  %46 = getelementptr inbounds i8, ptr %7, i64 4
  store i8 0, ptr %46, align 1, !tbaa !9
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15, ptr noundef nonnull %7)
  br label %48

48:                                               ; preds = %30, %44
  %.014 = phi i32 [ 1, %30 ], [ 0, %44 ]
  %49 = call i32 @fclose(ptr noundef nonnull %24)
  br label %.thread

.thread:                                          ; preds = %26, %8, %48, %16
  %.0 = phi i32 [ 1, %16 ], [ %.014, %48 ], [ 1, %8 ], [ 1, %26 ]
  ret i32 %.0
}

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

declare i32 @sodium_init() local_unnamed_addr #2

declare ptr @sodium_version_string() local_unnamed_addr #2

declare void @crypto_secretbox_keygen(ptr noundef) local_unnamed_addr #2

declare ptr @sodium_bin2hex(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @randombytes_buf(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @crypto_secretbox_easy(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @crypto_secretbox_open_easy(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

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

!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}


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