#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error_at_line(int, int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/);
scalar_t__ memcmp(char *, char *, size_t);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int check_magic(FILE *in) {
  size_t m_sz = sizeof("GnomeKeyring\n\r\0\n") - 1;
  char buf[m_sz];
  size_t r = fread(buf, 1, m_sz, in);
  int err = 0;
  if (r == 0) {
    error_at_line(1, errno,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/jmesmon/trifles/refs/"
                  "heads/master/gkr-decrypt.c",
                  46, "failed to read");
  }
  if (r != m_sz) {
    do {
      fprintf(stderr, "magic is %zu bytes and should be %zu bytes.", r, m_sz);
      putc('\n', stderr);
    } while (0);
    err++;
  }
  if (memcmp(buf, "GnomeKeyring\n\r\0\n", r)) {
    fprintf(stderr, "expected magic but got \"");
    __attribute__((unused)) size_t a = fwrite(buf, 1, r, stderr);
    fputs("\"\n", stderr);
    err++;
  }
  return -err;
}


x86 assembly (clang, -O0):
<check_magic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x10,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f9 <check_magic+0x89>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe18(%rip),%rdx
mov    $0x2e,%ecx
lea    0xe96(%rip),%r8
call   1030 <error_at_line@plt>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     124c <check_magic+0xdc>
jmp    120c <check_magic+0x9c>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1070 <putc@plt>
jmp    1243 <check_magic+0xd3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe86(%rip),%rsi
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     12be <check_magic+0x14e>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2d50(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
lea    0xe2e(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
sub    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_magic>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rcx
mov    %rsp,%rdi
mov    $0x10,%edx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,%rbx
cmp    $0x10,%rax
je     11f5 <check_magic+0x85>
test   %rbx,%rbx
jne    11c1 <check_magic+0x51>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdx
lea    0xed8(%rip),%r8
mov    $0x1,%edi
mov    $0x2e,%ecx
call   1030 <error_at_line@plt>
mov    0x2e18(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xec7(%rip),%rsi
mov    $0x10,%ecx
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%rbp),%esi
mov    $0xa,%edi
call   1070 <putc@plt>
mov    $0x1,%ebp
jmp    11f7 <check_magic+0x87>
xor    %ebp,%ebp
lea    0xee3(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
call   1060 <memcmp@plt>
test   %rax,%rax
je     124b <check_magic+0xdb>
mov    0x2dcb(%rip),%r14
mov    (%r14),%edi
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r14),%ecx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1090 <fwrite@plt>
mov    (%r14),%esi
lea    0xe9b(%rip),%rdi
call   1050 <fputs@plt>
add    $0x1,%ebp
neg    %ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jmesmon/trifles/refs/heads/master/gkr-decrypt.c\00"
@.str.1 = [15 x i8] c"failed to read\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"magic is %zu bytes and should be %zu bytes.\00"
@.str.3 = [17 x i8] c"GnomeKeyring\0A\0D\00\0A\00"
@.str.4 = [25 x i8] c"expected magic but got \22\00"
@.str.5 = [3 x i8] c"\22\0A\00"
define i32 @check_magic(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i32* %0, i32** %2
store i64 16, i64* %3
%9 = load i64, i64* %3
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = load i64, i64* %3
%13 = load i32*, i32** %2
%14 = call i64 @fread(i8* %11, i32 1, i64 %12, i32* %13)
store i64 %14, i64* %6
store i32 0, i32* %7
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* @errno
%19 = call i32 @error_at_line(i32 1, i32 %18, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %1
%21 = load i64, i64* %6
%22 = load i64, i64* %3
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
br label %25
25: ; preds = %24
%26 = load i32, i32* @stderr
%27 = load i64, i64* %6
%28 = load i64, i64* %3
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i64 %27, i64 %28)
%30 = load i32, i32* @stderr
%31 = call i32 @putc(i8 signext 10, i32 %30)
br label %32
32: ; preds = %25
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %36
36: ; preds = %33, %20
%37 = load i64, i64* %6
%38 = call i64 @memcmp(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%43 = load i64, i64* %6
%44 = load i32, i32* @stderr
%45 = call i64 @fwrite(i8* %11, i32 1, i64 %43, i32 %44)
store i64 %45, i64* %8
%46 = load i32, i32* @stderr
%47 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %50
50: ; preds = %40, %36
%51 = load i32, i32* %7
%52 = sub nsw i32 0, %51
%53 = load i8*, i8** %4
ret i32 %52
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jmesmon/trifles/refs/heads/master/gkr-decrypt.c\00"
@.str.1 = [15 x i8] c"failed to read\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"magic is %zu bytes and should be %zu bytes.\00"
@.str.3 = [17 x i8] c"GnomeKeyring\0A\0D\00\0A\00"
@.str.4 = [25 x i8] c"expected magic but got \22\00"
@.str.5 = [3 x i8] c"\22\0A\00"
define i32 @check_magic(i32* nocapture %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = call i64 @fread(i8* %3, i32 1, i64 16, i32* %0)
switch i64 %4, label %8 [
i64 0, label %5
i64 16, label %13
]
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @error_at_line(i32 1, i32 %6, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %5, %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i64 %4, i64 16)
%11 = load i32, i32* @stderr
%12 = tail call i32 @putc(i8 signext 10, i32 %11)
br label %13
13: ; preds = %1, %8
%14 = phi i32 [ 1, %8 ], [ 0, %1 ]
%15 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i64 @fwrite(i8* %3, i32 1, i64 %4, i32 %20)
%22 = load i32, i32* @stderr
%23 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i32 %14, 1
br label %25
25: ; preds = %17, %13
%26 = phi i32 [ %24, %17 ], [ %14, %13 ]
%27 = sub nsw i32 0, %26
ret i32 %27
}