#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*/ asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ perror(char *);
unsigned int scan_file(const char *prefix, const char *reg) {
  unsigned int ret;
  char *file;
  FILE *fp;
  asprintf(&file, "%s%s", prefix, reg);
  fp = fopen(file, "r");
  if (!fp) {
    perror(file);
    return 0;
  }
  fscanf(fp, "%x", &ret);
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<scan_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <asprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ac <scan_file+0x5c>
mov    -0x28(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cf <scan_file+0x7f>
mov    -0x30(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_file>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe9e(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <asprintf@plt>
mov    0x8(%rsp),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ab <scan_file+0x5b>
mov    %rax,%rbx
lea    0xe7b(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    11a5 <scan_file+0x55>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
define i32 @scan_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @perror(i8* %12)
br label %18
14: ; preds = %2
%15 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = call i32 @fclose(i32* %9)
%17 = load i32, i32* %3
br label %18
18: ; preds = %14, %11
%19 = phi i32 [ %17, %14 ], [ 0, %11 ]
ret i32 %19
}