#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 EOF;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *fd;
  int c, j, width;
  unsigned long word;
  if (argc < 3) {
    fprintf(stderr, "no input file specified\n");
    exit(1);
  }
  if (argc > 3) {
    fprintf(stderr, "too many input files (more than one) specified\n");
    exit(1);
  }
  width = atoi(argv[1]);
  fd = fopen(argv[2], "r");
  if (fd == NULL) {
    fprintf(stderr, "failed to open input file: %s\n", argv[1]);
    exit(1);
  }
  while (!feof(fd)) {
    j = 0;
    word = 0;
    while (j < width) {
      c = fgetc(fd);
      if (c == EOF) {
        c = 0;
      }
      word = (word << 8) + c;
      j++;
    }
    if (width == 1)
      printf("%.2lx\n", word);
    else if (width == 2)
      printf("%.4lx\n", word);
    else
      printf("%.8lx\n", word);
  }
  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)
jge    11b1 <main+0x41>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    11dc <main+0x6c>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1238 <main+0xc8>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    123d <main+0xcd>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    125b <main+0xeb>
jmp    1314 <main+0x1a4>
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12bc <main+0x14c>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d5c(%rip),%rcx
cmp    (%rcx),%eax
jne    129b <main+0x12b>
movl   $0x0,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x8,%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    126a <main+0xfa>
cmpl   $0x1,-0x24(%rbp)
jne    12db <main+0x16b>
mov    -0x30(%rbp),%rsi
lea    0xd99(%rip),%rdi
call   1030 <printf@plt>
jmp    130f <main+0x19f>
cmpl   $0x2,-0x24(%rbp)
jne    12fa <main+0x18a>
mov    -0x30(%rbp),%rsi
lea    0xd81(%rip),%rdi
call   1030 <printf@plt>
jmp    130a <main+0x19a>
mov    -0x30(%rbp),%rsi
lea    0xd73(%rip),%rdi
call   1030 <printf@plt>
jmp    130f <main+0x19f>
jmp    123d <main+0xcd>
xor    %eax,%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    $0x2,%edi
jle    1263 <main+0xf3>
cmp    $0x3,%edi
jne    1275 <main+0x105>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1296 <main+0x126>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d5 <main+0x65>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x2,%r15d
lea    0xe91(%rip),%rax
lea    0xe91(%rip),%rcx
cmove  %rax,%rcx
cmp    $0x1,%r15d
lea    0xe74(%rip),%r14
cmovne %rcx,%r14
mov    0x2de7(%rip),%r12
jmp    1229 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    %r13,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11c4 <main+0x54>
test   %r15d,%r15d
jle    1210 <main+0xa0>
mov    %r15d,%ebx
xor    %ebp,%ebp
jmp    124f <main+0xdf>
cs nopw 0x0(%rax,%rax,1)
nop
shl    $0x8,%rbp
movslq %ecx,%rax
add    %rax,%rbp
add    $0xffffffff,%ebx
je     1212 <main+0xa2>
mov    %r13,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    (%r12),%eax
je     1240 <main+0xd0>
mov    %eax,%ecx
jmp    1240 <main+0xd0>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
jmp    1285 <main+0x115>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xda1(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"no input file specified\0A\00"
@.str.1 = [48 x i8] c"too many input files (more than one) specified\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"failed to open input file: %s\0A\00"
@EOF = global i32 0
@.str.4 = [7 x i8] c"%.2lx\0A\00"
@.str.5 = [7 x i8] c"%.4lx\0A\00"
@.str.6 = [7 x i8] c"%.8lx\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 3
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %9
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %42
35: ; preds = %24
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %24
br label %43
43: ; preds = %84, %42
%44 = load i32*, i32** %6
%45 = call i32 @feof(i32* %44)
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %85
48: ; preds = %43
store i32 0, i32* %8
store i64 0, i64* %10
br label %49
49: ; preds = %60, %48
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %68
53: ; preds = %49
%54 = load i32*, i32** %6
%55 = call i32 @fgetc(i32* %54)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = load i32, i32* @EOF
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %53
store i32 0, i32* %7
br label %60
60: ; preds = %59, %53
%61 = load i64, i64* %10
%62 = shl i64 %61, 8
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = add i64 %62, %64
store i64 %65, i64* %10
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %49
68: ; preds = %49
%69 = load i32, i32* %9
%70 = icmp eq i32 %69, 1
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i64, i64* %10
%73 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 %72)
br label %84
74: ; preds = %68
%75 = load i32, i32* %9
%76 = icmp eq i32 %75, 2
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i64, i64* %10
%79 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %78)
br label %83
80: ; preds = %74
%81 = load i64, i64* %10
%82 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i64 %81)
br label %83
83: ; preds = %80, %77
br label %84
84: ; preds = %83, %71
br label %43
85: ; preds = %43
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"no input file specified\0A\00"
@.str.1 = [48 x i8] c"too many input files (more than one) specified\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"failed to open input file: %s\0A\00"
@EOF = global i32 0
@.str.4 = [7 x i8] c"%.2lx\0A\00"
@.str.5 = [7 x i8] c"%.4lx\0A\00"
@.str.6 = [7 x i8] c"%.8lx\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %31, label %22
22: ; preds = %14
%23 = tail call i32 @feof(i32* %20)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %54
25: ; preds = %22
%26 = icmp sgt i32 %17, 0
%27 = icmp eq i32 %17, 2
%28 = select i1 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%29 = icmp eq i32 %17, 1
%30 = select i1 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %28
br label %36
31: ; preds = %14
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %15
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %25, %49
br i1 %26, label %37, label %49
37: ; preds = %36, %37
%38 = phi i64 [ %46, %37 ], [ 0, %36 ]
%39 = phi i32 [ %47, %37 ], [ 0, %36 ]
%40 = tail call i32 @fgetc(i32* %20)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
%43 = select i1 %42, i32 0, i32 %40
%44 = shl i64 %38, 8
%45 = sext i32 %43 to i64
%46 = add i64 %44, %45
%47 = add nuw nsw i32 %39, 1
%48 = icmp eq i32 %47, %17
br i1 %48, label %49, label %37
49: ; preds = %37, %36
%50 = phi i64 [ 0, %36 ], [ %46, %37 ]
%51 = tail call i32 @printf(i8* %30, i64 %50)
%52 = tail call i32 @feof(i32* %20)
%53 = icmp eq i32 %52, 0
br i1 %53, label %36, label %54
54: ; preds = %49, %22
ret i32 0
}