#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, offset;
  if ((argc != 3) && (argc != 4)) {
    printf("Usage: make_mem <input file> <size> [offset]\n");
    return 0;
  }
  sscanf(argv[2], "%d", &size);
  if (argc == 4) {
    sscanf(argv[3], "%d", &offset);
  } else {
    offset = 0;
  }
  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);
  for (i = 0; i < size; i++) {
    if ((i % 16) == 0)
      printf("\n@%04X ", i + offset);
    printf("%02X ", buffer[i]);
  }
  printf("\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     11c4 <main+0x44>
cmpl   $0x4,-0x8(%rbp)
je     11c4 <main+0x44>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1314 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe5b(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1090 <sscanf@plt>
cmpl   $0x4,-0x8(%rbp)
jne    1203 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe39(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    120a <main+0x8a>
movl   $0x0,-0x2c(%rbp)
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    0xdfb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1275 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1314 <main+0x194>
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>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12f6 <main+0x176>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12ce <main+0x14e>
mov    -0x24(%rbp),%esi
add    -0x2c(%rbp),%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    129a <main+0x11a>
lea    0xd4a(%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   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     11c2 <main+0x22>
lea    0xe71(%rip),%rdi
call   1050 <puts@plt>
jmp    12b5 <main+0x115>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
lea    0xe30(%rip),%rsi
mov    %rsp,%rdx
call   10b0 <sscanf@plt>
cmp    $0x4,%ebx
jne    11f4 <main+0x54>
mov    0x18(%r14),%rdi
lea    0xe18(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10b0 <sscanf@plt>
jmp    11fc <main+0x5c>
movl   $0x0,0x4(%rsp)
mov    (%rsp),%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xaa,%esi
mov    %ebp,%edx
call   1090 <memset@plt>
mov    0x8(%r14),%rdi
lea    0xde0(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12b9 <main+0x119>
mov    %rax,%r15
mov    (%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1060 <fread@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
cmpl   $0x0,(%rsp)
jle    12a3 <main+0x103>
lea    0xdbf(%rip),%r14
lea    0xdc0(%rip),%r15
xor    %ebp,%ebp
jmp    128b <main+0xeb>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jge    12a3 <main+0x103>
test   $0xf,%bpl
jne    1270 <main+0xd0>
mov    0x4(%rsp),%esi
add    %ebp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1270 <main+0xd0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12d8 <main+0x138>
mov    0x8(%r14),%rsi
lea    0xd42(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Usage: make_mem <input file> <size> [offset]\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 = [8 x i8] c"\0A@%04X \00"
@.str.5 = [6 x i8] c"%02X \00"
@.str.6 = [2 x i8] c"\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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %85
18: ; preds = %13, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 4
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
br label %31
30: ; preds = %18
store i32 0, i32* %10
br label %31
31: ; preds = %30, %25
%32 = load i32, i32* %9
%33 = call i8* @malloc(i32 %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = load i32, i32* %9
%36 = call i32 @memset(i8* %34, i32 170, i32 %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %6
%41 = load i32*, i32** %6
%42 = icmp ne i32* %41, null
br i1 %42, label %50, label %43
43: ; preds = %31
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
store i32 1, i32* %3
br label %85
50: ; preds = %31
%51 = load i8*, i8** %7
%52 = load i32, i32* %9
%53 = load i32*, i32** %6
%54 = call i32 @fread(i8* %51, i32 1, i32 %52, i32* %53)
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %8
br label %57
57: ; preds = %78, %50
%58 = load i32, i32* %8
%59 = load i32, i32* %9
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %81
61: ; preds = %57
%62 = load i32, i32* %8
%63 = srem i32 %62, 16
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load i32, i32* %8
%67 = load i32, i32* %10
%68 = add nsw i32 %66, %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %65, %61
%71 = load i8*, i8** %7
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %70
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %57
81: ; preds = %57
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%83 = load i8*, i8** %7
%84 = call i32 @free(i8* %83)
store i32 0, i32* %3
br label %85
85: ; preds = %81, %43, %16
%86 = load i32, i32* %3
ret i32 %86
}

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.4 = [8 x i8] c"\0A@%04X \00"
@.str.5 = [6 x i8] c"%02X \00"
@str = [45 x i8] c"Usage: make_mem <input file> <size> [offset]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = add i32 %0, -5
%8 = icmp ult i32 %7, -2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %60
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%15 = icmp eq i32 %0, 4
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
br label %21
20: ; preds = %11
store i32 0, i32* %4
br label %21
21: ; preds = %20, %16
%22 = load i32, i32* %3
%23 = call i8* @malloc(i32 %22)
%24 = call i32 @memset(i8* %23, i32 170, i32 %22)
%25 = getelementptr inbounds i8*, i8** %1, 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))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %21
%30 = load i8*, i8** %25
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = call i32 @free(i8* %23)
br label %60
33: ; preds = %21
%34 = load i32, i32* %3
%35 = call i32 @fread(i8* %23, i32 1, i32 %34, i32* %27)
%36 = call i32 @fclose(i32* %27)
%37 = load i32, i32* %3
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %57
39: ; preds = %33, %48
%40 = phi i64 [ %53, %48 ], [ 0, %33 ]
%41 = trunc i64 %40 to i32
%42 = and i32 %41, 15
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* %4
%46 = add nsw i32 %45, %41
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %44, %39
%49 = getelementptr inbounds i8, i8* %23, i64 %40
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = add nuw nsw i64 %40, 1
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %39, label %57
57: ; preds = %48, %33
%58 = call i32 @putchar(i32 10)
%59 = call i32 @free(i8* %23)
br label %60
60: ; preds = %57, %29, %9
%61 = phi i32 [ 0, %9 ], [ 0, %57 ], [ 1, %29 ]
ret i32 %61
}