#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *serialread(const char *keyfile) {
  FILE *fp;
  unsigned char *snx;
  fp = fopen(keyfile, "rb");
  if (fp) {
    snx = (unsigned char *)calloc(64, sizeof(unsigned char));
    if (snx) {
      fread(snx, sizeof(unsigned char), 64, fp);
    }
    fclose(fp);
    return snx;
  } else
    return NULL;
}


x86 assembly (clang, -O0):
<serialread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b6 <serialread+0x76>
mov    $0x40,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <serialread+0x60>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11be <serialread+0x7e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialread>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118e <serialread+0x4e>
mov    %rax,%r14
mov    $0x40,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1184 <serialread+0x44>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1190 <serialread+0x50>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i8* @serialread(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %23
10: ; preds = %1
%11 = call i64 @calloc(i32 64, i32 1)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32*, i32** %4
%18 = call i32 @fread(i8* %16, i32 1, i32 64, i32* %17)
br label %19
19: ; preds = %15, %10
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %5
store i8* %22, i8** %2
br label %24
23: ; preds = %1
store i8* null, i8** %2
br label %24
24: ; preds = %23, %19
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i8* @serialread(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i64 @calloc(i32 64, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @fread(i8* %6, i32 1, i32 64, i32* %2)
br label %10
10: ; preds = %8, %4
%11 = tail call i32 @fclose(i32* %2)
br label %12
12: ; preds = %1, %10
%13 = phi i8* [ %6, %10 ], [ null, %1 ]
ret i8* %13
}