#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 % 10) == 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    $0xa,%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    12d0 <main+0x140>
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     12f6 <main+0x166>
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    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    12de <main+0x14e>
mov    $0xcccccccd,%r14d
lea    0xe06(%rip),%rbp
lea    0xea8(%rip),%r12
lea    0xe00(%rip),%r13
xor    %r15d,%r15d
jmp    1286 <main+0xf6>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <puts@plt>
add    $0x1,%r15
movslq 0x4(%rsp),%rax
cmp    %rax,%r15
jge    12de <main+0x14e>
mov    %r15d,%eax
imul   %r14,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
cmp    %eax,%r15d
jne    12a9 <main+0x119>
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movzbl (%rbx,%r15,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    %rax,%r15
je     1270 <main+0xe0>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1278 <main+0xe8>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
jmp    12f2 <main+0x162>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1315 <main+0x185>
mov    0x8(%r14),%rsi
lea    0xd05(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%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, 10
%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 %62
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 %62
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 %59
34: ; preds = %23, %54
%35 = phi i64 [ %55, %54 ], [ 0, %23 ]
%36 = trunc i64 %35 to i32
%37 = urem i32 %36, 10
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = getelementptr inbounds i8, i8* %13, i64 %35
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %3
%47 = add nsw i32 %46, -1
%48 = zext i32 %47 to i64
%49 = icmp eq i64 %35, %48
br i1 %49, label %52, label %50
50: ; preds = %41
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %54
52: ; preds = %41
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.14, i64 0, i64 0))
br label %54
54: ; preds = %50, %52
%55 = add nuw nsw i64 %35, 1
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %55, %57
br i1 %58, label %34, label %59
59: ; preds = %54, %23
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0))
%61 = call i32 @free(i8* %13)
br label %62
62: ; preds = %59, %19, %6
%63 = phi i32 [ 0, %6 ], [ 0, %59 ], [ 1, %19 ]
ret i32 %63
}