#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 *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char *argv[]) {
  unsigned char buffer[4];
  int tmp;
  long ct = 0;
  char innm[40], outnm[40];
  FILE *infile, *outfile;
  printf("\n\nSwap a Big-Endian Data file to Little Endian\n");
  printf("          or vise-versa.  (32 bit data only)\n");
  if (argc > 1) {
    sprintf(innm, "%s", argv[1]);
    printf("\nReading data from \"%s\".\n", innm);
    if (NULL == (infile = fopen(innm, "r+b"))) {
      printf("\nCan't open \"%s\", exiting.\n", innm);
      exit(1);
    }
    sprintf(outnm, "%s_swapped", argv[1]);
    printf("Writing data to \"%s\".\n\n", outnm);
    if (NULL == (outfile = fopen(outnm, "w+b"))) {
      printf("\nCan't open %s, exiting.\n", outnm);
      exit(1);
    }
  } else {
    printf("\n\nPlease enter a filename for the input data file");
    printf(" after \"readdata\".\n");
    exit(1);
  }
  ct = 0;
  while (fread(buffer, sizeof(unsigned char), 4, infile)) {
    tmp = buffer[0];
    buffer[0] = buffer[3];
    buffer[3] = tmp;
    tmp = buffer[1];
    buffer[1] = buffer[2];
    buffer[2] = tmp;
    fwrite(buffer, sizeof(unsigned char), 4, outfile);
    ct++;
  }
  printf("Converted %ld points.\n\n", ct);
  fclose(infile);
  fclose(outfile);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1292 <main+0x122>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe94(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x88(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1222 <main+0xb2>
lea    -0x50(%rbp),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe66(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x90(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    128d <main+0x11d>
lea    -0x80(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12b8 <main+0x148>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movq   $0x0,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1335 <main+0x1c5>
movzbl -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x11(%rbp)
movzbl -0x13(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x13(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x12(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x90(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12c0 <main+0x150>
mov    -0x20(%rbp),%rsi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x88(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x90(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xf1d(%rip),%rdi
call   1040 <puts@plt>
lea    0xf40(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
jl     1202 <main+0x72>
mov    0x8(%rbx),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xe2a(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe33(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
jne    1226 <main+0x96>
lea    0xe23(%rip),%rdi
lea    0x40(%rsp),%rsi
jmp    1272 <main+0xe2>
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xf0a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdx
lea    0xe06(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
lea    0xdfd(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
jne    1283 <main+0xf3>
lea    0xdf4(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     12fb <main+0x16b>
lea    0xc(%rsp),%r12
nopl   0x0(%rax)
movzbl 0xc(%rsp),%eax
movzbl 0xf(%rsp),%ecx
mov    %cl,0xc(%rsp)
mov    %al,0xf(%rsp)
rolw   $0x8,0xd(%rsp)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
add    $0x1,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jne    12b0 <main+0x120>
lea    0xdab(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"\0A\0ASwap a Big-Endian Data file to Little Endian\0A\00"
@.str.1 = [46 x i8] c" or vise-versa. (32 bit data only)\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [26 x i8] c"\0AReading data from \22%s\22.\0A\00"
@.str.4 = [4 x i8] c"r+b\00"
@.str.5 = [28 x i8] c"\0ACan't open \22%s\22, exiting.\0A\00"
@.str.6 = [11 x i8] c"%s_swapped\00"
@.str.7 = [24 x i8] c"Writing data to \22%s\22.\0A\0A\00"
@.str.8 = [4 x i8] c"w+b\00"
@.str.9 = [26 x i8] c"\0ACan't open %s, exiting.\0A\00"
@.str.10 = [50 x i8] c"\0A\0APlease enter a filename for the input data file\00"
@.str.11 = [20 x i8] c" after \22readdata\22.\0A\00"
@.str.12 = [24 x i8] c"Converted %ld points.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca [40 x i8]
%10 = alloca [40 x i8]
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %48
17: ; preds = %2
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32* %26, i32** %11
%27 = icmp eq i32* null, %26
br i1 %27, label %28, label %32
28: ; preds = %17
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
store i32* %41, i32** %12
%42 = icmp eq i32* null, %41
br i1 %42, label %43, label %47
43: ; preds = %32
%44 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %32
br label %52
48: ; preds = %2
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %47
store i64 0, i64* %8
br label %53
53: ; preds = %58, %52
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%55 = load i32*, i32** %11
%56 = call i64 @fread(i8* %54, i32 1, i32 4, i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %82
58: ; preds = %53
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
store i32 %61, i32* %7
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
%63 = load i8, i8* %62
%64 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 %63, i8* %64
%65 = load i32, i32* %7
%66 = trunc i32 %65 to i8
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 %66, i8* %67
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
store i32 %70, i32* %7
%71 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%72 = load i8, i8* %71
%73 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 %72, i8* %73
%74 = load i32, i32* %7
%75 = trunc i32 %74 to i8
%76 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
store i8 %75, i8* %76
%77 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%78 = load i32*, i32** %12
%79 = call i32 @fwrite(i8* %77, i32 1, i32 4, i32* %78)
%80 = load i64, i64* %8
%81 = add nsw i64 %80, 1
store i64 %81, i64* %8
br label %53
82: ; preds = %53
%83 = load i64, i64* %8
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i64 %83)
%85 = load i32*, i32** %11
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %12
%88 = call i32 @fclose(i32* %87)
%89 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.3 = [26 x i8] c"\0AReading data from \22%s\22.\0A\00"
@.str.4 = [4 x i8] c"r+b\00"
@.str.5 = [28 x i8] c"\0ACan't open \22%s\22, exiting.\0A\00"
@.str.6 = [11 x i8] c"%s_swapped\00"
@.str.7 = [24 x i8] c"Writing data to \22%s\22.\0A\0A\00"
@.str.8 = [4 x i8] c"w+b\00"
@.str.9 = [26 x i8] c"\0ACan't open %s, exiting.\0A\00"
@.str.10 = [50 x i8] c"\0A\0APlease enter a filename for the input data file\00"
@.str.12 = [24 x i8] c"Converted %ld points.\0A\0A\00"
@str = [47 x i8] c"\0A\0ASwap a Big-Endian Data file to Little Endian\00"
@str.13 = [45 x i8] c" or vise-versa. (32 bit data only)\00"
@str.14 = [19 x i8] c" after \22readdata\22.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = alloca [40 x i8]
%5 = alloca [40 x i8]
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.13, i64 0, i64 0))
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %38
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i8* @strcpy(i8* %7, i8* dereferenceable(1) %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%17 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = load i8*, i8** %13
%24 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%26 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %35, label %28
28: ; preds = %22
%29 = call i64 @fread(i8* %6, i32 1, i32 4, i32* %17)
%30 = icmp eq i64 %29, 0
br i1 %30, label %52, label %31
31: ; preds = %28
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
br label %42
35: ; preds = %22
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %8)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %2
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %31, %42
%43 = phi i64 [ 0, %31 ], [ %49, %42 ]
%44 = load i8, i8* %6
%45 = load i8, i8* %32
store i8 %45, i8* %6
store i8 %44, i8* %32
%46 = load i8, i8* %33
%47 = load i8, i8* %34
store i8 %47, i8* %33
store i8 %46, i8* %34
%48 = call i32 @fwrite(i8* %6, i32 1, i32 4, i32* %26)
%49 = add nuw nsw i64 %43, 1
%50 = call i64 @fread(i8* %6, i32 1, i32 4, i32* %17)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %42
52: ; preds = %42, %28
%53 = phi i64 [ 0, %28 ], [ %49, %42 ]
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i64 %53)
%55 = call i32 @fclose(i32* %17)
%56 = call i32 @fclose(i32* %26)
%57 = call i32 @exit(i32 0)
unreachable
}