#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int readDataSwappingBytes(int /*<<< orphan*/ *);
int readDataWithoutSwapping(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *filePointer;
  int counter = 0;
  if (argc != 3) {
    printf("Usage: <input file> <swap|not>\n");
    puts("Use 'swap' in the second argument to swap the bytes or 'not' for not "
         "swapping");
    exit(1);
  }
  puts("Aldebaro Klautau - www.laps.ufpa.br - March 10, 2009");
  puts("Each columns represents:");
  puts("<byte counter> <decimal char> <hexa char> <(ASCII)> <short> <int> "
       "<long int> <float> <double>\n");
  filePointer = fopen(argv[1], "rb");
  if (filePointer == NULL) {
    printf("Error opening file %s", argv[1]);
    exit(1);
  }
  if (strcmp(argv[2], "swap") == 0) {
    counter = readDataSwappingBytes(filePointer);
  } else {
    counter = readDataWithoutSwapping(filePointer);
  }
  fclose(filePointer);
  printf("\n\n%d bytes read from file %s\n", counter, argv[1]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cb <main+0x4b>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf1d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1232 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xefd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xef3(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1261 <main+0xe1>
mov    -0x18(%rbp),%rdi
call   1040 <readDataSwappingBytes@plt>
mov    %eax,-0x1c(%rbp)
jmp    126d <main+0xed>
mov    -0x18(%rbp),%rdi
call   1070 <readDataWithoutSwapping@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    1218 <main+0x98>
mov    %rsi,%r14
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
lea    0xf3c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123a <main+0xba>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xf3d(%rip),%rsi
call   1080 <strcmp@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     11eb <main+0x6b>
call   1070 <readDataWithoutSwapping@plt>
jmp    11f0 <main+0x70>
call   1040 <readDataSwappingBytes@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x8(%r14),%rdx
lea    0xf14(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: <input file> <swap|not>\0A\00"
@.str.1 = [78 x i8] c"Use 'swap' in the second argument to swap the bytes or 'not' for not swapping\00"
@.str.2 = [53 x i8] c"Aldebaro Klautau - www.laps.ufpa.br - March 10, 2009\00"
@.str.3 = [25 x i8] c"Each columns represents:\00"
@.str.4 = [95 x i8] c"<byte counter> <decimal char> <hexa char> <(ASCII)> <short> <int> <long int> <float> <double>\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [22 x i8] c"Error opening file %s\00"
@.str.7 = [5 x i8] c"swap\00"
@.str.8 = [30 x i8] c"\0A\0A%d bytes read from file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @puts(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32 @puts(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @puts(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.4, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %14
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32*, i32** %6
%38 = call i32 @readDataSwappingBytes(i32* %37)
store i32 %38, i32* %7
br label %42
39: ; preds = %30
%40 = load i32*, i32** %6
%41 = call i32 @readDataWithoutSwapping(i32* %40)
store i32 %41, i32* %7
br label %42
42: ; preds = %39, %36
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* %7
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %45, i8* %48)
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [78 x i8] c"Use 'swap' in the second argument to swap the bytes or 'not' for not swapping\00"
@.str.2 = [53 x i8] c"Aldebaro Klautau - www.laps.ufpa.br - March 10, 2009\00"
@.str.3 = [25 x i8] c"Each columns represents:\00"
@.str.4 = [95 x i8] c"<byte counter> <decimal char> <hexa char> <(ASCII)> <short> <int> <long int> <float> <double>\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [22 x i8] c"Error opening file %s\00"
@.str.7 = [5 x i8] c"swap\00"
@.str.8 = [30 x i8] c"\0A\0A%d bytes read from file %s\0A\00"
@str = [31 x i8] c"Usage: <input file> <swap|not>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([95 x i8], [95 x i8]* @.str.4, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i8*, i8** %12
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %8
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = tail call i32 @readDataSwappingBytes(i32* %14)
br label %29
27: ; preds = %20
%28 = tail call i32 @readDataWithoutSwapping(i32* %14)
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
%31 = tail call i32 @fclose(i32* %14)
%32 = load i8*, i8** %12
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %30, i8* %32)
ret i32 1
}