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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
struct package_list *decrypt_ccf(unsigned char *, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ free_package_list(struct package_list *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ print_package_list(struct package_list *);
void ccf_demo(const char *file) {
  FILE *fp = fopen(file, "r");
  fseek(fp, 0, SEEK_END);
  size_t len = ftell(fp);
  unsigned char *data = malloc(len);
  fseek(fp, 0, SEEK_SET);
  fread(data, 1, len, fp);
  fclose(fp);
  struct package_list *packages = decrypt_ccf(data, len);
  free(data);
  print_package_list(packages);
  free_package_list(packages);
}


x86 assembly (clang, -O0):
<ccf_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   10a0 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <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   1070 <decrypt_ccf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <print_package_list@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <free_package_list@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccf_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   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <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   1070 <decrypt_ccf@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <print_package_list@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    10c0 <free_package_list@plt>

LLVM IR (-O0):
%struct.package_list = type { i32 }
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @ccf_demo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca %struct.package_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.package_list* @decrypt_ccf(i8* %25, i64 %26)
store %struct.package_list* %27, %struct.package_list** %6
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = load %struct.package_list*, %struct.package_list** %6
%31 = call i32 @print_package_list(%struct.package_list* %30)
%32 = load %struct.package_list*, %struct.package_list** %6
%33 = call i32 @free_package_list(%struct.package_list* %32)
ret void
}

LLVM IR (-O2):
%struct.package_list = type { i32 }
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @ccf_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.package_list* @decrypt_ccf(i8* %6, i64 %5)
%12 = tail call i32 @free(i8* %6)
%13 = tail call i32 @print_package_list(%struct.package_list* %11)
%14 = tail call i32 @free_package_list(%struct.package_list* %11)
ret void
}