#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 uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  FILE *in;
  if (argc < 2) {
    printf("Usage: %s <inputfile> [<width (bytes), 1-4>]\n", argv[0]);
    return 1;
  }
  int width;
  if (argc < 3) {
    width = 1;
  } else {
    width = strtol(argv[2], NULL, 0);
  }
  if ((in = fopen(argv[1], "rb")) == NULL) {
    perror(argv[1]);
    return 1;
  }
  printf("memory_initialization_radix = 16;\n");
  printf("memory_initialization_vector =\n");
  uint32_t c, w;
  size_t len, off = 0;
  fseek(in, 0, SEEK_END);
  len = ftell(in);
  fseek(in, 0, SEEK_SET);
  while (off < len) {
    c = 0;
    for (w = 0; w < width; w++) {
      c |= (fgetc(in) & 0xff) << (8 * w);
    }
    printf("%x, \n", c);
    off += width;
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x185>
cmpl   $0x3,-0x8(%rbp)
jge    11d7 <main+0x57>
movl   $0x1,-0x1c(%rbp)
jmp    11ed <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1228 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x185>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d60(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12f5 <main+0x175>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d3 <main+0x153>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
and    $0xff,%eax
mov    -0x24(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    129d <main+0x11d>
mov    -0x20(%rbp),%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x1c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1281 <main+0x101>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11c1 <main+0x31>
mov    (%r14),%rsi
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    12b8 <main+0x128>
movl   $0x1,0xc(%rsp)
cmp    $0x2,%edi
je     11df <main+0x4f>
mov    0x10(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,0xc(%rsp)
mov    0x8(%r14),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12c7 <main+0x137>
mov    %rax,%rbx
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbp
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbp,0x10(%rsp)
test   %rbp,%rbp
je     12ae <main+0x11e>
movslq 0xc(%rsp),%r12
xor    %r15d,%r15d
jmp    127a <main+0xea>
nopl   0x0(%rax,%rax,1)
lea    0xdca(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r12,%r15
cmp    0x10(%rsp),%r15
jae    12ae <main+0x11e>
mov    $0x0,%ebp
cmpl   $0x0,0xc(%rsp)
jle    1260 <main+0xd0>
xor    %r14d,%r14d
mov    0xc(%rsp),%r13d
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1060 <fgetc@plt>
movzbl %al,%eax
mov    %r14d,%ecx
shl    %cl,%eax
or     %eax,%ebp
add    $0x8,%r14d
add    $0xffffffff,%r13d
jne    1290 <main+0x100>
jmp    1260 <main+0xd0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r14),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
jmp    12b8 <main+0x128>

LLVM IR (-O0):
@.str = [46 x i8] c"Usage: %s <inputfile> [<width (bytes), 1-4>]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [35 x i8] c"memory_initialization_radix = 16;\0A\00"
@.str.3 = [32 x i8] c"memory_initialization_vector =\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [6 x i8] c"%x, \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %81
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 1, i32* %7
br label %28
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @strtol(i8* %26, i32* null, i32 0)
store i32 %27, i32* %7
br label %28
28: ; preds = %23, %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %6
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @perror(i8* %37)
store i32 1, i32* %3
br label %81
39: ; preds = %28
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %11
%42 = load i32*, i32** %6
%43 = load i32, i32* @SEEK_END
%44 = call i32 @fseek(i32* %42, i32 0, i32 %43)
%45 = load i32*, i32** %6
%46 = call i64 @ftell(i32* %45)
store i64 %46, i64* %10
%47 = load i32*, i32** %6
%48 = load i32, i32* @SEEK_SET
%49 = call i32 @fseek(i32* %47, i32 0, i32 %48)
br label %50
50: ; preds = %71, %39
%51 = load i64, i64* %11
%52 = load i64, i64* %10
%53 = icmp ult i64 %51, %52
br i1 %53, label %54, label %78
54: ; preds = %50
store i32 0, i32* %8
store i32 0, i32* %9
br label %55
55: ; preds = %68, %54
%56 = load i32, i32* %9
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %71
59: ; preds = %55
%60 = load i32*, i32** %6
%61 = call i32 @fgetc(i32* %60)
%62 = and i32 %61, 255
%63 = load i32, i32* %9
%64 = mul nsw i32 8, %63
%65 = shl i32 %62, %64
%66 = load i32, i32* %8
%67 = or i32 %66, %65
store i32 %67, i32* %8
br label %68
68: ; preds = %59
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %55
71: ; preds = %55
%72 = load i32, i32* %8
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = load i64, i64* %11
%77 = add i64 %76, %75
store i64 %77, i64* %11
br label %50
78: ; preds = %50
%79 = load i32*, i32** %6
%80 = call i32 @fclose(i32* %79)
store i32 0, i32* %3
br label %81
81: ; preds = %78, %34, %14
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [46 x i8] c"Usage: %s <inputfile> [<width (bytes), 1-4>]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [6 x i8] c"%x, \0A\00"
@str = [34 x i8] c"memory_initialization_radix = 16;\00"
@str.5 = [31 x i8] c"memory_initialization_vector =\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %53
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 0)
br label %13
13: ; preds = %7, %9
%14 = phi i32 [ %12, %9 ], [ 1, %7 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i8*, i8** %15
%21 = tail call i32 @perror(i8* %20)
br label %53
22: ; preds = %13
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%25 = load i32, i32* @SEEK_END
%26 = tail call i32 @fseek(i32* %17, i32 0, i32 %25)
%27 = tail call i64 @ftell(i32* %17)
%28 = load i32, i32* @SEEK_SET
%29 = tail call i32 @fseek(i32* %17, i32 0, i32 %28)
%30 = icmp eq i64 %27, 0
br i1 %30, label %51, label %31
31: ; preds = %22
%32 = icmp sgt i32 %14, 0
%33 = sext i32 %14 to i64
br label %34
34: ; preds = %31, %46
%35 = phi i64 [ 0, %31 ], [ %49, %46 ]
br i1 %32, label %36, label %46
36: ; preds = %34, %36
%37 = phi i32 [ %44, %36 ], [ 0, %34 ]
%38 = phi i32 [ %43, %36 ], [ 0, %34 ]
%39 = tail call i32 @fgetc(i32* %17)
%40 = and i32 %39, 255
%41 = shl nsw i32 %37, 3
%42 = shl i32 %40, %41
%43 = or i32 %42, %38
%44 = add nuw nsw i32 %37, 1
%45 = icmp eq i32 %44, %14
br i1 %45, label %46, label %36
46: ; preds = %36, %34
%47 = phi i32 [ 0, %34 ], [ %43, %36 ]
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = add i64 %35, %33
%50 = icmp ult i64 %49, %27
br i1 %50, label %34, label %51
51: ; preds = %46, %22
%52 = tail call i32 @fclose(i32* %17)
br label %53
53: ; preds = %19, %51, %4
%54 = phi i32 [ 1, %4 ], [ 1, %19 ], [ 0, %51 ]
ret i32 %54
}