; LLVM IR from Aeternum-Veritas/Merry :: childmain (merry_get_and_set_id)

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

@stdout = external global ptr, align 8
@stderr = external global ptr, align 8
@id = external hidden global i8, align 1
@.str.17 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [42 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_get_and_set_id() #2 {
  %1 = alloca i8, align 1
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  %6 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef @.str.17, ptr noundef null) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %7 = call noalias ptr @fopen(ptr noundef @.str.18, ptr noundef @.str.19)
  store ptr %7, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %0
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef @.str.20) #4
  store i8 1, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %45

13:                                               ; preds = %0
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call zeroext i8 @lock_file(ptr noundef %14)
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = call i32 @fclose(ptr noundef %19)
  store i8 1, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %45

21:                                               ; preds = %13
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = call i64 @fread(ptr noundef @id, i64 noundef 1, i64 noundef 1, ptr noundef %22)
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %24 = load i8, ptr @id, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = add nsw i32 %25, 1
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %4, align 1, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = call i64 @fwrite(ptr noundef %4, i64 noundef 1, i64 noundef 1, ptr noundef %28)
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call zeroext i8 @unlock_file(ptr noundef %30)
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %37

34:                                               ; preds = %21
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = call i32 @fclose(ptr noundef %35)
  store i8 1, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %44

37:                                               ; preds = %21
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call i32 @fclose(ptr noundef %38)
  %40 = load ptr, ptr @stdout, align 8, !tbaa !5
  %41 = load i8, ptr %4, align 1, !tbaa !9
  %42 = zext i8 %41 to i32
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str.21, i32 noundef %42) #4
  store i8 0, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %44

44:                                               ; preds = %37, %34
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  br label %45

45:                                               ; preds = %44, %18, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %46 = load i8, ptr %1, align 1
  ret i8 %46
}

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

declare zeroext i8 @lock_file(ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

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

declare zeroext i8 @unlock_file(ptr noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 }

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


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

@stdout = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@id = external hidden global i8, align 1
@.str.17 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [42 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: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_get_and_set_id() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdout, align 8, !tbaa !5
  %2 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.17, ptr noundef null) #4
  %3 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.19)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %8

5:                                                ; preds = %0
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.20) #5
  br label %24

8:                                                ; preds = %0
  %9 = tail call zeroext i8 @lock_file(ptr noundef nonnull %3) #4
  %10 = icmp eq i8 %9, 1
  br i1 %10, label %11, label %13

11:                                               ; preds = %8
  %12 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %24

13:                                               ; preds = %8
  %14 = tail call i64 @fread(ptr noundef nonnull @id, i64 noundef 1, i64 noundef 1, ptr noundef nonnull %3)
  %15 = load i8, ptr @id, align 1, !tbaa !9
  %16 = add i8 %15, 1
  %chari = sext i8 %16 to i32
  %fputc = tail call i32 @fputc(i32 %chari, ptr nonnull %3)
  %17 = tail call zeroext i8 @unlock_file(ptr noundef nonnull %3) #4
  %18 = icmp eq i8 %17, 1
  %19 = tail call i32 @fclose(ptr noundef nonnull %3)
  br i1 %18, label %24, label %20

20:                                               ; preds = %13
  %21 = load ptr, ptr @stdout, align 8, !tbaa !5
  %22 = zext i8 %16 to i32
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.21, i32 noundef %22) #4
  br label %24

24:                                               ; preds = %13, %20, %11, %5
  %.1 = phi i8 [ 1, %5 ], [ 1, %11 ], [ 0, %20 ], [ 1, %13 ]
  ret i8 %.1
}

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

declare zeroext i8 @lock_file(ptr noundef) local_unnamed_addr #2

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

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

declare zeroext i8 @unlock_file(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #3

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 = { 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 = { "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 = { nofree nounwind }
attributes #4 = { nounwind }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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