#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 EOF;
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *strchr(char *, char);
void visit(char *fname) {
  FILE *f;
  char buf[512], *ptr;
  int ch, x = 0;
  f = fopen(fname, "rb");
  if (!f)
    err(1, "%s", fname);
  snprintf(buf, sizeof(buf), "%s", fname);
  ptr = buf;
  while (strchr(ptr, '/')) {
    ptr = strchr(ptr, '/') + 1;
  }
  if (strchr(ptr, '.')) {
    *strchr(ptr, '.') = 0;
  }
  printf("uint8_t data_%s[] = {", ptr);
  while ((ch = fgetc(f)) != EOF) {
    if (x == 0) {
      printf("\n\t");
    } else {
      printf(" ");
    }
    printf("0x%02x,", ch);
    x = (x + 1) % 8;
  }
  printf("\n};\n");
  fclose(f);
}


x86 assembly (clang, -O0):
<visit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x220(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <visit+0x4d>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe4b(%rip),%rsi
call   1080 <err@plt>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
lea    0xe2f(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1223 <visit+0xb3>
mov    -0x218(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
jmp    11e7 <visit+0x77>
mov    -0x218(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1252 <visit+0xe2>
mov    -0x218(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x21c(%rbp)
mov    0x2d6b(%rip),%rcx
cmp    (%rcx),%eax
je     12e3 <visit+0x173>
cmpl   $0x0,-0x220(%rbp)
jne    12a5 <visit+0x135>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b3 <visit+0x143>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x21c(%rbp),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x220(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x220(%rbp)
jmp    1267 <visit+0xf7>
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<visit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rbx
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11cc <visit+0x3c>
lea    0xe44(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
call   10a0 <err@plt>
mov    %rsp,%rbp
lea    0xe2d(%rip),%rdx
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rcx
call   1080 <snprintf@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rbx
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%rbp
test   %rax,%rax
jne    11f0 <visit+0x60>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     121e <visit+0x8e>
movb   $0x0,(%rax)
lea    0xde1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    0x2daa(%rip),%r13
cmp    0x0(%r13),%eax
jne    126a <visit+0xda>
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xda9(%rip),%r14
lea    0xda5(%rip),%r15
xor    %ebx,%ebx
jmp    12bb <visit+0x12b>
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x1(%rbx),%eax
lea    0x8(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
neg    %ecx
add    %ecx,%ebx
add    $0x1,%ebx
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     1244 <visit+0xb4>
test   %ebx,%ebx
jne    1280 <visit+0xf0>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    128a <visit+0xfa>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"uint8_t data_%s[] = {\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c"\0A\09\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [8 x i8] c"0x%02x,\00"
@.str.6 = [5 x i8] c"\0A};\0A\00"
define void @visit(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [512 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %1
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%17 = load i8*, i8** %2
%18 = call i32 @snprintf(i8* %16, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8* %19, i8** %5
br label %20
20: ; preds = %24, %15
%21 = load i8*, i8** %5
%22 = call i8* @strchr(i8* %21, i8 signext 47)
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = call i8* @strchr(i8* %25, i8 signext 47)
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %5
br label %20
28: ; preds = %20
%29 = load i8*, i8** %5
%30 = call i8* @strchr(i8* %29, i8 signext 46)
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %5
%34 = call i8* @strchr(i8* %33, i8 signext 46)
store i8 0, i8* %34
br label %35
35: ; preds = %32, %28
%36 = load i8*, i8** %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %50, %35
%39 = load i32*, i32** %3
%40 = call i32 @fgetc(i32* %39)
store i32 %40, i32* %6
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %56
43: ; preds = %38
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %50
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
%55 = srem i32 %54, 8
store i32 %55, i32* %7
br label %38
56: ; preds = %38
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%58 = load i32*, i32** %3
%59 = call i32 @fclose(i32* %58)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"uint8_t data_%s[] = {\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c"\0A\09\00"
@.str.5 = [8 x i8] c"0x%02x,\00"
@str = [4 x i8] c"\0A};\00"
define void @visit(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
%9 = call i32 @snprintf(i8* %3, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %10, %8
%11 = phi i8* [ %3, %8 ], [ %14, %10 ]
%12 = call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 47)
%13 = icmp eq i8* %12, null
%14 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %13, label %15, label %10
15: ; preds = %10
%16 = call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 46)
%17 = icmp eq i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15
store i8 0, i8* %16
br label %19
19: ; preds = %18, %15
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%21 = call i32 @fgetc(i32* %4)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %39, label %24
24: ; preds = %19, %32
%25 = phi i32 [ %36, %32 ], [ %21, %19 ]
%26 = phi i32 [ %35, %32 ], [ 0, %19 ]
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %32
30: ; preds = %24
%31 = call i32 @putchar(i32 32)
br label %32
32: ; preds = %30, %28
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%34 = add nsw i32 %26, 1
%35 = srem i32 %34, 8
%36 = call i32 @fgetc(i32* %4)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %24
39: ; preds = %32, %19
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%41 = call i32 @fclose(i32* %4)
ret void
}