#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 */
char *ReadFile(char const *, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char const *, scalar_t__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ strlen(char const *);
char const *strrchr(char const *, char);
void DumpData(const char *infn, const char *outfn, int skip) {
  FILE *f;
  int i;
  int insize;
  char symname[9];
  const char *in;
  const char *infn_stripped = strrchr(infn, '/');
  if (strrchr(infn, '\\') > infn_stripped)
    infn_stripped = strrchr(infn, '\\');
  if (infn_stripped == NULL)
    infn_stripped = infn;
  else
    ++infn_stripped;
  f = fopen(outfn, "wb");
  memset(symname, 0, 9);
  memcpy(symname, infn_stripped, strlen(infn_stripped) - 4);
  fprintf(f, "char far %s[] ={\r\n", symname);
  in = ReadFile(infn, &insize);
  for (i = skip; i < insize; ++i) {
    fprintf(f, "%d", (unsigned char)in[i]);
    if (i != insize - 1)
      fprintf(f, ",\r\n");
  }
  fprintf(f, " };\r\n");
  fclose(f);
  free((char *)in);
}


x86 assembly (clang, -O0):
<DumpData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1070 <strrchr@plt>
cmp    -0x48(%rbp),%rax
jbe    11df <DumpData+0x4f>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11f7 <DumpData+0x67>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1203 <DumpData+0x73>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x31(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1080 <memset@plt>
lea    -0x31(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
sub    $0x4,%rdx
call   10a0 <memcpy@plt>
mov    -0x20(%rbp),%rdi
lea    -0x31(%rbp),%rdx
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <ReadFile@plt>
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12e1 <DumpData+0x151>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     12ce <DumpData+0x13e>
mov    -0x20(%rbp),%rdi
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12d3 <DumpData+0x143>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1281 <DumpData+0xf1>
mov    -0x20(%rbp),%rdi
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DumpData>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x5c,%esi
call   1070 <strrchr@plt>
cmp    %rbx,%rax
cmova  %rax,%rbx
lea    0x1(%rbx),%rbp
test   %rbx,%rbx
cmove  %r12,%rbp
lea    0xe18(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0x7(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    -0x4(%rax),%rdx
mov    %r15,%rdi
mov    %rbp,%rsi
call   10a0 <memcpy@plt>
lea    0xdde(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rsp,%rsi
mov    %r12,%rdi
call   1050 <ReadFile@plt>
mov    %rax,%r12
cmp    %r14d,(%rsp)
jle    12a1 <DumpData+0x101>
movslq %r14d,%rbp
lea    0xdc6(%rip),%r14
lea    0xdc2(%rip),%r15
jmp    126b <DumpData+0xcb>
nopl   0x0(%rax)
add    $0x1,%rbp
cltq
cmp    %rax,%rbp
jge    12a1 <DumpData+0x101>
movzbl (%r12,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    %ecx,%ebp
je     1260 <DumpData+0xc0>
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    (%rsp),%eax
jmp    1260 <DumpData+0xc0>
lea    0xd75(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [19 x i8] c"char far %s[] ={\0D\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c",\0D\0A\00"
@.str.4 = [6 x i8] c" };\0D\0A\00"
define void @DumpData(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [9 x i8]
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%13 = load i8*, i8** %4
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8* %14, i8** %12
%15 = load i8*, i8** %4
%16 = call i8* @strrchr(i8* %15, i8 signext 92)
%17 = load i8*, i8** %12
%18 = icmp ugt i8* %16, %17
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = call i8* @strrchr(i8* %20, i8 signext 92)
store i8* %21, i8** %12
br label %22
22: ; preds = %19, %3
%23 = load i8*, i8** %12
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i8*, i8** %4
store i8* %26, i8** %12
br label %30
27: ; preds = %22
%28 = load i8*, i8** %12
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %12
br label %30
30: ; preds = %27, %25
%31 = load i8*, i8** %5
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %7
%33 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 9)
%35 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%36 = load i8*, i8** %12
%37 = load i8*, i8** %12
%38 = call i64 @strlen(i8* %37)
%39 = sub nsw i64 %38, 4
%40 = call i32 @memcpy(i8* %35, i8* %36, i64 %39)
%41 = load i32*, i32** %7
%42 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %4
%45 = call i8* @ReadFile(i8* %44, i32* %9)
store i8* %45, i8** %11
%46 = load i32, i32* %6
store i32 %46, i32* %8
br label %47
47: ; preds = %68, %30
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %71
51: ; preds = %47
%52 = load i32*, i32** %7
%53 = load i8*, i8** %11
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %8
%61 = load i32, i32* %9
%62 = sub nsw i32 %61, 1
%63 = icmp ne i32 %60, %62
br i1 %63, label %64, label %67
64: ; preds = %51
%65 = load i32*, i32** %7
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %67
67: ; preds = %64, %51
br label %68
68: ; preds = %67
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %47
71: ; preds = %47
%72 = load i32*, i32** %7
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
%76 = load i8*, i8** %11
%77 = call i32 @free(i8* %76)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [19 x i8] c"char far %s[] ={\0D\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c",\0D\0A\00"
@.str.4 = [6 x i8] c" };\0D\0A\00"
define void @DumpData(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = alloca [9 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%10 = icmp ugt i8* %9, %8
%11 = select i1 %10, i8* %9, i8* %8
%12 = icmp eq i8* %11, null
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = select i1 %12, i8* %0, i8* %13
%15 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @memset(i8* %7, i32 0, i32 9)
%17 = call i64 @strlen(i8* dereferenceable(1) %14)
%18 = add nsw i64 %17, -4
%19 = call i32 @memcpy(i8* %7, i8* %14, i64 %18)
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%21 = call i8* @ReadFile(i8* %0, i32* %4)
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, %2
br i1 %23, label %24, label %44
24: ; preds = %3
%25 = sext i32 %2 to i64
br label %26
26: ; preds = %24, %39
%27 = phi i64 [ %25, %24 ], [ %41, %39 ]
%28 = getelementptr inbounds i8, i8* %21, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
%34 = trunc i64 %27 to i32
%35 = icmp eq i32 %33, %34
br i1 %35, label %39, label %36
36: ; preds = %26
%37 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %15)
%38 = load i32, i32* %4
br label %39
39: ; preds = %26, %36
%40 = phi i32 [ %32, %26 ], [ %38, %36 ]
%41 = add nsw i64 %27, 1
%42 = sext i32 %40 to i64
%43 = icmp slt i64 %41, %42
br i1 %43, label %26, label %44
44: ; preds = %39, %3
%45 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 5, i64 1, i32* %15)
%46 = call i32 @fclose(i32* %15)
%47 = call i32 @free(i8* %21)
ret void
}