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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  uint8_t vals[3];
  int counter = 0;
  if (argc <= 1) {
    printf("\nShould pass a filename as input via command line\n");
    return 0;
  }
  FILE *fp = fopen(argv[1], "rb");
  if (!fp) {
    printf("\nFailed to open file named \"%s\" for reading\n", argv[1]);
    return 0;
  }
  while (!feof(fp)) {
    if (!fread(vals, sizeof(vals), 1, fp)) {
      break;
    }
    printf(" BE_Cross_SwapGroup24LE(0x%02x, 0x%02x, 0x%02x)", vals[0], vals[1],
           vals[2]);
    if (++counter == 5) {
      counter = 0;
      printf("\n");
    }
  }
  fclose(fp);
  printf("\n");
  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)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1191 <main+0x41>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127f <main+0x12f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127f <main+0x12f>
jmp    11db <main+0x8b>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f9 <main+0xa9>
jmp    1261 <main+0x111>
lea    -0x1c(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0xc,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    121e <main+0xce>
jmp    1261 <main+0x111>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0x5,%eax
jne    125c <main+0x10c>
movl   $0x0,-0x20(%rbp)
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11db <main+0x8b>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@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
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     118d <main+0x1d>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
jmp    11da <main+0x6a>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11c8 <main+0x58>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11e7 <main+0x77>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11da <main+0x6a>
mov    0x8(%r14),%rsi
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc(%rsp),%r14
lea    0xe3d(%rip),%r15
xor    %ebp,%ebp
jmp    120c <main+0x9c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11b4 <main+0x44>
mov    %r14,%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     11b4 <main+0x44>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
cmp    $0x5,%ebp
jne    1200 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1200 <main+0x90>

LLVM IR (-O0):
@.str = [51 x i8] c"\0AShould pass a filename as input via command line\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [45 x i8] c"\0AFailed to open file named \22%s\22 for reading\0A\00"
@.str.3 = [48 x i8] c" BE_Cross_SwapGroup24LE(0x%02x, 0x%02x, 0x%02x)\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i32]
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %55
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %8
%18 = load i32*, i32** %8
%19 = icmp ne i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %23)
store i32 0, i32* %3
br label %55
25: ; preds = %13
br label %26
26: ; preds = %50, %25
%27 = load i32*, i32** %8
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %51
31: ; preds = %26
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%33 = load i32*, i32** %8
%34 = call i32 @fread(i32* %32, i32 12, i32 1, i32* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %31
br label %51
37: ; preds = %31
%38 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 2
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %41, i32 %43)
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
%47 = icmp eq i32 %46, 5
br i1 %47, label %48, label %50
48: ; preds = %37
store i32 0, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %37
br label %26
51: ; preds = %36, %26
%52 = load i32*, i32** %8
%53 = call i32 @fclose(i32* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %55
55: ; preds = %51, %20, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [45 x i8] c"\0AFailed to open file named \22%s\22 for reading\0A\00"
@.str.3 = [48 x i8] c" BE_Cross_SwapGroup24LE(0x%02x, 0x%02x, 0x%02x)\00"
@str = [50 x i8] c"\0AShould pass a filename as input via command line\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i32]
%4 = bitcast [3 x i32]* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %43
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%15 = tail call i32 @feof(i32* %11)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
br label %23
20: ; preds = %8
%21 = load i8*, i8** %9
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %43
23: ; preds = %17, %36
%24 = phi i32 [ 0, %17 ], [ %37, %36 ]
%25 = call i32 @fread(i32* %14, i32 12, i32 1, i32* %11)
%26 = icmp eq i32 %25, 0
br i1 %26, label %40, label %27
27: ; preds = %23
%28 = load i32, i32* %14
%29 = load i32, i32* %18
%30 = load i32, i32* %19
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %29, i32 %30)
%32 = add nsw i32 %24, 1
%33 = icmp eq i32 %32, 5
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = tail call i32 @putchar(i32 10)
br label %36
36: ; preds = %34, %27
%37 = phi i32 [ 0, %34 ], [ %32, %27 ]
%38 = tail call i32 @feof(i32* %11)
%39 = icmp eq i32 %38, 0
br i1 %39, label %23, label %40
40: ; preds = %36, %23, %13
%41 = tail call i32 @fclose(i32* %11)
%42 = tail call i32 @putchar(i32 10)
br label %43
43: ; preds = %20, %40, %6
ret i32 0
}