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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htobe16(int /*<<< orphan*/);
int /*<<< orphan*/ le16toh(int /*<<< orphan*/);
int main() {
  FILE *src = fopen("solaris.dat", "r"), *dst = fopen("solaris.ans", "w");
  uint16_t buf;
  while (fread(&buf, sizeof(buf), 1, src) == 1) {
    buf = htobe16(le16toh(buf));
    fwrite(&buf, sizeof(buf), 1, dst);
  }
  fclose(src);
  fclose(dst);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11eb <main+0x8b>
mov    -0x1c(%rbp),%edi
call   1050 <le16toh@plt>
mov    %eax,%edi
call   1070 <htobe16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
jmp    119d <main+0x3d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe88(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1203 <main+0xa3>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
call   1050 <le16toh@plt>
mov    %eax,%edi
call   1070 <htobe16@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11c0 <main+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"solaris.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"solaris.ans\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %6, i32** %3
br label %7
7: ; preds = %11, %0
%8 = load i32*, i32** %2
%9 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* %4
%13 = call i32 @le16toh(i32 %12)
%14 = call i32 @htobe16(i32 %13)
store i32 %14, i32* %4
%15 = load i32*, i32** %3
%16 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %15)
br label %7
17: ; preds = %7
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"solaris.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"solaris.ans\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %0, %7
%8 = load i32, i32* %1
%9 = tail call i32 @le16toh(i32 %8)
%10 = tail call i32 @htobe16(i32 %9)
store i32 %10, i32* %1
%11 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %3)
%12 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %2)
%13 = icmp eq i32 %12, 1
br i1 %13, label %7, label %14
14: ; preds = %7, %0
%15 = tail call i32 @fclose(i32* %2)
%16 = tail call i32 @fclose(i32* %3)
ret i32 0
}