#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 */
struct link_list {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
struct link_list *decrypt_rsdf(char *, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ free_link_list(struct link_list *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ print_link_list(struct link_list *, char *);
void rsdf_demo(const char *file) {
  FILE *fp = fopen(file, "r");
  fseek(fp, 0, SEEK_END);
  size_t len = ftell(fp);
  char *data = malloc(len);
  fseek(fp, 0, SEEK_SET);
  fread(data, 1, len, fp);
  fclose(fp);
  struct link_list *links = decrypt_rsdf(data, len);
  free(data);
  print_link_list(links, "");
  free_link_list(links);
}


x86 assembly (clang, -O0):
<rsdf_demo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <decrypt_rsdf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1060 <print_link_list@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <free_link_list@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsdf_demo>:
push   %r15
push   %r14
push   %rbx
lea    0xe54(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <decrypt_rsdf@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdi
call   1060 <print_link_list@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    10c0 <free_link_list@plt>

LLVM IR (-O0):
%struct.link_list = type { i32 }
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define void @rsdf_demo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca %struct.link_list*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %3
%13 = call i64 @ftell(i32* %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %5
%16 = load i32*, i32** %3
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i8*, i8** %5
%20 = load i64, i64* %4
%21 = load i32*, i32** %3
%22 = call i32 @fread(i8* %19, i32 1, i64 %20, i32* %21)
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %5
%26 = load i64, i64* %4
%27 = call %struct.link_list* @decrypt_rsdf(i8* %25, i64 %26)
store %struct.link_list* %27, %struct.link_list** %6
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = load %struct.link_list*, %struct.link_list** %6
%31 = call i32 @print_link_list(%struct.link_list* %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%32 = load %struct.link_list*, %struct.link_list** %6
%33 = call i32 @free_link_list(%struct.link_list* %32)
ret void
}

LLVM IR (-O2):
%struct.link_list = type { i32 }
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define void @rsdf_demo(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @SEEK_END
%4 = tail call i32 @fseek(i32* %2, i32 0, i32 %3)
%5 = tail call i64 @ftell(i32* %2)
%6 = tail call i8* @malloc(i64 %5)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %2, i32 0, i32 %7)
%9 = tail call i32 @fread(i8* %6, i32 1, i64 %5, i32* %2)
%10 = tail call i32 @fclose(i32* %2)
%11 = tail call %struct.link_list* @decrypt_rsdf(i8* %6, i64 %5)
%12 = tail call i32 @free(i8* %6)
%13 = tail call i32 @print_link_list(%struct.link_list* %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @free_link_list(%struct.link_list* %11)
ret void
}