#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
char *strrchr(char *, char);
void mkdata(char *name) {
  FILE *fd;
  int c, len;
  char *basename;
  fd = fopen(name, "r");
  if (!fd) {
    perror(name);
    exit(-1);
  }
  basename = strrchr(name, '/');
  if (basename)
    ++basename;
  else
    basename = name;
  name = strchr(basename, '.');
  if (name)
    *name = 0;
  printf("static const char %s_data[] = {\n\t", basename);
  len = 0;
  for (;;) {
    c = getc(fd);
    if (c < 0)
      break;
    printf("%d,", c);
    len += 2;
    if (c > 9)
      ++len;
    if (c > 99)
      ++len;
    if (len > 66) {
      printf("\n\t");
      len = 0;
    }
  }
  if (len > 0)
    printf("\n");
  printf("};\n");
}


x86 assembly (clang, -O0):
<mkdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <mkdata+0x3e>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11dc <mkdata+0x6c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e4 <mkdata+0x74>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1208 <mkdata+0x98>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123c <mkdata+0xcc>
jmp    12a0 <mkdata+0x130>
mov    -0x14(%rbp),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x9,-0x14(%rbp)
jle    1269 <mkdata+0xf9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x63,-0x14(%rbp)
jle    127c <mkdata+0x10c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x42,-0x18(%rbp)
jle    129b <mkdata+0x12b>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
jmp    1221 <mkdata+0xb1>
cmpl   $0x0,-0x18(%rbp)
jle    12b8 <mkdata+0x148>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdata>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     127e <mkdata+0xee>
mov    %rax,%r12
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
lea    0x1(%rax),%rbp
test   %rax,%rax
cmove  %r14,%rbp
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e0 <mkdata+0x50>
movb   $0x0,(%rax)
lea    0xe1b(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   10b0 <getc@plt>
test   %eax,%eax
js     126a <mkdata+0xda>
mov    %eax,%ebp
lea    0xe1e(%rip),%r14
lea    0xe14(%rip),%r15
xor    %ebx,%ebx
jmp    122e <mkdata+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
test   %eax,%eax
js     125c <mkdata+0xcc>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0xa,%ebp
sbb    $0xffffffff,%ebx
cmp    $0x64,%ebp
sbb    $0xffffffff,%ebx
add    $0x2,%ebx
cmp    $0x43,%ebx
jl     1220 <mkdata+0x90>
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1220 <mkdata+0x90>
test   %ebx,%ebx
jle    126a <mkdata+0xda>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdb7(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    %r14,%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [34 x i8] c"static const char %s_data[] = {\0A\09\00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [3 x i8] c"\0A\09\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"};\0A\00"
define void @mkdata(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
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 = icmp ne i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 @perror(i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i8* @strrchr(i8* %16, i8 signext 47)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %6
br label %25
23: ; preds = %15
%24 = load i8*, i8** %2
store i8* %24, i8** %6
br label %25
25: ; preds = %23, %20
%26 = load i8*, i8** %6
%27 = call i8* @strchr(i8* %26, i8 signext 46)
store i8* %27, i8** %2
%28 = load i8*, i8** %2
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i8*, i8** %2
store i8 0, i8* %31
br label %32
32: ; preds = %30, %25
%33 = load i8*, i8** %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 0, i32* %5
br label %35
35: ; preds = %62, %32
%36 = load i32*, i32** %3
%37 = call i32 @getc(i32* %36)
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %63
41: ; preds = %35
%42 = load i32, i32* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 2
store i32 %45, i32* %5
%46 = load i32, i32* %4
%47 = icmp sgt i32 %46, 9
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %51
51: ; preds = %48, %41
%52 = load i32, i32* %4
%53 = icmp sgt i32 %52, 99
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %57
57: ; preds = %54, %51
%58 = load i32, i32* %5
%59 = icmp sgt i32 %58, 66
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %62
62: ; preds = %60, %57
br label %35
63: ; preds = %40
%64 = load i32, i32* %5
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [34 x i8] c"static const char %s_data[] = {\0A\09\00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [3 x i8] c"\0A\09\00"
@str = [3 x i8] c"};\00"
define void @mkdata(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @perror(i8* %0)
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %1
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%9 = icmp eq i8* %8, null
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = select i1 %9, i8* %0, i8* %10
%12 = tail call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %7
store i8 0, i8* %12
br label %15
15: ; preds = %14, %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%17 = tail call i32 @getc(i32* %2)
%18 = icmp slt i32 %17, 0
br i1 %18, label %40, label %19
19: ; preds = %15, %32
%20 = phi i32 [ %34, %32 ], [ %17, %15 ]
%21 = phi i32 [ %33, %32 ], [ 0, %15 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%23 = icmp ugt i32 %20, 9
%24 = select i1 %23, i32 3, i32 2
%25 = add nsw i32 %24, %21
%26 = icmp ugt i32 %20, 99
%27 = zext i1 %26 to i32
%28 = add nsw i32 %25, %27
%29 = icmp sgt i32 %28, 66
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %19
%33 = phi i32 [ 0, %30 ], [ %28, %19 ]
%34 = tail call i32 @getc(i32* %2)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %19
36: ; preds = %32
%37 = icmp sgt i32 %33, 0
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = tail call i32 @putchar(i32 10)
br label %40
40: ; preds = %15, %38, %36
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret void
}