#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*/ SEEK_END;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned char *buffer;
  unsigned char s;
  size_t size, i;
  if (argc < 2) {
    printf("Usage:%s <In-File> <Out-File>\n", argv[0]);
    printf("This tool can help you to invert endian on WORD\n");
    exit(0);
  }
  fp = fopen(argv[1], "rb");
  if (fp == NULL)
    exit(0);
  fseek(fp, 0, SEEK_END);
  size = ftell(fp);
  rewind(fp);
  printf("File size:%d\n", size);
  buffer = malloc(size);
  fread(buffer, 1, size, fp);
  fclose(fp);
  for (i = 0; i <= size; i += 2) {
    s = buffer[i];
    buffer[i] = buffer[i + 1];
    buffer[i + 1] = s;
  }
  fp = fopen(argv[2], "wb+");
  if (fp == NULL)
    exit(0);
  fwrite(buffer, 1, size, fp);
  fclose(fp);
  printf("Completed write:%s\n", argv[2]);
  free(buffer);
}


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    11fa <main+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1224 <main+0x74>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x30(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
ja     12e7 <main+0x137>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    0x1(%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
jmp    1294 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd6b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1311 <main+0x161>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jle    1300 <main+0x140>
mov    0x8(%r14),%rdi
lea    0xe3f(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     131d <main+0x15d>
mov    %rax,%r12
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1080 <rewind@plt>
lea    0xe02(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r15,%rax
shr    %rax
add    $0x1,%rax
cmp    $0x2,%r15
jb     1288 <main+0xc8>
mov    %rax,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %ebx,%ebx
nopl   0x0(%rax)
rolw   $0x8,0x0(%r13,%rbx,1)
rolw   $0x8,0x2(%r13,%rbx,1)
add    $0x4,%rbx
add    $0xfffffffffffffffe,%rcx
jne    1270 <main+0xb0>
test   $0x1,%al
je     12a7 <main+0xe7>
mov    0x0(%r13,%rbx,1),%al
mov    %rbx,%rcx
or     $0x1,%rcx
mov    0x0(%r13,%rcx,1),%dl
mov    %dl,0x0(%r13,%rbx,1)
mov    %al,0x0(%r13,%rcx,1)
mov    0x10(%r14),%rdi
lea    0xd7e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     131d <main+0x15d>
mov    %rax,%r12
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    0x10(%r14),%rsi
lea    0xd4f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%r14),%rsi
lea    0xcf6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd30(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Usage:%s <In-File> <Out-File>\0A\00"
@.str.1 = [49 x i8] c"This tool can help you to invert endian on WORD\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.3 = [14 x i8] c"File size:%d\0A\00"
@.str.4 = [4 x i8] c"wb+\00"
@.str.5 = [20 x i8] c"Completed write:%s\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 i8
%9 = alloca i64
%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, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %20
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32*, i32** %6
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %9
%35 = load i32*, i32** %6
%36 = call i32 @rewind(i32* %35)
%37 = load i64, i64* %9
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 %37)
%39 = load i64, i64* %9
%40 = call i8* @malloc(i64 %39)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = load i64, i64* %9
%43 = load i32*, i32** %6
%44 = call i32 @fread(i8* %41, i32 1, i64 %42, i32* %43)
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
store i64 0, i64* %10
br label %47
47: ; preds = %69, %29
%48 = load i64, i64* %10
%49 = load i64, i64* %9
%50 = icmp ule i64 %48, %49
br i1 %50, label %51, label %72
51: ; preds = %47
%52 = load i8*, i8** %7
%53 = load i64, i64* %10
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = load i8, i8* %54
store i8 %55, i8* %8
%56 = load i8*, i8** %7
%57 = load i64, i64* %10
%58 = add i64 %57, 1
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = load i8*, i8** %7
%62 = load i64, i64* %10
%63 = getelementptr inbounds i8, i8* %61, i64 %62
store i8 %60, i8* %63
%64 = load i8, i8* %8
%65 = load i8*, i8** %7
%66 = load i64, i64* %10
%67 = add i64 %66, 1
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 %64, i8* %68
br label %69
69: ; preds = %51
%70 = load i64, i64* %10
%71 = add i64 %70, 2
store i64 %71, i64* %10
br label %47
72: ; preds = %47
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 2
%75 = load i8*, i8** %74
%76 = call i32* @fopen(i8* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32* %76, i32** %6
%77 = load i32*, i32** %6
%78 = icmp eq i32* %77, null
br i1 %78, label %79, label %81
79: ; preds = %72
%80 = call i32 @exit(i32 0)
unreachable
81: ; preds = %72
%82 = load i8*, i8** %7
%83 = load i64, i64* %9
%84 = load i32*, i32** %6
%85 = call i32 @fwrite(i8* %82, i32 1, i64 %83, i32* %84)
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 2
%90 = load i8*, i8** %89
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %90)
%92 = load i8*, i8** %7
%93 = call i32 @free(i8* %92)
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [31 x i8] c"Usage:%s <In-File> <Out-File>\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.3 = [14 x i8] c"File size:%d\0A\00"
@.str.4 = [4 x i8] c"wb+\00"
@.str.5 = [20 x i8] c"Completed write:%s\0A\00"
@str = [48 x i8] c"This tool can help you to invert endian on WORD\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %9
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %12, i32 0, i32 %17)
%19 = tail call i64 @ftell(i32* %12)
%20 = tail call i32 @rewind(i32* %12)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 %19)
%22 = tail call i8* @malloc(i64 %19)
%23 = tail call i32 @fread(i8* %22, i32 1, i64 %19, i32* %12)
%24 = tail call i32 @fclose(i32* %12)
%25 = lshr i64 %19, 1
%26 = add nuw i64 %25, 1
%27 = and i64 %26, 1
%28 = icmp ult i64 %19, 2
br i1 %28, label %48, label %29
29: ; preds = %16
%30 = and i64 %26, -2
br label %31
31: ; preds = %31, %29
%32 = phi i64 [ 0, %29 ], [ %45, %31 ]
%33 = phi i64 [ 0, %29 ], [ %46, %31 ]
%34 = getelementptr inbounds i8, i8* %22, i64 %32
%35 = load i8, i8* %34
%36 = or i64 %32, 1
%37 = getelementptr inbounds i8, i8* %22, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %34
store i8 %35, i8* %37
%39 = or i64 %32, 2
%40 = getelementptr inbounds i8, i8* %22, i64 %39
%41 = load i8, i8* %40
%42 = or i64 %32, 3
%43 = getelementptr inbounds i8, i8* %22, i64 %42
%44 = load i8, i8* %43
store i8 %44, i8* %40
store i8 %41, i8* %43
%45 = add nuw i64 %32, 4
%46 = add nuw i64 %33, 2
%47 = icmp eq i64 %46, %30
br i1 %47, label %48, label %31
48: ; preds = %31, %16
%49 = phi i64 [ 0, %16 ], [ %45, %31 ]
%50 = icmp eq i64 %27, 0
br i1 %50, label %57, label %51
51: ; preds = %48
%52 = getelementptr inbounds i8, i8* %22, i64 %49
%53 = load i8, i8* %52
%54 = or i64 %49, 1
%55 = getelementptr inbounds i8, i8* %22, i64 %54
%56 = load i8, i8* %55
store i8 %56, i8* %52
store i8 %53, i8* %55
br label %57
57: ; preds = %48, %51
%58 = getelementptr inbounds i8*, i8** %1, i64 2
%59 = load i8*, i8** %58
%60 = tail call i32* @fopen(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = tail call i32 @exit(i32 0)
unreachable
64: ; preds = %57
%65 = tail call i32 @fwrite(i8* %22, i32 1, i64 %19, i32* %60)
%66 = tail call i32 @fclose(i32* %60)
%67 = load i8*, i8** %58
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %67)
%69 = tail call i32 @free(i8* %22)
ret i32 0
}