#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 fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int strlen(char *);
void DumpEidData(FILE *pFile, int iInputSize, int iEidCount,
                 char *pFilenamePrefix) {
  FILE *pOutput;
  char *szFilename;
  char *szBuf;
  int iRes, iSize;
  printf("dumping EID%d from eEID at %p, size %d (%x)..\n", iEidCount, pFile,
         iInputSize, iInputSize);
  szBuf = (char *)malloc(iInputSize + 1);
  szFilename = (char *)malloc(strlen(pFilenamePrefix) + 2);
  if (szBuf == NULL) {
    perror("malloc");
    exit(1);
  };
  iSize = fread(szBuf, iInputSize, 1, pFile);
  sprintf(szFilename, "%s%d", pFilenamePrefix, iEidCount);
  pOutput = fopen(szFilename, "wb");
  iRes = fwrite(szBuf, iInputSize, 1, pOutput);
  if (iRes != iSize) {
    perror("fwrite");
    exit(1);
  };
  free(szBuf);
}


x86 assembly (clang, -O0):
<DumpEidData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe35(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1217 <DumpEidData+0x77>
lea    0xe27(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xdf5(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     1294 <DumpEidData+0xf4>
lea    0xdb9(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DumpEidData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r13
lea    0xe43(%rip),%rdi
mov    %edx,%esi
mov    %r13,%rdx
mov    %ebx,%ecx
mov    %ebx,%r8d
call   1060 <printf@plt>
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
call   1070 <malloc@plt>
test   %r14,%r14
je     1255 <DumpEidData+0xb5>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    %eax,%r13d
lea    0xe2b(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r12d,%ecx
call   10a0 <sprintf@plt>
lea    0xe1b(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
cmp    %r13d,%eax
jne    125e <DumpEidData+0xbe>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xdd3(%rip),%rdi
jmp    1265 <DumpEidData+0xc5>
lea    0xdd9(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"dumping EID%d from eEID at %p, size %d (%x)..\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [5 x i8] c"%s%d\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [7 x i8] c"fwrite\00"
define void @DumpEidData(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%14 = load i32, i32* %7
%15 = load i32*, i32** %5
%16 = load i32, i32* %6
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %14, i32* %15, i32 %16, i32 %17)
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %11
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 2
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %10
%28 = load i8*, i8** %11
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %4
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %4
%34 = load i8*, i8** %11
%35 = load i32, i32* %6
%36 = load i32*, i32** %5
%37 = call i32 @fread(i8* %34, i32 %35, i32 1, i32* %36)
store i32 %37, i32* %13
%38 = load i8*, i8** %10
%39 = load i8*, i8** %8
%40 = load i32, i32* %7
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %39, i32 %40)
%42 = load i8*, i8** %10
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %43, i32** %9
%44 = load i8*, i8** %11
%45 = load i32, i32* %6
%46 = load i32*, i32** %9
%47 = call i32 @fwrite(i8* %44, i32 %45, i32 1, i32* %46)
store i32 %47, i32* %12
%48 = load i32, i32* %12
%49 = load i32, i32* %13
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %33
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %33
%55 = load i8*, i8** %11
%56 = call i32 @free(i8* %55)
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"dumping EID%d from eEID at %p, size %d (%x)..\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [5 x i8] c"%s%d\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [7 x i8] c"fwrite\00"
define void @DumpEidData(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %2, i32* %0, i32 %1, i32 %1)
%6 = add nsw i32 %1, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strlen(i8* %3)
%10 = add nsw i32 %9, 2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %7, 0
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %4
%18 = tail call i32 @fread(i8* %8, i32 %1, i32 1, i32* %0)
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 %2)
%20 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @fwrite(i8* %8, i32 %1, i32 1, i32* %20)
%22 = icmp eq i32 %21, %18
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = tail call i32 @free(i8* %8)
ret void
}