#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void process_file(char *path, char *url) {
  static char buf[4096];
  FILE *file = fopen(path, "rb");
  if (!file) {
    fprintf(stderr, "error processing file '%s'", path);
    perror(NULL);
    exit(1);
  }
  fseek(file, 0, SEEK_END);
  int length = ftell(file);
  fseek(file, 0, SEEK_SET);
  printf("  { .url = \"%s\", .length = %d, .data = \"", url, length);
  int len;
  while ((len = fread(buf, 1, sizeof(buf), file)) > 0) {
    char *p;
    for (p = buf; len; len--, p++)
      printf("\\x%02hhx", *p);
  }
  printf("\" },\n");
  fclose(file);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11eb <process_file+0x5b>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe30(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rcx
lea    0x2e41(%rip),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    12a3 <process_file+0x113>
lea    0x2e1f(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     129e <process_file+0x10e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1265 <process_file+0xd5>
jmp    1234 <process_file+0xa4>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1290 <process_file+0xf0>
mov    %rax,%r14
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %eax,%ebp
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0xe21(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x2e70(%rip),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1274 <process_file+0xd4>
mov    %eax,%ebp
lea    0xe15(%rip),%r12
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
jne    1240 <process_file+0xa0>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %r15,%rbx
test   %eax,%eax
jg     1240 <process_file+0xa0>
lea    0xdd5(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
mov    %rbp,%rdx
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@process_file.buf = internal global [4096 x i8] zeroinitializer
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"error processing file '%s'\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [41 x i8] c" { .url = \22%s\22, .length = %d, .data = \22\00"
@.str.3 = [9 x i8] c"\\x%02hhx\00"
@.str.4 = [6 x i8] c"\22 },\0A\00"
define void @process_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @perror(i32* null)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32*, i32** %5
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i32*, i32** %5
%24 = call i32 @ftell(i32* %23)
store i32 %24, i32* %6
%25 = load i32*, i32** %5
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i8*, i8** %4
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %29)
br label %31
31: ; preds = %49, %19
%32 = load i32*, i32** %5
%33 = call i32 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @process_file.buf, i64 0, i64 0), i32 1, i32 4096, i32* %32)
store i32 %33, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %31
store i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @process_file.buf, i64 0, i64 0), i8** %8
br label %36
36: ; preds = %44, %35
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load i8*, i8** %8
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %39
%45 = load i32, i32* %7
%46 = add nsw i32 %45, -1
store i32 %46, i32* %7
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %8
br label %36
49: ; preds = %36
br label %31
50: ; preds = %31
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%52 = load i32*, i32** %5
%53 = call i32 @fclose(i32* %52)
ret void
}

LLVM IR (-O2):
@process_file.buf = internal global [4096 x i8] zeroinitializer
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"error processing file '%s'\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [41 x i8] c" { .url = \22%s\22, .length = %d, .data = \22\00"
@.str.3 = [9 x i8] c"\\x%02hhx\00"
@str = [5 x i8] c"\22 },\00"
define void @process_file(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 @perror(i32* null)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %3, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %3)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %3, i32 0, i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %13)
%17 = tail call i32 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @process_file.buf, i64 0, i64 0), i32 1, i32 4096, i32* %3)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %22, label %34
19: ; preds = %22
%20 = tail call i32 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @process_file.buf, i64 0, i64 0), i32 1, i32 4096, i32* %3)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %31, label %34
22: ; preds = %10, %31
%23 = phi i8* [ %32, %31 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @process_file.buf, i64 0, i64 0), %10 ]
%24 = phi i32 [ %33, %31 ], [ %17, %10 ]
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = add nsw i32 %24, -1
%29 = getelementptr inbounds i8, i8* %23, i64 1
%30 = icmp eq i32 %28, 0
br i1 %30, label %19, label %31
31: ; preds = %22, %19
%32 = phi i8* [ %29, %22 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @process_file.buf, i64 0, i64 0), %19 ]
%33 = phi i32 [ %28, %22 ], [ %20, %19 ]
br label %22
34: ; preds = %19, %10
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%36 = tail call i32 @fclose(i32* %3)
ret void
}