#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 */

/* Variables and functions */
int read(int /*<<< orphan*/, char **, int);
int /*<<< orphan*/ write(int, ...);
int main() {
  char buf[2];
  char buf2[2] = {0xff, 0xff};
  while (read(0, &buf, 2) == 2) {
    write(1, &buf2, 2);
    write(1, &buf[1], 1);
    write(1, &buf[0], 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%ax
mov    %ax,-0x8(%rbp)
lea    -0x6(%rbp),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
jne    1195 <main+0x75>
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x6(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x6(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    113a <main+0x1a>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movw   $0xffff,0xe(%rsp)
lea    0xc(%rsp),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
jne    11b0 <main+0x90>
lea    0xd(%rsp),%r14
lea    0xe(%rsp),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
je     1160 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.buf2 = [2 x i8] c"\FF\FF"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8]
%3 = alloca [2 x i8]
store i32 0, i32* %1
%4 = bitcast [2 x i8]* %3 to i8*
br label %5
5: ; preds = %9, %0
%6 = bitcast [2 x i8]* %2 to i8**
%7 = call i32 @read(i32 0, i8** %6, i32 2)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = call i32 (i32, ...) @write(i32 1, [2 x i8]* %3, i32 2)
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%12 = call i32 (i32, ...) @write(i32 1, i8* %11, i32 1)
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%14 = call i32 (i32, ...) @write(i32 1, i8* %13, i32 1)
br label %5
15: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [2 x i8]
%2 = alloca i16
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%4 = bitcast i16* %2 to i8*
store i16 -1, i16* %2
%5 = bitcast [2 x i8]* %1 to i8**
%6 = call i32 @read(i32 0, i8** %5, i32 2)
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
br label %10
10: ; preds = %8, %10
%11 = call i32 (i32, ...) @write(i32 1, i16* %2, i32 2)
%12 = call i32 (i32, ...) @write(i32 1, i8* %9, i32 1)
%13 = call i32 (i32, ...) @write(i32 1, i8* %3, i32 1)
%14 = call i32 @read(i32 0, i8** %5, i32 2)
%15 = icmp eq i32 %14, 2
br i1 %15, label %10, label %16
16: ; preds = %10, %0
ret i32 0
}