#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*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int load_key(unsigned int *crt, const char *filename) {
  FILE *key;
  size_t idx;
  if (access(filename, R_OK) != 0)
    return errno;
  if (crt == NULL)
    return -1;
  key = fopen(filename, "r");
  idx = 0;
  while (idx < 5) {
    char tmp;
    if (fscanf(key, "%c", &tmp) != 1)
      return -2;
    crt[idx++] = (unsigned int)tmp & 0xff;
  }
  return 0;
}


x86 assembly (clang, -O0):
<load_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
je     116d <load_key+0x3d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <load_key+0xd0>
cmpq   $0x0,-0x10(%rbp)
jne    1184 <load_key+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <load_key+0xd0>
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
jae    11f9 <load_key+0xc9>
mov    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
lea    -0x29(%rbp),%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     11d4 <load_key+0xa4>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1200 <load_key+0xd0>
movsbl -0x29(%rbp),%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %edx,(%rax,%rcx,4)
jmp    11a0 <load_key+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_key>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
je     1163 <load_key+0x33>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
jmp    123b <load_key+0x10b>
test   %r15,%r15
je     1236 <load_key+0x106>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r14
lea    0xe7d(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rax,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    122f <load_key+0xff>
movzbl 0xf(%rsp),%eax
mov    %eax,(%r15)
lea    0xe58(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %r14,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    122f <load_key+0xff>
movzbl 0xf(%rsp),%eax
mov    %eax,0x4(%r15)
lea    0xe36(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %r14,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    122f <load_key+0xff>
movzbl 0xf(%rsp),%eax
mov    %eax,0x8(%r15)
lea    0xe14(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %r14,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    122f <load_key+0xff>
movzbl 0xf(%rsp),%eax
mov    %eax,0xc(%r15)
lea    0xdf2(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %r14,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    122f <load_key+0xff>
movzbl 0xf(%rsp),%eax
mov    %eax,0x10(%r15)
xor    %eax,%eax
jmp    123b <load_key+0x10b>
mov    $0xfffffffe,%eax
jmp    123b <load_key+0x10b>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@R_OK = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @load_key(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8
store i32* %0, i32** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i32, i32* @R_OK
%11 = call i64 @access(i8* %9, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* @errno
store i32 %14, i32* %3
br label %39
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %3
br label %39
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
store i64 0, i64* %7
br label %22
22: ; preds = %30, %19
%23 = load i64, i64* %7
%24 = icmp ult i64 %23, 5
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i32*, i32** %6
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -2, i32* %3
br label %39
30: ; preds = %25
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = and i32 %32, 255
%34 = load i32*, i32** %4
%35 = load i64, i64* %7
%36 = add i64 %35, 1
store i64 %36, i64* %7
%37 = getelementptr inbounds i32, i32* %34, i64 %35
store i32 %33, i32* %37
br label %22
38: ; preds = %22
store i32 0, i32* %3
br label %39
39: ; preds = %38, %29, %18, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@R_OK = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @load_key(i32* writeonly %0, i8* nocapture %1) {
%3 = alloca i8
%4 = load i32, i32* @R_OK
%5 = tail call i64 @access(i8* %1, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = load i32, i32* @errno
br label %43
9: ; preds = %2
%10 = icmp eq i32* %0, null
br i1 %10, label %43, label %11
11: ; preds = %9
%12 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%14 = icmp eq i32 %13, 1
br i1 %14, label %16, label %15
15: ; preds = %33, %27, %21, %16, %11
br label %43
16: ; preds = %11
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
store i32 %18, i32* %0
%19 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %15
21: ; preds = %16
%22 = load i8, i8* %3
%23 = zext i8 %22 to i32
%24 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %23, i32* %24
%25 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %15
27: ; preds = %21
%28 = load i8, i8* %3
%29 = zext i8 %28 to i32
%30 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %29, i32* %30
%31 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %15
33: ; preds = %27
%34 = load i8, i8* %3
%35 = zext i8 %34 to i32
%36 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %35, i32* %36
%37 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %15
39: ; preds = %33
%40 = load i8, i8* %3
%41 = zext i8 %40 to i32
%42 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %41, i32* %42
br label %43
43: ; preds = %39, %15, %9, %7
%44 = phi i32 [ %8, %7 ], [ -1, %9 ], [ -2, %15 ], [ 0, %39 ]
ret i32 %44
}