#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  FILE *f;
  unsigned char *buffer;
  int i, size;
  if (argc != 3) {
    printf("Usage: make_array <input file> <size>\n");
    return 0;
  }
  sscanf(argv[2], "%d", &size);
  buffer = malloc(size);
  memset(buffer, 0xAA, size);
  f = fopen(argv[1], "rb");
  if (!f) {
    printf("Can't open file %s.\n", argv[1]);
    free(buffer);
    return 1;
  }
  fread((char *)buffer, 1, size, f);
  fclose(f);
  printf("library ieee;\nuse ieee.std_logic_1164.all;\n\npackage sd_rom_pkg "
         "is\n\n");
  printf("    type t_sdrom_array is array (natural range <>) of "
         "std_logic_vector(7 downto 0);\n\n");
  printf("    constant sdrom_array : t_sdrom_array(0 to %d) := (", size - 1);
  for (i = 0; i < size; i++) {
    if ((i % 16) == 0)
      printf("\n        ");
    printf("X\"%02X\"", buffer[i]);
    if (i != (size - 1))
      printf(", ");
    else
      printf(" );\n");
  }
  printf("\nend;\n");
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ba <main+0x3a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133d <main+0x1bd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1090 <sscanf@plt>
mov    -0x28(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    $0xaa,%esi
call   1070 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    133d <main+0x1bd>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%esi
sub    $0x1,%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    131f <main+0x19f>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12c0 <main+0x140>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     12fe <main+0x17e>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    130c <main+0x18c>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1311 <main+0x191>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1292 <main+0x112>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    12c1 <main+0x131>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
lea    0xe4e(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10a0 <sscanf@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xaa,%esi
mov    %ebp,%edx
call   1080 <memset@plt>
mov    0x8(%r14),%rdi
lea    0xe1f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12e8 <main+0x158>
mov    %rax,%rbp
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%esi
add    $0xffffffff,%esi
lea    0xde4(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    12d2 <main+0x142>
lea    0xe09(%rip),%rbp
lea    0xeab(%rip),%r12
lea    0xe03(%rip),%r13
xor    %r14d,%r14d
jmp    1286 <main+0xf6>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <puts@plt>
add    $0x1,%r14
movslq 0x4(%rsp),%rax
cmp    %rax,%r14
jge    12d2 <main+0x142>
test   $0xf,%r14b
jne    129a <main+0x10a>
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movzbl (%rbx,%r14,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    %rax,%r14
je     1270 <main+0xe0>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1278 <main+0xe8>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
xor    %r15d,%r15d
jmp    1308 <main+0x178>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1308 <main+0x178>
mov    0x8(%r14),%rsi
lea    0xd13(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: make_array <input file> <size>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [21 x i8] c"Can't open file %s.\0A\00"
@.str.4 = [68 x i8] c"library ieee;\0Ause ieee.std_logic_1164.all;\0A\0Apackage sd_rom_pkg is\0A\0A\00"
@.str.5 = [86 x i8] c" type t_sdrom_array is array (natural range <>) of std_logic_vector(7 downto 0);\0A\0A\00"
@.str.6 = [55 x i8] c" constant sdrom_array : t_sdrom_array(0 to %d) := (\00"
@.str.7 = [10 x i8] c"\0A \00"
@.str.8 = [8 x i8] c"X\22%02X\22\00"
@.str.9 = [3 x i8] c", \00"
@.str.10 = [5 x i8] c" );\0A\00"
@.str.11 = [7 x i8] c"\0Aend;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %83
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%19 = load i32, i32* %9
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i32, i32* %9
%23 = call i32 @memset(i8* %21, i32 170, i32 %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %37, label %30
30: ; preds = %14
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %7
%36 = call i32 @free(i8* %35)
store i32 1, i32* %3
br label %83
37: ; preds = %14
%38 = load i8*, i8** %7
%39 = load i32, i32* %9
%40 = load i32*, i32** %6
%41 = call i32 @fread(i8* %38, i32 1, i32 %39, i32* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* %9
%47 = sub nsw i32 %46, 1
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %47)
store i32 0, i32* %8
br label %49
49: ; preds = %76, %37
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %79
53: ; preds = %49
%54 = load i32, i32* %8
%55 = srem i32 %54, 16
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i8*, i8** %7
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %8
%68 = load i32, i32* %9
%69 = sub nsw i32 %68, 1
%70 = icmp ne i32 %67, %69
br i1 %70, label %71, label %73
71: ; preds = %59
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %75
73: ; preds = %59
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %75
75: ; preds = %73, %71
br label %76
76: ; preds = %75
%77 = load i32, i32* %8
%78 = add nsw i32 %77, 1
store i32 %78, i32* %8
br label %49
79: ; preds = %49
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%81 = load i8*, i8** %7
%82 = call i32 @free(i8* %81)
store i32 0, i32* %3
br label %83
83: ; preds = %79, %30, %12
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [21 x i8] c"Can't open file %s.\0A\00"
@.str.6 = [55 x i8] c" constant sdrom_array : t_sdrom_array(0 to %d) := (\00"
@.str.7 = [10 x i8] c"\0A \00"
@.str.8 = [8 x i8] c"X\22%02X\22\00"
@.str.9 = [3 x i8] c", \00"
@str = [67 x i8] c"library ieee;\0Ause ieee.std_logic_1164.all;\0A\0Apackage sd_rom_pkg is\0A\00"
@str.12 = [85 x i8] c" type t_sdrom_array is array (natural range <>) of std_logic_vector(7 downto 0);\0A\00"
@str.13 = [6 x i8] c"\0Aend;\00"
@str.14 = [4 x i8] c" );\00"
@str.15 = [38 x i8] c"Usage: make_array <input file> <size>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.15, i64 0, i64 0))
br label %61
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = call i8* @malloc(i32 %12)
%14 = call i32 @memset(i8* %13, i32 170, i32 %12)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %8
%20 = load i8*, i8** %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = call i32 @free(i8* %13)
br label %61
23: ; preds = %8
%24 = load i32, i32* %3
%25 = call i32 @fread(i8* %13, i32 1, i32 %24, i32* %17)
%26 = call i32 @fclose(i32* %17)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.12, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = add nsw i32 %29, -1
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %58
34: ; preds = %23, %53
%35 = phi i64 [ %54, %53 ], [ 0, %23 ]
%36 = and i64 %35, 15
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = getelementptr inbounds i8, i8* %13, i64 %35
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %3
%46 = add nsw i32 %45, -1
%47 = zext i32 %46 to i64
%48 = icmp eq i64 %35, %47
br i1 %48, label %51, label %49
49: ; preds = %40
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %53
51: ; preds = %40
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.14, i64 0, i64 0))
br label %53
53: ; preds = %49, %51
%54 = add nuw nsw i64 %35, 1
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = icmp slt i64 %54, %56
br i1 %57, label %34, label %58
58: ; preds = %53, %23
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0))
%60 = call i32 @free(i8* %13)
br label %61
61: ; preds = %58, %19, %6
%62 = phi i32 [ 0, %6 ], [ 0, %58 ], [ 1, %19 ]
ret i32 %62
}